Skip to content

Commit 781438b

Browse files
authored
Merge pull request #110 from doccano/feature/add-verify-option
Add verify option
2 parents 007887b + 2251034 commit 781438b

File tree

3 files changed

+39
-3
lines changed

3 files changed

+39
-3
lines changed

doccano_client/client.py

Lines changed: 15 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -66,8 +66,21 @@
6666

6767

6868
class DoccanoClient:
69-
def __init__(self, base_url: str):
70-
self._base_repository = BaseRepository(base_url)
69+
def __init__(self, base_url: str, verify: Optional[str | bool] = None):
70+
"""Initialize the client.
71+
72+
Args:
73+
base_url (str): The base url of the Doccano instance
74+
verify (str | bool): Either a boolean, in which case it controls whether we verify
75+
the server's TLS certificate, or a string, in which case it must be a path
76+
to a CA bundle to use. Defaults to ``True``. When set to
77+
``False``, requests will accept any TLS certificate presented by
78+
the server, and will ignore hostname mismatches and/or expired
79+
certificates, which will make your application vulnerable to
80+
man-in-the-middle (MitM) attacks. Setting verify to ``False``
81+
may be useful during local development or testing.
82+
"""
83+
self._base_repository = BaseRepository(base_url, verify=verify)
7184
self._user_repository = UserRepository(self._base_repository)
7285
self._role_repository = RoleRepository(self._base_repository)
7386
self._project_repository = ProjectRepository(self._base_repository)

doccano_client/repositories/base.py

Lines changed: 20 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,3 +1,7 @@
1+
from __future__ import annotations
2+
3+
from typing import Optional
4+
15
import requests
26
from requests import Response, exceptions
37

@@ -34,9 +38,24 @@ def verbose_raise_for_status(response: Response) -> Response:
3438
class BaseRepository:
3539
"""Base repository for interacting with the Doccano API"""
3640

37-
def __init__(self, base_url: str) -> None:
41+
def __init__(self, base_url: str, verify: Optional[str | bool] = None) -> None:
42+
"""Initialize the repository with the base url
43+
44+
Args:
45+
base_url (str): The base url of the Doccano instance
46+
verify (str | bool): Either a boolean, in which case it controls whether we verify
47+
the server's TLS certificate, or a string, in which case it must be a path
48+
to a CA bundle to use. Defaults to ``True``. When set to
49+
``False``, requests will accept any TLS certificate presented by
50+
the server, and will ignore hostname mismatches and/or expired
51+
certificates, which will make your application vulnerable to
52+
man-in-the-middle (MitM) attacks. Setting verify to ``False``
53+
may be useful during local development or testing.
54+
"""
3855
self._base_url = base_url
3956
self._session = requests.Session()
57+
if verify is not None:
58+
self._session.verify = verify
4059
headers = {
4160
"content-type": "application/json",
4261
"accept": "application/json",

docs/usage.md

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,9 @@
11
# Usage
22

3+
## Initialization
4+
5+
::: doccano_client.DoccanoClient.__init__
6+
37
## Authentication
48

59
::: doccano_client.DoccanoClient.login

0 commit comments

Comments
 (0)