Skip to content

Commit 7d8d9e0

Browse files
authored
Merge pull request #199 from jsteemann/feature/certificate-verification
allow to disable TLS certificate verification
2 parents b69a0df + 4ff5c4d commit 7d8d9e0

File tree

2 files changed

+40
-0
lines changed

2 files changed

+40
-0
lines changed

arango/client.py

Lines changed: 10 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -45,6 +45,8 @@ class ArangoClient:
4545
the de-serialized object. If not given, ``json.loads`` is used by
4646
default.
4747
:type deserializer: callable
48+
:param verify_certificate: Verify TLS certificates.
49+
:type verify_certificate: bool
4850
"""
4951

5052
def __init__(
@@ -55,6 +57,7 @@ def __init__(
5557
http_client: Optional[HTTPClient] = None,
5658
serializer: Callable[..., str] = lambda x: dumps(x),
5759
deserializer: Callable[[str], Any] = lambda x: loads(x),
60+
verify_certificate: bool = True,
5861
) -> None:
5962
if isinstance(hosts, str):
6063
self._hosts = [host.strip("/") for host in hosts.split(",")]
@@ -76,6 +79,10 @@ def __init__(
7679
self._deserializer = deserializer
7780
self._sessions = [self._http.create_session(h) for h in self._hosts]
7881

82+
# set flag for SSL/TLS certificate verification
83+
for session in self._sessions:
84+
session.verify = verify_certificate
85+
7986
def __repr__(self) -> str:
8087
return f"<ArangoClient {','.join(self._hosts)}>"
8188

@@ -110,6 +117,7 @@ def db(
110117
verify: bool = False,
111118
auth_method: str = "basic",
112119
superuser_token: Optional[str] = None,
120+
verify_certificate: bool = True,
113121
) -> StandardDatabase:
114122
"""Connect to an ArangoDB database and return the database API wrapper.
115123
@@ -130,6 +138,8 @@ def db(
130138
If set, parameters **username**, **password** and **auth_method**
131139
are ignored. This token is not refreshed automatically.
132140
:type superuser_token: str
141+
:param verify_certificate: Verify TLS certificates.
142+
:type verify_certificate: bool
133143
:return: Standard database API wrapper.
134144
:rtype: arango.database.StandardDatabase
135145
:raise arango.exceptions.ServerConnectionError: If **verify** was set

docs/certificates.rst

Lines changed: 30 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,30 @@
1+
TLS certificate verification
2+
----------------------------
3+
4+
When connecting against a server using an https/TLS connection, TLS certificates
5+
are verified by default.
6+
By default, self-signed certificates will cause trouble when connecting.
7+
8+
.. code-block:: python
9+
10+
client = ArangoClient(hosts="https://localhost:8529")
11+
12+
In order to make connections work even when using self-signed certificates, the
13+
`verify_certificates` option can be disabled when creating the `ArangoClient`
14+
instance:
15+
16+
.. code-block:: python
17+
18+
client = ArangoClient(hosts="https://localhost:8529", verify_certificate=False)
19+
20+
This will allow connecting, but the underlying `urllib3` library may still issue
21+
warnings due to the insecurity of using self-signed certificates.
22+
23+
To turn off these warnings as well, you can add the following code to your client
24+
application:
25+
26+
.. code-block:: python
27+
28+
import requests
29+
requests.packages.urllib3.disable_warnings()
30+

0 commit comments

Comments
 (0)