Skip to content

Commit f3c6acf

Browse files
gladhornxginn8
authored andcommitted
Allow connecting to influxdb running on a path on the server (influxdata#556)
* 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. * Test and fix for None path
1 parent ed4561b commit f3c6acf

File tree

2 files changed

+35
-2
lines changed

2 files changed

+35
-2
lines changed

influxdb/client.py

Lines changed: 17 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -59,6 +59,8 @@ class InfluxDBClient(object):
5959
:type udp_port: int
6060
:param proxies: HTTP(S) proxy to use for Requests, defaults to {}
6161
:type proxies: dict
62+
:param path: path of InfluxDB on the server to connect, defaults to ''
63+
:type path: str
6264
"""
6365

6466
def __init__(self,
@@ -75,6 +77,7 @@ def __init__(self,
7577
udp_port=4444,
7678
proxies=None,
7779
pool_size=10,
80+
path='',
7881
):
7982
"""Construct a new InfluxDBClient object."""
8083
self.__host = host
@@ -98,6 +101,13 @@ def __init__(self,
98101
if use_udp:
99102
self.udp_socket = socket.socket(socket.AF_INET, socket.SOCK_DGRAM)
100103

104+
if not path:
105+
self.__path = ''
106+
elif path[0] == '/':
107+
self.__path = path
108+
else:
109+
self.__path = '/' + path
110+
101111
self._scheme = "http"
102112

103113
if ssl is True:
@@ -110,10 +120,11 @@ def __init__(self,
110120
else:
111121
self._proxies = proxies
112122

113-
self.__baseurl = "{0}://{1}:{2}".format(
123+
self.__baseurl = "{0}://{1}:{2}{3}".format(
114124
self._scheme,
115125
self._host,
116-
self._port)
126+
self._port,
127+
self._path)
117128

118129
self._headers = {
119130
'Content-Type': 'application/json',
@@ -132,6 +143,10 @@ def _host(self):
132143
def _port(self):
133144
return self.__port
134145

146+
@property
147+
def _path(self):
148+
return self.__path
149+
135150
@property
136151
def _udp_port(self):
137152
return self.__udp_port

influxdb/tests/client_test.py

Lines changed: 18 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -109,6 +109,24 @@ def test_scheme(self):
109109
)
110110
self.assertEqual('https://host:8086', cli._baseurl)
111111

112+
cli = InfluxDBClient(
113+
'host', 8086, 'username', 'password', 'database', ssl=True,
114+
path="somepath"
115+
)
116+
self.assertEqual('https://host:8086/somepath', cli._baseurl)
117+
118+
cli = InfluxDBClient(
119+
'host', 8086, 'username', 'password', 'database', ssl=True,
120+
path=None
121+
)
122+
self.assertEqual('https://host:8086', cli._baseurl)
123+
124+
cli = InfluxDBClient(
125+
'host', 8086, 'username', 'password', 'database', ssl=True,
126+
path="/somepath"
127+
)
128+
self.assertEqual('https://host:8086/somepath', cli._baseurl)
129+
112130
def test_dsn(self):
113131
"""Set up the test datasource name for TestInfluxDBClient object."""
114132
cli = InfluxDBClient.from_dsn('influxdb://192.168.0.1:1886')

0 commit comments

Comments
 (0)
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