Skip to content

Commit f8063f9

Browse files
feat: Make TLS/SSL certificate verification optional (#126)
1 parent 59577cc commit f8063f9

File tree

3 files changed

+29
-0
lines changed

3 files changed

+29
-0
lines changed
Lines changed: 11 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,11 @@
1+
"""Example to demonstrate disabling TLS/SSL certificate verification for connections"""
2+
3+
from nisystemlink.clients.core import HttpConfigurationManager
4+
from nisystemlink.clients.file import FileClient
5+
6+
# explicitly get the http config and set the verify option
7+
http_config = HttpConfigurationManager.get_configuration()
8+
http_config.verify = False
9+
10+
client = FileClient(configuration=http_config)
11+
print(client.api_info())

nisystemlink/clients/core/_http_configuration.py

Lines changed: 13 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -23,6 +23,7 @@ def __init__(
2323
password: Optional[str] = None,
2424
cert_path: Optional[pathlib.Path] = None,
2525
workspace: Optional[str] = None,
26+
verify: bool = True,
2627
) -> None:
2728
"""Initialize a configuration.
2829
@@ -40,6 +41,7 @@ def __init__(
4041
password: The user's password to use when authorization is required.
4142
cert_path: Local path to an SSL certificate file.
4243
workspace: ID of workspace to use for client operations.
44+
verify: Verify the security certificate for connection
4345
4446
Raises:
4547
ValueError: if ``server_uri`` is missing scheme or host information.
@@ -73,6 +75,17 @@ def __init__(
7375

7476
self._workspace = workspace
7577

78+
self._verify = verify
79+
80+
@property
81+
def verify(self) -> bool:
82+
"""Verify the security certificate for connection."""
83+
return self._verify
84+
85+
@verify.setter
86+
def verify(self, value: bool) -> None:
87+
self._verify = value
88+
7689
@property
7790
def timeout_milliseconds(self) -> int: # noqa: D401
7891
"""The number of milliseconds before a request times out with an error.

nisystemlink/clients/core/_uplink/_base_client.py

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -3,6 +3,7 @@
33
from json import loads
44
from typing import Any, Callable, Dict, get_origin, Optional, Type, Union
55

6+
import requests
67
from nisystemlink.clients import core
78
from pydantic import parse_obj_as
89
from requests import JSONDecodeError, Response
@@ -79,10 +80,14 @@ def __init__(self, configuration: core.HttpConfiguration, base_path: str = ""):
7980
configuration: Defines the web server to connect to and information about how to connect.
8081
base_path: The base path for all API calls.
8182
"""
83+
session = requests.Session()
84+
session.verify = configuration.verify
85+
8286
super().__init__(
8387
base_url=configuration.server_uri + base_path,
8488
converter=_JsonModelConverter(),
8589
hooks=[_handle_http_status],
90+
client=session,
8691
)
8792
if configuration.api_keys:
8893
self.session.headers.update(configuration.api_keys)

0 commit comments

Comments
 (0)