From 74470bb34c9b9ac1382ca9d98d4a17eb9cdec10f Mon Sep 17 00:00:00 2001 From: Frederik Gladhorn Date: Mon, 15 Jan 2018 16:02:53 +0100 Subject: [PATCH 1/2] Allow connecting to influxdb running on a path on the server Make it possible to connect to the databases on a path on servers. https://someserver.com/myinfluxdb instead of the root of the server. --- influxdb/client.py | 13 +++++++++++-- influxdb/tests/client_test.py | 12 ++++++++++++ 2 files changed, 23 insertions(+), 2 deletions(-) diff --git a/influxdb/client.py b/influxdb/client.py index 01559cfc..50cc2dbe 100644 --- a/influxdb/client.py +++ b/influxdb/client.py @@ -59,6 +59,8 @@ class InfluxDBClient(object): :type udp_port: int :param proxies: HTTP(S) proxy to use for Requests, defaults to {} :type proxies: dict + :param path: path of InfluxDB on the server to connect, defaults to '' + :type path: str """ def __init__(self, @@ -75,10 +77,12 @@ def __init__(self, udp_port=4444, proxies=None, pool_size=10, + path='', ): """Construct a new InfluxDBClient object.""" self.__host = host self.__port = int(port) + self.__path = path if not path or path[0] == '/' else '/' + path self._username = username self._password = password self._database = database @@ -110,10 +114,11 @@ def __init__(self, else: self._proxies = proxies - self.__baseurl = "{0}://{1}:{2}".format( + self.__baseurl = "{0}://{1}:{2}{3}".format( self._scheme, self._host, - self._port) + self._port, + self._path) self._headers = { 'Content-Type': 'application/json', @@ -132,6 +137,10 @@ def _host(self): def _port(self): return self.__port + @property + def _path(self): + return self.__path + @property def _udp_port(self): return self.__udp_port diff --git a/influxdb/tests/client_test.py b/influxdb/tests/client_test.py index ff325907..2c5e443c 100644 --- a/influxdb/tests/client_test.py +++ b/influxdb/tests/client_test.py @@ -109,6 +109,18 @@ def test_scheme(self): ) self.assertEqual('https://host:8086', cli._baseurl) + cli = InfluxDBClient( + 'host', 8086, 'username', 'password', 'database', ssl=True, + path="somepath" + ) + self.assertEqual('https://host:8086/somepath', cli._baseurl) + + cli = InfluxDBClient( + 'host', 8086, 'username', 'password', 'database', ssl=True, + path="/somepath" + ) + self.assertEqual('https://host:8086/somepath', cli._baseurl) + def test_dsn(self): """Set up the test datasource name for TestInfluxDBClient object.""" cli = InfluxDBClient.from_dsn('influxdb://192.168.0.1:1886') From fadd5c4db9064c1e1b9e2ab40a8b8063ce770e70 Mon Sep 17 00:00:00 2001 From: Michael Wyraz Date: Wed, 4 Apr 2018 20:21:47 +0200 Subject: [PATCH 2/2] Test and fix for None path --- influxdb/client.py | 8 +++++++- influxdb/tests/client_test.py | 6 ++++++ 2 files changed, 13 insertions(+), 1 deletion(-) diff --git a/influxdb/client.py b/influxdb/client.py index 1a7cbbdf..62d5a025 100644 --- a/influxdb/client.py +++ b/influxdb/client.py @@ -82,7 +82,6 @@ def __init__(self, """Construct a new InfluxDBClient object.""" self.__host = host self.__port = int(port) - self.__path = path if not path or path[0] == '/' else '/' + path self._username = username self._password = password self._database = database @@ -102,6 +101,13 @@ def __init__(self, if use_udp: self.udp_socket = socket.socket(socket.AF_INET, socket.SOCK_DGRAM) + if not path: + self.__path = '' + elif path[0] == '/': + self.__path = path + else: + self.__path = '/' + path + self._scheme = "http" if ssl is True: diff --git a/influxdb/tests/client_test.py b/influxdb/tests/client_test.py index d35d0628..efdfb770 100644 --- a/influxdb/tests/client_test.py +++ b/influxdb/tests/client_test.py @@ -115,6 +115,12 @@ def test_scheme(self): ) self.assertEqual('https://host:8086/somepath', cli._baseurl) + cli = InfluxDBClient( + 'host', 8086, 'username', 'password', 'database', ssl=True, + path=None + ) + self.assertEqual('https://host:8086', cli._baseurl) + cli = InfluxDBClient( 'host', 8086, 'username', 'password', 'database', ssl=True, path="/somepath" pFad - Phonifier reborn

Pfad - The Proxy pFad of © 2024 Garber Painting. All rights reserved.

Note: This service is not intended for secure transactions such as banking, social media, email, or purchasing. Use at your own risk. We assume no liability whatsoever for broken pages.


Alternative Proxies:

Alternative Proxy

pFad Proxy

pFad v3 Proxy

pFad v4 Proxy