Skip to content

Commit 62ba5f7

Browse files
committed
feat: prepare to add warning into API call
1 parent 38fc35c commit 62ba5f7

File tree

6 files changed

+51
-22
lines changed

6 files changed

+51
-22
lines changed

influxdb_client/client/_base.py

Lines changed: 0 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -98,13 +98,6 @@ def __init__(self, url, token, debug=None, timeout=10_000, enable_gzip=False, or
9898
self.profilers = kwargs.get('profilers', None)
9999
pass
100100

101-
def _response_header(self, response, header_name='X-Influxdb-Version') -> str:
102-
if response is not None and len(response) >= 3:
103-
if header_name in response[2]:
104-
return response[2][header_name]
105-
106-
return "unknown"
107-
108101
@classmethod
109102
def _from_config_file(cls, config_file: str = "config.ini", debug=None, enable_gzip=False, **kwargs):
110103
config = configparser.ConfigParser()

influxdb_client/client/influxdb_client.py

Lines changed: 2 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -407,7 +407,7 @@ def version(self) -> str:
407407

408408
response = ping_service.get_ping_with_http_info(_return_http_data_only=False)
409409

410-
return self._response_header(response)
410+
return ping_service.response_header(response)
411411

412412
def build(self) -> str:
413413
"""
@@ -417,9 +417,7 @@ def build(self) -> str:
417417
"""
418418
ping_service = PingService(self.api_client)
419419

420-
response = ping_service.get_ping_with_http_info(_return_http_data_only=False)
421-
422-
return self._response_header(response, header_name='X-Influxdb-Build')
420+
return ping_service.build_type()
423421

424422
def ready(self) -> Ready:
425423
"""

influxdb_client/client/influxdb_client_async.py

Lines changed: 2 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -251,7 +251,7 @@ async def version(self) -> str:
251251
ping_service = PingService(self.api_client)
252252

253253
response = await ping_service.get_ping_async(_return_http_data_only=False)
254-
return self._response_header(response)
254+
return ping_service.response_header(response)
255255

256256
async def build(self) -> str:
257257
"""
@@ -261,8 +261,7 @@ async def build(self) -> str:
261261
"""
262262
ping_service = PingService(self.api_client)
263263

264-
response = await ping_service.get_ping_async(_return_http_data_only=False)
265-
return self._response_header(response, header_name='X-Influxdb-Build')
264+
return await ping_service.build_type_async()
266265

267266
def query_api(self, query_options: QueryOptions = QueryOptions()) -> QueryApiAsync:
268267
"""

influxdb_client/service/_base_service.py

Lines changed: 44 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -2,6 +2,13 @@
22

33
# noinspection PyMethodMayBeStatic
44
class _BaseService(object):
5+
6+
def __init__(self, api_client=None):
7+
"""Init common services operation."""
8+
if api_client is None:
9+
raise ValueError("Invalid value for `api_client`, must be defined.")
10+
self.api_client = api_client
11+
512
def _check_operation_params(self, operation_id, supported_params, local_params):
613
supported_params.append('async_req')
714
supported_params.append('_return_http_data_only')
@@ -16,3 +23,40 @@ def _check_operation_params(self, operation_id, supported_params, local_params):
1623
)
1724
local_params[key] = val
1825
del local_params['kwargs']
26+
27+
def _is_cloud_instance(self) -> bool:
28+
return False
29+
30+
async def _is_cloud_instance_async(self) -> bool:
31+
return False
32+
33+
def build_type(self) -> str:
34+
"""
35+
Return the build type of the connected InfluxDB Server.
36+
37+
:return: The type of InfluxDB build.
38+
"""
39+
from influxdb_client import PingService
40+
ping_service = PingService(self.api_client)
41+
42+
response = ping_service.get_ping_with_http_info(_return_http_data_only=False)
43+
return self.response_header(response, header_name='X-Influxdb-Build')
44+
45+
async def build_type_async(self) -> str:
46+
"""
47+
Return the build type of the connected InfluxDB Server.
48+
49+
:return: The type of InfluxDB build.
50+
"""
51+
from influxdb_client import PingService
52+
ping_service = PingService(self.api_client)
53+
54+
response = await ping_service.get_ping_async(_return_http_data_only=False)
55+
return self.response_header(response, header_name='X-Influxdb-Build')
56+
57+
def response_header(self, response, header_name='X-Influxdb-Version') -> str:
58+
if response is not None and len(response) >= 3:
59+
if header_name in response[2]:
60+
return response[2][header_name]
61+
62+
return "unknown"

influxdb_client/service/bucket_schemas_service.py

Lines changed: 1 addition & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -27,13 +27,7 @@ class BucketSchemasService(_BaseService):
2727

2828
def __init__(self, api_client=None): # noqa: E501,D401,D403
2929
"""BucketSchemasService - a operation defined in OpenAPI."""
30-
if api_client is None:
31-
raise ValueError("Invalid value for `api_client`, must be defined.")
32-
self.api_client = api_client
33-
34-
from influxdb_client.client.warnings import CloudOnlyWarning
35-
CloudOnlyWarning.print_warning('BucketSchemasService',
36-
'https://docs.influxdata.com/influxdb/cloud/organizations/buckets/bucket-schema/') # noqa: E501
30+
super().__init__(api_client)
3731

3832
def create_measurement_schema(self, bucket_id, measurement_schema_create_request, **kwargs): # noqa: E501,D401,D403
3933
"""Create a measurement schema for a bucket.

influxdb_client/service/invokable_scripts_service.py

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -33,7 +33,8 @@ def __init__(self, api_client=None): # noqa: E501,D401,D403
3333

3434
from influxdb_client.client.warnings import CloudOnlyWarning
3535
CloudOnlyWarning.print_warning('InvokableScriptsService',
36-
'https://docs.influxdata.com/influxdb/cloud/api-guide/api-invokable-scripts/') # noqa: E501
36+
'https://docs.influxdata.com/influxdb/cloud/api-guide/api-invokable-scripts/',
37+
api_client) # noqa: E501
3738

3839
def delete_scripts_id(self, script_id, **kwargs): # noqa: E501,D401,D403
3940
"""Delete a script.

0 commit comments

Comments
 (0)