Skip to content

feat: add verifySSL param #33

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Open
wants to merge 2 commits into
base: main
Choose a base branch
from
Open
Show file tree
Hide file tree
Changes from all 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
1 change: 1 addition & 0 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -51,6 +51,7 @@ The `InfisicalSDKClient` takes the following parameters, which are used as a glo

- **host** (`str`, _Optional_): The host URL for your Infisical instance. Defaults to `https://app.infisical.com`.
- **token** (`str`, _Optional_): Specify an authentication token to use for all requests. If provided, you will not need to call any of the `auth` methods. Defaults to `None`
- **verifySSL** (`bool`, _Optional_): Whether to run the security certificate check for SSL/TLS connections. Defaults to `True`
- **cache_ttl** (`int`, _Optional_): The SDK has built-in client-side caching for secrets, greatly improving response times. By default, secrets are cached for 1 minute (60 seconds). You can disable caching by setting `cache_ttl` to `None`, or adjust the duration in seconds as needed.

```python
Expand Down
6 changes: 4 additions & 2 deletions infisical_sdk/client.py
Original file line number Diff line number Diff line change
Expand Up @@ -7,19 +7,21 @@
from infisical_sdk.util import SecretsCache

class InfisicalSDKClient:
def __init__(self, host: str, token: str = None, cache_ttl: int = 60):
def __init__(self, host: str, token: str = None, cache_ttl: int = 60, verifySSL: bool = True):
"""
Initialize the Infisical SDK client.

:param str host: The host URL for your Infisical instance. Will default to `https://app.infisical.com` if not specified.
:param str token: The authentication token for the client. If not specified, you can use the `auth` methods to authenticate.
:param int cache_ttl: The time to live for the secrets cache. This is the number of seconds that secrets fetched from the API will be cached for. Set to `None` to disable caching. Defaults to `60` seconds.
:param bool verifySSL: Whether to verify SSL certificates. Set to `False` to disable verification for self-signed certificates. Defaults to `True`.
"""

self.host = host
self.access_token = token
self.verifySSL = verifySSL

self.api = InfisicalRequests(host=host, token=token)
self.api = InfisicalRequests(host=host, token=token, verifySSL=verifySSL)
self.cache = SecretsCache(cache_ttl)
self.auth = Auth(self.api, self.set_token)
self.secrets = V3RawSecrets(self.api, self.cache)
Expand Down
23 changes: 17 additions & 6 deletions infisical_sdk/infisical_requests.py
Original file line number Diff line number Diff line change
Expand Up @@ -51,9 +51,20 @@ def from_dict(cls, data: Dict) -> 'APIResponse[T]':


class InfisicalRequests:
def __init__(self, host: str, token: Optional[str] = None):
"""
Initialize the Infisical requests client.

:param str host: The host URL for your Infisical instance.
:param str token: Optional authentication token for the client.
:param bool verifySSL: Whether to verify SSL certificates. Set to `False` to disable
verification for self-signed certificates. Warning: Disabling
SSL verification may expose you to man-in-the-middle attacks.
Only use in development or with trusted networks. Defaults to `True`.
"""
def __init__(self, host: str, token: Optional[str] = None, verifySSL: bool = True):
self.host = host.rstrip("/")
self.session = requests.Session()
self.verifySSL = verifySSL

# Set common headers
self.session.headers.update({
Expand Down Expand Up @@ -108,7 +119,7 @@ def get(
model: model class to parse response into
params: Optional query parameters
"""
response = self.session.get(self._build_url(path), params=params)
response = self.session.get(self._build_url(path), params=params, verify=self.verifySSL)
data = self._handle_response(response)

parsed_data = model.from_dict(data) if hasattr(model, 'from_dict') else data
Expand All @@ -132,7 +143,7 @@ def post(
# Filter out None values
json = {k: v for k, v in json.items() if v is not None}

response = self.session.post(self._build_url(path), json=json)
response = self.session.post(self._build_url(path), json=json, verify=self.verifySSL)
data = self._handle_response(response)

parsed_data = model.from_dict(data) if hasattr(model, 'from_dict') else data
Expand All @@ -156,7 +167,7 @@ def patch(
# Filter out None values
json = {k: v for k, v in json.items() if v is not None}

response = self.session.patch(self._build_url(path), json=json)
response = self.session.patch(self._build_url(path), json=json, verify=self.verifySSL)
data = self._handle_response(response)

parsed_data = model.from_dict(data) if hasattr(model, 'from_dict') else data
Expand All @@ -174,13 +185,13 @@ def delete(
json: Optional[Dict[str, Any]] = None
) -> APIResponse[T]:

"""Make a PATCH request with JSON data"""
"""Make a DELETE request with JSON data"""

if json is not None:
# Filter out None values
json = {k: v for k, v in json.items() if v is not None}

response = self.session.delete(self._build_url(path), json=json)
response = self.session.delete(self._build_url(path), json=json, verify=self.verifySSL)
data = self._handle_response(response)

parsed_data = model.from_dict(data) if hasattr(model, 'from_dict') else data
Expand Down