From afa862183c8b9d21fb4bdf051e6ef76c2b0d04b0 Mon Sep 17 00:00:00 2001 From: Lloyd Wallis Date: Fri, 11 Jan 2019 11:22:51 +0000 Subject: [PATCH 1/2] Add support for providing a client certificate for mutual TLS authentication. --- influxdb/client.py | 14 ++++++++++++++ influxdb/tests/client_test.py | 8 ++++++++ 2 files changed, 22 insertions(+) diff --git a/influxdb/client.py b/influxdb/client.py index 8ac557d3..283294c1 100644 --- a/influxdb/client.py +++ b/influxdb/client.py @@ -61,6 +61,11 @@ class InfluxDBClient(object): :type proxies: dict :param path: path of InfluxDB on the server to connect, defaults to '' :type path: str + :param cert: Path to client certificate to use for mutual TLS + authentication, defaults to None + :type cert: str + + :raises ValueError: if cert is provided but ssl is disabled (set to False) """ def __init__(self, @@ -78,6 +83,7 @@ def __init__(self, proxies=None, pool_size=10, path='', + cert=None, ): """Construct a new InfluxDBClient object.""" self.__host = host @@ -120,6 +126,14 @@ def __init__(self, else: self._proxies = proxies + if cert: + if not ssl: + raise ValueError( + "Client certificate provided but ssl is disabled." + ) + else: + self._session.cert = cert + self.__baseurl = "{0}://{1}:{2}{3}".format( self._scheme, self._host, diff --git a/influxdb/tests/client_test.py b/influxdb/tests/client_test.py index e4cc7e11..b741cf7a 100644 --- a/influxdb/tests/client_test.py +++ b/influxdb/tests/client_test.py @@ -149,6 +149,14 @@ def test_dsn(self): **{'ssl': False}) self.assertEqual('http://my.host.fr:1886', cli._baseurl) + def test_cert(self): + """Test mutual TLS authentication for TestInfluxDBClient object.""" + cli = InfluxDBClient(ssl=True, cert='/etc/pki/tls/private/dummy.crt') + self.assertEqual(cli._session.cert, '/etc/pki/tls/private/dummy.crt') + + with self.assertRaises(ValueError): + cli = InfluxDBClient(cert='/etc/pki/tls/private/dummy.crt') + def test_switch_database(self): """Test switch database in TestInfluxDBClient object.""" cli = InfluxDBClient('host', 8086, 'username', 'password', 'database') From e4d6b131c4fcd3609c6bf8c7e12b11ba28940b11 Mon Sep 17 00:00:00 2001 From: Lloyd Wallis Date: Thu, 16 May 2019 11:54:50 +0100 Subject: [PATCH 2/2] Be more explicit in documentation on valid values for the parameter --- influxdb/client.py | 6 ++++-- 1 file changed, 4 insertions(+), 2 deletions(-) diff --git a/influxdb/client.py b/influxdb/client.py index 283294c1..ad4c6b66 100644 --- a/influxdb/client.py +++ b/influxdb/client.py @@ -61,8 +61,10 @@ class InfluxDBClient(object): :type proxies: dict :param path: path of InfluxDB on the server to connect, defaults to '' :type path: str - :param cert: Path to client certificate to use for mutual TLS - authentication, defaults to None + :param cert: Path to client certificate information to use for mutual TLS + authentication. You can specify a local cert to use + as a single file containing the private key and the certificate, or as + a tuple of both files’ paths, defaults to None :type cert: str :raises ValueError: if cert is provided but ssl is disabled (set to False) 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