Skip to content

Commit 94788ee

Browse files
Merge pull request #39 from Infisical/feat/secretMissingParams
Add missing params to secret endpoints
2 parents eaf1f82 + 2636ba7 commit 94788ee

File tree

2 files changed

+72
-14
lines changed

2 files changed

+72
-14
lines changed

README.md

Lines changed: 24 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -109,6 +109,7 @@ secrets = client.secrets.list_secrets(
109109

110110
**Parameters:**
111111
- `project_id` (str): The ID of your project.
112+
- `project_slug` (str): The slug of your project.
112113
- `environment_slug` (str): The environment in which to list secrets (e.g., "dev").
113114
- `secret_path` (str): The path to the secrets.
114115
- `expand_secret_references` (bool): Whether to expand secret references.
@@ -117,6 +118,8 @@ secrets = client.secrets.list_secrets(
117118
- `include_imports` (bool): Whether to include imported secrets.
118119
- `tag_filters` (List[str]): Tags to filter secrets.
119120

121+
**Note:** Exactly one of `project_id` or `project_slug` is required. If both are provided, `project_id` takes precedence.
122+
120123
**Returns:**
121124
- `ListSecretsResponse`: The response containing the list of secrets.
122125

@@ -133,19 +136,26 @@ new_secret = client.secrets.create_secret_by_name(
133136
skip_multiline_encoding=False,
134137
secret_reminder_repeat_days=30, # Optional
135138
secret_reminder_note="Remember to update this secret" # Optional
139+
secret_metadata=[{"key": "metadata_key", "value": "metadata_value"}], # Optional
140+
tags_ids=["tag_id_1", "tag_id_2"] # Optional
136141
)
137142
```
138143

139144
**Parameters:**
140145
- `secret_name` (str): The name of the secret.
141146
- `project_id` (str): The ID of your project.
147+
- `project_slug` (str): The slug of your project.
142148
- `secret_path` (str): The path to the secret.
143149
- `environment_slug` (str): The environment in which to create the secret.
144150
- `secret_value` (str): The value of the secret.
145151
- `secret_comment` (str, optional): A comment associated with the secret.
146152
- `skip_multiline_encoding` (bool, optional): Whether to skip encoding for multiline secrets.
147153
- `secret_reminder_repeat_days` (Union[float, int], optional): Number of days after which to repeat secret reminders.
148154
- `secret_reminder_note` (str, optional): A note for the secret reminder.
155+
- `secret_metadata` (List[Dict[str, Any]], optional): Metadata associated with the secret.
156+
- `tags_ids` (List[str], optional): IDs of tags to associate with the secret.
157+
158+
**Note:** Exactly one of `project_id` or `project_slug` is required. If both are provided, `project_id` takes precedence.
149159

150160
**Returns:**
151161
- `BaseSecret`: The response after creating the secret.
@@ -156,6 +166,7 @@ new_secret = client.secrets.create_secret_by_name(
156166
updated_secret = client.secrets.update_secret_by_name(
157167
current_secret_name="EXISTING_SECRET",
158168
project_id="<project-id>",
169+
project_slug="<project-slug>",
159170
secret_path="/",
160171
environment_slug="dev",
161172
secret_value="new_secret_value",
@@ -164,12 +175,15 @@ updated_secret = client.secrets.update_secret_by_name(
164175
secret_reminder_repeat_days=30, # Optional
165176
secret_reminder_note="Updated reminder note", # Optional
166177
new_secret_name="NEW_NAME" # Optional
178+
secret_metadata=[{"key": "metadata_key", "value": "metadata_value"}], # Optional
179+
tags_ids=["tag_id_1", "tag_id_2"] # Optional
167180
)
168181
```
169182

170183
**Parameters:**
171184
- `current_secret_name` (str): The current name of the secret.
172185
- `project_id` (str): The ID of your project.
186+
- `project_slug` (str): The slug of your project.
173187
- `secret_path` (str): The path to the secret.
174188
- `environment_slug` (str): The environment in which to update the secret.
175189
- `secret_value` (str, optional): The new value of the secret.
@@ -178,6 +192,10 @@ updated_secret = client.secrets.update_secret_by_name(
178192
- `secret_reminder_repeat_days` (Union[float, int], optional): Updated number of days after which to repeat secret reminders.
179193
- `secret_reminder_note` (str, optional): An updated note for the secret reminder.
180194
- `new_secret_name` (str, optional): A new name for the secret.
195+
- `secret_metadata` (List[Dict[str, Any]], optional): Metadata associated with the secret.
196+
- `tags_ids` (List[str], optional): IDs of tags to associate with the secret.
197+
198+
**Note:** Exactly one of `project_id` or `project_slug` is required. If both are provided, `project_id` takes precedence.
181199

182200
**Returns:**
183201
- `BaseSecret`: The response after updating the secret.
@@ -200,13 +218,16 @@ secret = client.secrets.get_secret_by_name(
200218
**Parameters:**
201219
- `secret_name` (str): The name of the secret.
202220
- `project_id` (str): The ID of your project.
221+
- `project_slug` (str): The slug of your project.
203222
- `environment_slug` (str): The environment in which to retrieve the secret.
204223
- `secret_path` (str): The path to the secret.
205224
- `expand_secret_references` (bool): Whether to expand secret references.
206225
- `view_secret_value` (bool): Whether or not to include the secret value in the response. If set to false, the `secretValue` will be masked with `<hidden-by-infisical>`. Defaults to true.
207226
- `include_imports` (bool): Whether to include imported secrets.
208227
- `version` (str, optional): The version of the secret to retrieve. Fetches the latest by default.
209228

229+
**Note:** Exactly one of `project_id` or `project_slug` is required. If both are provided, `project_id` takes precedence.
230+
210231
**Returns:**
211232
- `BaseSecret`: The response containing the secret.
212233

@@ -224,9 +245,12 @@ deleted_secret = client.secrets.delete_secret_by_name(
224245
**Parameters:**
225246
- `secret_name` (str): The name of the secret to delete.
226247
- `project_id` (str): The ID of your project.
248+
- `project_slug` (str): The slug of your project.
227249
- `environment_slug` (str): The environment in which to delete the secret.
228250
- `secret_path` (str): The path to the secret.
229251

252+
**Note:** Exactly one of `project_id` or `project_slug` is required. If both are provided, `project_id` takes precedence.
253+
230254
**Returns:**
231255
- `BaseSecret`: The response after deleting the secret.
232256

infisical_sdk/resources/secrets.py

Lines changed: 48 additions & 14 deletions
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,4 @@
1-
from typing import List, Union
1+
from typing import List, Union, Optional, Dict, Any
22

33
from infisical_sdk.infisical_requests import InfisicalRequests
44
from infisical_sdk.api_types import ListSecretsResponse, SingleSecretResponse, BaseSecret
@@ -14,14 +14,15 @@ def __init__(self, requests: InfisicalRequests, cache: SecretsCache) -> None:
1414

1515
def list_secrets(
1616
self,
17-
project_id: str,
1817
environment_slug: str,
1918
secret_path: str,
19+
project_id: str = None,
2020
expand_secret_references: bool = True,
2121
view_secret_value: bool = True,
2222
recursive: bool = False,
2323
include_imports: bool = True,
24-
tag_filters: List[str] = []) -> ListSecretsResponse:
24+
tag_filters: List[str] = [],
25+
project_slug: str = None) -> ListSecretsResponse:
2526

2627
params = {
2728
"workspaceId": project_id,
@@ -31,8 +32,12 @@ def list_secrets(
3132
"expandSecretReferences": str(expand_secret_references).lower(),
3233
"recursive": str(recursive).lower(),
3334
"include_imports": str(include_imports).lower(),
35+
"workspaceSlug": project_slug
3436
}
3537

38+
if project_slug is None and project_id is None:
39+
raise ValueError("project_slug or project_id must be provided")
40+
3641
if tag_filters:
3742
params["tagSlugs"] = ",".join(tag_filters)
3843

@@ -58,16 +63,18 @@ def list_secrets(
5863
def get_secret_by_name(
5964
self,
6065
secret_name: str,
61-
project_id: str,
6266
environment_slug: str,
6367
secret_path: str,
68+
project_id: str = None,
69+
project_slug: str = None,
6470
expand_secret_references: bool = True,
6571
include_imports: bool = True,
6672
view_secret_value: bool = True,
6773
version: str = None) -> BaseSecret:
6874

6975
params = {
7076
"workspaceId": project_id,
77+
"workspaceSlug": project_slug,
7178
"viewSecretValue": str(view_secret_value).lower(),
7279
"environment": environment_slug,
7380
"secretPath": secret_path,
@@ -76,6 +83,9 @@ def get_secret_by_name(
7683
"version": version
7784
}
7885

86+
if project_slug is None and project_id is None:
87+
raise ValueError("project_slug or project_id must be provided")
88+
7989
cache_params = {
8090
"project_id": project_id,
8191
"environment_slug": environment_slug,
@@ -105,27 +115,37 @@ def get_secret_by_name(
105115
def create_secret_by_name(
106116
self,
107117
secret_name: str,
108-
project_id: str,
109118
secret_path: str,
110119
environment_slug: str,
120+
project_id: str = None,
111121
secret_value: str = None,
112122
secret_comment: str = None,
113123
skip_multiline_encoding: bool = False,
114124
secret_reminder_repeat_days: Union[float, int] = None,
115-
secret_reminder_note: str = None) -> BaseSecret:
125+
secret_reminder_note: str = None,
126+
project_slug: str = None,
127+
secret_metadata: Optional[List[Dict[str, Any]]] = None,
128+
tags_ids: Optional[List[str]] = None,
129+
) -> BaseSecret:
116130

117131
requestBody = {
118132
"workspaceId": project_id,
133+
"projectSlug": project_slug,
119134
"environment": environment_slug,
120135
"secretPath": secret_path,
121136
"secretValue": secret_value,
122137
"secretComment": secret_comment,
123-
"tagIds": None,
138+
"tagIds": tags_ids,
124139
"skipMultilineEncoding": skip_multiline_encoding,
125140
"type": "shared",
126141
"secretReminderRepeatDays": secret_reminder_repeat_days,
127-
"secretReminderNote": secret_reminder_note
142+
"secretReminderNote": secret_reminder_note,
143+
"secretMetadata": secret_metadata,
128144
}
145+
146+
if project_slug is None and project_id is None:
147+
raise ValueError("project_slug or project_id must be provided")
148+
129149
result = self.requests.post(
130150
path=f"/api/v3/secrets/raw/{secret_name}",
131151
json=requestBody,
@@ -152,30 +172,39 @@ def create_secret_by_name(
152172
def update_secret_by_name(
153173
self,
154174
current_secret_name: str,
155-
project_id: str,
156175
secret_path: str,
157176
environment_slug: str,
177+
project_id: str = None,
158178
secret_value: str = None,
159179
secret_comment: str = None,
160180
skip_multiline_encoding: bool = False,
161181
secret_reminder_repeat_days: Union[float, int] = None,
162182
secret_reminder_note: str = None,
163-
new_secret_name: str = None) -> BaseSecret:
183+
new_secret_name: str = None,
184+
project_slug: str = None,
185+
secret_metadata: Optional[List[Dict[str, Any]]] = None,
186+
tags_ids: Optional[List[str]] = None,
187+
) -> BaseSecret:
164188

165189
requestBody = {
166190
"workspaceId": project_id,
191+
"projectSlug": project_slug,
167192
"environment": environment_slug,
168193
"secretPath": secret_path,
169194
"secretValue": secret_value,
170195
"secretComment": secret_comment,
171196
"newSecretName": new_secret_name,
172-
"tagIds": None,
197+
"tagIds": tags_ids,
173198
"skipMultilineEncoding": skip_multiline_encoding,
174199
"type": "shared",
175200
"secretReminderRepeatDays": secret_reminder_repeat_days,
176-
"secretReminderNote": secret_reminder_note
201+
"secretReminderNote": secret_reminder_note,
202+
"secretMetadata": secret_metadata,
177203
}
178204

205+
if project_slug is None and project_id is None:
206+
raise ValueError("project_slug or project_id must be provided")
207+
179208
result = self.requests.patch(
180209
path=f"/api/v3/secrets/raw/{current_secret_name}",
181210
json=requestBody,
@@ -201,12 +230,17 @@ def update_secret_by_name(
201230
def delete_secret_by_name(
202231
self,
203232
secret_name: str,
204-
project_id: str,
205233
secret_path: str,
206-
environment_slug: str) -> BaseSecret:
234+
environment_slug: str,
235+
project_id: str = None,
236+
project_slug: str = None) -> BaseSecret:
237+
238+
if project_slug is None and project_id is None:
239+
raise ValueError("project_slug or project_id must be provided")
207240

208241
requestBody = {
209242
"workspaceId": project_id,
243+
"projectSlug": project_slug,
210244
"environment": environment_slug,
211245
"secretPath": secret_path,
212246
"type": "shared",

0 commit comments

Comments
 (0)