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 2 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
13 changes: 11 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,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
Copy link
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Since you're slicing the string here, perhaps it would make sense to first cast the input to a string (similar to the above port cast)?

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

So you'e prefer something like:

_path = str(path)
self.__path = _path if not _path or _path[0] == '/' else '/' + _path

Any other suggestion how to make this look better?

Copy link
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

It dosen't have to be a oneliner

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Sure, my suggestion was no longer a one-liner either. What should it be like?

self._username = username
self._password = password
self._database = database
Expand Down Expand Up @@ -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',
Expand All @@ -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
Expand Down
12 changes: 12 additions & 0 deletions influxdb/tests/client_test.py
Original file line number Diff line number Diff line change
Expand Up @@ -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')
Expand Down