@@ -69,44 +69,79 @@ def __init__(self, url, token, debug=None, timeout=10000, enable_gzip=False, org
6969 @classmethod
7070 def from_config_file (cls , config_file : str = "config.ini" , debug = None , enable_gzip = False ):
7171 """
72- Configure client via '*.ini' file in segment 'influx2' .
72+ Configure client via configuration file. The configuration has to be under 'influx' section .
7373
74- Supported options:
74+ The supported formats:
75+ - https://docs.python.org/3/library/configparser.html
76+ - https://toml.io/en/
77+
78+ Configuration options:
7579 - url
7680 - org
7781 - token
7882 - timeout,
7983 - verify_ssl
8084 - ssl_ca_cert
85+
86+ config.ini example::
87+
88+ [influx2]
89+ url=http://localhost:8086
90+ org=my-org
91+ token=my-token
92+ timeout=6000
93+
94+ [tags]
95+ id = 132-987-655
96+ customer = California Miner
97+ data_center = ${env.data_center}
98+
99+ config.toml example::
100+
101+ [influx2]
102+ url = "http://localhost:8086"
103+ token = "my-token"
104+ org = "my-org"
105+ timeout = 6000
106+
107+ [tags]
108+ id = "132-987-655"
109+ customer = "California Miner"
110+ data_center = "${env.data_center}"
111+
81112 """
82113 config = configparser .ConfigParser ()
83114 config .read (config_file )
84115
85- url = config ['influx2' ]['url' ]
86- token = config ['influx2' ]['token' ]
116+ def config_value (key : str ):
117+ return config ['influx2' ][key ].strip ('"' )
118+
119+ url = config_value ('url' )
120+ token = config_value ('token' )
87121
88122 timeout = None
89123
90124 if config .has_option ('influx2' , 'timeout' ):
91- timeout = config [ 'influx2' ][ ' timeout']
125+ timeout = config_value ( ' timeout')
92126
93127 org = None
94128
95129 if config .has_option ('influx2' , 'org' ):
96- org = config [ 'influx2' ][ ' org']
130+ org = config_value ( ' org')
97131
98132 verify_ssl = True
99133 if config .has_option ('influx2' , 'verify_ssl' ):
100- verify_ssl = config [ 'influx2' ][ ' verify_ssl']
134+ verify_ssl = config_value ( ' verify_ssl')
101135
102136 ssl_ca_cert = None
103137 if config .has_option ('influx2' , 'ssl_ca_cert' ):
104- ssl_ca_cert = config [ 'influx2' ][ ' ssl_ca_cert']
138+ ssl_ca_cert = config_value ( ' ssl_ca_cert')
105139
106140 default_tags = None
107141
108142 if config .has_section ('tags' ):
109- default_tags = dict (config .items ('tags' ))
143+ tags = {k : v .strip ('"' ) for k , v in config .items ('tags' )}
144+ default_tags = dict (tags )
110145
111146 if timeout :
112147 return cls (url , token , debug = debug , timeout = int (timeout ), org = org , default_tags = default_tags ,
0 commit comments