Skip to content

Commit 38fc35c

Browse files
committed
feat: add API to check build type of InfluxDB instance
1 parent d2ab4d7 commit 38fc35c

File tree

5 files changed

+37
-5
lines changed

5 files changed

+37
-5
lines changed

influxdb_client/client/_base.py

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -98,10 +98,10 @@ 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 _version(self, response) -> str:
101+
def _response_header(self, response, header_name='X-Influxdb-Version') -> str:
102102
if response is not None and len(response) >= 3:
103-
if 'X-Influxdb-Version' in response[2]:
104-
return response[2]['X-Influxdb-Version']
103+
if header_name in response[2]:
104+
return response[2][header_name]
105105

106106
return "unknown"
107107

influxdb_client/client/influxdb_client.py

Lines changed: 13 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -407,7 +407,19 @@ def version(self) -> str:
407407

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

410-
return self._version(response)
410+
return self._response_header(response)
411+
412+
def build(self) -> str:
413+
"""
414+
Return the build type of the connected InfluxDB Server.
415+
416+
:return: The type of InfluxDB build.
417+
"""
418+
ping_service = PingService(self.api_client)
419+
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')
411423

412424
def ready(self) -> Ready:
413425
"""

influxdb_client/client/influxdb_client_async.py

Lines changed: 12 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -251,7 +251,18 @@ 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._version(response)
254+
return self._response_header(response)
255+
256+
async def build(self) -> str:
257+
"""
258+
Return the build type of the connected InfluxDB Server.
259+
260+
:return: The type of InfluxDB build.
261+
"""
262+
ping_service = PingService(self.api_client)
263+
264+
response = await ping_service.get_ping_async(_return_http_data_only=False)
265+
return self._response_header(response, header_name='X-Influxdb-Build')
255266

256267
def query_api(self, query_options: QueryOptions = QueryOptions()) -> QueryApiAsync:
257268
"""

tests/test_InfluxDBClient.py

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -316,6 +316,10 @@ def test_version(self):
316316
version = self.client.version()
317317
self.assertTrue(len(version) > 0)
318318

319+
def test_build(self):
320+
build = self.client.build()
321+
self.assertEqual('oss', build.lower())
322+
319323
def test_version_not_running_instance(self):
320324
client_not_running = InfluxDBClient("http://localhost:8099", token="my-token", debug=True)
321325
with self.assertRaises(NewConnectionError):

tests/test_InfluxDBClientAsync.py

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -49,6 +49,11 @@ async def test_version(self):
4949
version = await self.client.version()
5050
self.assertTrue(len(version) > 0)
5151

52+
@async_test
53+
async def test_build(self):
54+
build = await self.client.build()
55+
self.assertEqual('oss', build.lower())
56+
5257
def test_create_query_api(self):
5358
query_api = self.client.query_api()
5459
self.assertIsNotNone(query_api)

0 commit comments

Comments
 (0)