Skip to content

Commit c7bd8fb

Browse files
committed
fix: requested changes
1 parent f10e6fb commit c7bd8fb

File tree

4 files changed

+50
-8
lines changed

4 files changed

+50
-8
lines changed

README.md

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -47,11 +47,11 @@ secrets = client.secrets.list_secrets(project_id="<project-id>", environment_slu
4747

4848
## InfisicalSDKClient Parameters
4949

50-
The `InfisicalSDKClient` takes the following parameters, which are used a global configuration.
50+
The `InfisicalSDKClient` takes the following parameters, which are used as a global configuration for the lifetime of the SDK instance.
5151

5252
- **host** (`str`, _Optional_): The host URL for your Infisical instance. Defaults to `https://app.infisical.com`.
53-
- **token** (`str`, _Optional_): Specify a authentication token to use for all requests. If provided, you will not need to call any of the `auth` methods. Defaults to `None`
54-
- **cache_ttl** (`int`, _Optional_): The SDK has an inbuilt client-side cache mechanism for secrets, which greatly improves speed for the secret methods. By default secrets are cached for 5 minutes. You can disable caching by setting `cache_ttl` to `None`. The value is in seconds, so `300` equates to 5 minutes caching TTL. Default is `300` seconds.
53+
- **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`
54+
- **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.
5555

5656
```python
5757
client = InfisicalSDKClient(

infisical_sdk/client.py

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -7,13 +7,13 @@
77
from infisical_sdk.util import SecretsCache
88

99
class InfisicalSDKClient:
10-
def __init__(self, host: str, token: str = None, cache_ttl: int = 300):
10+
def __init__(self, host: str, token: str = None, cache_ttl: int = 60):
1111
"""
1212
Initialize the Infisical SDK client.
1313
1414
:param str host: The host URL for your Infisical instance. Will default to `https://app.infisical.com` if not specified.
1515
:param str token: The authentication token for the client. If not specified, you can use the `auth` methods to authenticate.
16-
: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.
16+
: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.
1717
"""
1818

1919
self.host = host

infisical_sdk/resources/secrets.py

Lines changed: 44 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -37,7 +37,7 @@ def list_secrets(
3737
params["tagSlugs"] = ",".join(tag_filters)
3838

3939

40-
cache_key = self.cache.compute_cache_key("list_secrets", **params)
40+
cache_key = self.cache.compute_cache_key(CACHE_KEY_LIST_SECRETS, **params)
4141
if self.cache.enabled:
4242
cached_response = self.cache.get(cache_key)
4343

@@ -76,7 +76,14 @@ def get_secret_by_name(
7676
"version": version
7777
}
7878

79-
cache_key = self.cache.compute_cache_key(CACHE_KEY_SINGLE_SECRET, **params)
79+
cache_params = {
80+
"project_id": project_id,
81+
"environment_slug": environment_slug,
82+
"secret_path": secret_path,
83+
"secret_name": secret_name,
84+
}
85+
86+
cache_key = self.cache.compute_cache_key(CACHE_KEY_SINGLE_SECRET, **cache_params)
8087

8188
if self.cache.enabled:
8289
cached_response = self.cache.get(cache_key)
@@ -125,6 +132,18 @@ def create_secret_by_name(
125132
model=SingleSecretResponse
126133
)
127134

135+
136+
if self.cache.enabled:
137+
cache_params = {
138+
"project_id": project_id,
139+
"environment_slug": environment_slug,
140+
"secret_path": secret_path,
141+
"secret_name": secret_name,
142+
}
143+
144+
cache_key = self.cache.compute_cache_key(CACHE_KEY_SINGLE_SECRET, **cache_params)
145+
self.cache.set(cache_key, result.data.secret)
146+
128147
return result.data.secret
129148

130149
def update_secret_by_name(
@@ -160,6 +179,18 @@ def update_secret_by_name(
160179
model=SingleSecretResponse
161180
)
162181

182+
if self.cache.enabled:
183+
cache_params = {
184+
"project_id": project_id,
185+
"environment_slug": environment_slug,
186+
"secret_path": secret_path,
187+
"secret_name": current_secret_name,
188+
}
189+
190+
cache_key = self.cache.compute_cache_key(CACHE_KEY_SINGLE_SECRET, **cache_params)
191+
self.cache.unset(cache_key)
192+
193+
163194
return result.data.secret
164195

165196
def delete_secret_by_name(
@@ -182,4 +213,15 @@ def delete_secret_by_name(
182213
model=SingleSecretResponse
183214
)
184215

216+
if self.cache.enabled:
217+
cache_params = {
218+
"project_id": project_id,
219+
"environment_slug": environment_slug,
220+
"secret_path": secret_path,
221+
"secret_name": secret_name,
222+
}
223+
224+
cache_key = self.cache.compute_cache_key(CACHE_KEY_SINGLE_SECRET, **cache_params)
225+
self.cache.unset(cache_key)
226+
185227
return result.data.secret

setup.cfg

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,3 +1,3 @@
11
[flake8]
22
max-line-length=99
3-
exclude = .venv,test.py
3+
exclude = .venv,test.py,sink

0 commit comments

Comments
 (0)