Skip to content

Commit 85c7b39

Browse files
committed
chore: add API documentation, option types and assert for flight_client_options
1 parent 6c631c0 commit 85c7b39

File tree

2 files changed

+45
-4
lines changed

2 files changed

+45
-4
lines changed

influxdb_client_3/query/query_api.py

Lines changed: 39 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -8,12 +8,31 @@
88

99

1010
class QueryApiOptions(object):
11-
tls_root_certs = None
12-
tls_verify = None
13-
proxy = None
14-
flight_client_options = None
11+
"""
12+
Structure for encapsulating options for the QueryApi
13+
14+
Attributes
15+
----------
16+
tls_root_certs (bytes): contents of an SSL root certificate or chain read as bytes
17+
tls_verify (bool): whether to verify SSL certificates or not
18+
proxy (str): URL to a proxy server
19+
flight_client_options (dict): base set of flight client options passed to internal pyarrow.flight.FlightClient
20+
"""
21+
tls_root_certs: bytes = None
22+
tls_verify: bool = None
23+
proxy: str = None
24+
flight_client_options: dict = None
1525

1626
def __init__(self, root_certs_path, verify, proxy, flight_client_options):
27+
"""
28+
Initialize a set of QueryApiOptions
29+
30+
:param root_certs_path: path to a certificate .pem file.
31+
:param verify: whether to verify SSL certificates or not.
32+
:param proxy: URL of a proxy server, if required.
33+
:param flight_client_options: set of flight_client_options
34+
to be passed to internal pyarrow.flight.FlightClient.
35+
"""
1736
if root_certs_path:
1837
self.tls_root_certs = self._read_certs(root_certs_path)
1938
self.tls_verify = verify
@@ -26,7 +45,21 @@ def _read_certs(self, path):
2645

2746

2847
class QueryApiOptionsBuilder(object):
48+
"""
49+
Helper class to make adding QueryApiOptions more dynamic.
2950
51+
Example:
52+
53+
.. code-block:: python
54+
55+
options = QueryApiOptionsBuilder()\
56+
.proxy("http://internal.tunnel.proxy:8080") \
57+
.root_certs("/home/fred/.etc/ssl/alt_certs.pem") \
58+
.tls_verify(True) \
59+
.build()
60+
61+
client = QueryApi(connection, token, None, None, options)
62+
"""
3063
_root_certs_path = None
3164
_tls_verify = True
3265
_proxy = None
@@ -49,6 +82,7 @@ def flight_client_options(self, flight_client_options):
4982
return self
5083

5184
def build(self):
85+
"""Build a QueryApiOptions object with previously set values"""
5286
return QueryApiOptions(
5387
root_certs_path=self._root_certs_path,
5488
verify=self._tls_verify,
@@ -62,6 +96,7 @@ class QueryApi(object):
6296
Implementation for '/api/v2/query' endpoint.
6397
6498
Example:
99+
65100
.. code-block:: python
66101
67102
from influxdb_client import InfluxDBClient

tests/test_query.py

Lines changed: 6 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -228,11 +228,15 @@ def test_query_client_with_options(self):
228228
token = "my_token"
229229
proxy_name = "http://my.proxy.org"
230230
cert_file = "cert_test.pem"
231+
private_key = 'our_key'
232+
cert_chain = 'mTLS_explicit_chain'
231233
self.create_cert_file(cert_file)
234+
test_flight_client_options = {'private_key': private_key, 'cert_chain': cert_chain}
232235
options = QueryApiOptionsBuilder()\
233236
.proxy(proxy_name) \
234237
.root_certs(cert_file) \
235238
.tls_verify(False) \
239+
.flight_client_options(test_flight_client_options) \
236240
.build()
237241

238242
client = QueryApi(connection,
@@ -245,6 +249,8 @@ def test_query_client_with_options(self):
245249
try:
246250
assert client._token == token
247251
assert client._flight_client_options['tls_root_certs'].decode('utf-8') == self.sample_cert
252+
assert client._flight_client_options['private_key'] == private_key
253+
assert client._flight_client_options['cert_chain'] == cert_chain
248254
assert client._proxy == proxy_name
249255
fc_opts = client._flight_client_options
250256
assert dict(fc_opts['generic_options'])['grpc.secondary_user_agent'].startswith('influxdb3-python/')

0 commit comments

Comments
 (0)