Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

fix: set proxy server in config file #283

Merged
merged 3 commits into from
Jul 13, 2021
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
3 changes: 3 additions & 0 deletions CHANGELOG.md
Original file line number Diff line number Diff line change
Expand Up @@ -3,6 +3,9 @@
### Features
1. [#281](https://github.com/influxdata/influxdb-client-python/pull/281): `FluxTable`, `FluxColumn` and `FluxRecord` objects have helpful reprs

### Bug Fixes
1. [#283](https://github.com/influxdata/influxdb-client-python/pull/283): Set proxy server in config file

## 1.19.0 [2021-07-09]

### Features
Expand Down
9 changes: 8 additions & 1 deletion influxdb_client/client/influxdb_client.py
Original file line number Diff line number Diff line change
Expand Up @@ -115,6 +115,7 @@ def from_config_file(cls, config_file: str = "config.ini", debug=None, enable_gz
- connection_pool_maxsize
- auth_basic
- profilers
- proxy


config.ini example::
Expand All @@ -127,6 +128,7 @@ def from_config_file(cls, config_file: str = "config.ini", debug=None, enable_gz
connection_pool_maxsize=25
auth_basic=false
profilers=query,operator
proxy=http:proxy.domain.org:8080

[tags]
id = 132-987-655
Expand All @@ -143,6 +145,7 @@ def from_config_file(cls, config_file: str = "config.ini", debug=None, enable_gz
connection_pool_maxsize = 25
auth_basic = false
profilers="query, operator"
proxy = "http://proxy.domain.org:8080"

[tags]
id = "132-987-655"
Expand Down Expand Up @@ -192,10 +195,14 @@ def config_value(key: str):
if config.has_option('influx2', 'profilers'):
profilers = [x.strip() for x in config_value('profilers').split(',')]

proxy = None
if config.has_option('influx2', 'proxy'):
proxy = config_value('proxy')

return cls(url, token, debug=debug, timeout=_to_int(timeout), org=org, default_tags=default_tags,
enable_gzip=enable_gzip, verify_ssl=_to_bool(verify_ssl), ssl_ca_cert=ssl_ca_cert,
connection_pool_maxsize=_to_int(connection_pool_maxsize), auth_basic=_to_bool(auth_basic),
profilers=profilers)
profilers=profilers, proxy=proxy)

@classmethod
def from_env_properties(cls, debug=None, enable_gzip=False):
Expand Down
14 changes: 14 additions & 0 deletions tests/config-enabled-proxy.ini
Original file line number Diff line number Diff line change
@@ -0,0 +1,14 @@
[influx2]
url=http://localhost:8086
org=my-org
token=my-token
timeout=6000
connection_pool_maxsize=55
auth_basic=false
profilers=query, operator
proxy=http://proxy.domain.org:8080

[tags]
id = 132-987-655
customer = California Miner
data_center = ${env.data_center}
5 changes: 5 additions & 0 deletions tests/test_InfluxDBClient.py
Original file line number Diff line number Diff line change
Expand Up @@ -75,6 +75,11 @@ def assertConfig(self):
self.assertEqual(False, self.client.api_client.configuration.auth_basic)
self.assertEqual(["query", "operator"], self.client.profilers)

def test_init_from_file_proxy(self):
self.client = InfluxDBClient.from_config_file(f'{os.path.dirname(__file__)}/config-enabled-proxy.ini')
self.assertConfig()
self.assertEqual("http://proxy.domain.org:8080", self.client.api_client.configuration.proxy)

def test_init_from_file_ssl_default(self):
self.client = InfluxDBClient.from_config_file(f'{os.path.dirname(__file__)}/config.ini')

Expand Down