Skip to content
This repository has been archived by the owner on Oct 29, 2024. It is now read-only.

Allow connecting to influxdb running on a path on the server #556

Merged
merged 6 commits into from
May 8, 2018
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
19 changes: 17 additions & 2 deletions influxdb/client.py
Original file line number Diff line number Diff line change
Expand Up @@ -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,
Expand All @@ -75,6 +77,7 @@ def __init__(self,
udp_port=4444,
proxies=None,
pool_size=10,
path='',
):
"""Construct a new InfluxDBClient object."""
self.__host = host
Expand All @@ -98,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:
Expand All @@ -110,10 +120,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',
Expand All @@ -132,6 +143,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
Expand Down
18 changes: 18 additions & 0 deletions influxdb/tests/client_test.py
Original file line number Diff line number Diff line change
Expand Up @@ -109,6 +109,24 @@ 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=None
)
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)

def test_dsn(self):
"""Set up the test datasource name for TestInfluxDBClient object."""
cli = InfluxDBClient.from_dsn('influxdb://192.168.0.1:1886')
Expand Down