diff --git a/README.md b/README.md index fdc8e67..8422547 100644 --- a/README.md +++ b/README.md @@ -109,6 +109,7 @@ secrets = client.secrets.list_secrets( **Parameters:** - `project_id` (str): The ID of your project. +- `project_slug` (str): The slug of your project. - `environment_slug` (str): The environment in which to list secrets (e.g., "dev"). - `secret_path` (str): The path to the secrets. - `expand_secret_references` (bool): Whether to expand secret references. @@ -117,6 +118,8 @@ secrets = client.secrets.list_secrets( - `include_imports` (bool): Whether to include imported secrets. - `tag_filters` (List[str]): Tags to filter secrets. +**Note:** Exactly one of `project_id` or `project_slug` is required. If both are provided, `project_id` takes precedence. + **Returns:** - `ListSecretsResponse`: The response containing the list of secrets. @@ -133,12 +136,15 @@ new_secret = client.secrets.create_secret_by_name( skip_multiline_encoding=False, secret_reminder_repeat_days=30, # Optional secret_reminder_note="Remember to update this secret" # Optional + secret_metadata=[{"key": "metadata_key", "value": "metadata_value"}], # Optional + tags_ids=["tag_id_1", "tag_id_2"] # Optional ) ``` **Parameters:** - `secret_name` (str): The name of the secret. - `project_id` (str): The ID of your project. +- `project_slug` (str): The slug of your project. - `secret_path` (str): The path to the secret. - `environment_slug` (str): The environment in which to create the secret. - `secret_value` (str): The value of the secret. @@ -146,6 +152,10 @@ new_secret = client.secrets.create_secret_by_name( - `skip_multiline_encoding` (bool, optional): Whether to skip encoding for multiline secrets. - `secret_reminder_repeat_days` (Union[float, int], optional): Number of days after which to repeat secret reminders. - `secret_reminder_note` (str, optional): A note for the secret reminder. +- `secret_metadata` (List[Dict[str, Any]], optional): Metadata associated with the secret. +- `tags_ids` (List[str], optional): IDs of tags to associate with the secret. + +**Note:** Exactly one of `project_id` or `project_slug` is required. If both are provided, `project_id` takes precedence. **Returns:** - `BaseSecret`: The response after creating the secret. @@ -156,6 +166,7 @@ new_secret = client.secrets.create_secret_by_name( updated_secret = client.secrets.update_secret_by_name( current_secret_name="EXISTING_SECRET", project_id="", + project_slug="", secret_path="/", environment_slug="dev", secret_value="new_secret_value", @@ -164,12 +175,15 @@ updated_secret = client.secrets.update_secret_by_name( secret_reminder_repeat_days=30, # Optional secret_reminder_note="Updated reminder note", # Optional new_secret_name="NEW_NAME" # Optional + secret_metadata=[{"key": "metadata_key", "value": "metadata_value"}], # Optional + tags_ids=["tag_id_1", "tag_id_2"] # Optional ) ``` **Parameters:** - `current_secret_name` (str): The current name of the secret. - `project_id` (str): The ID of your project. +- `project_slug` (str): The slug of your project. - `secret_path` (str): The path to the secret. - `environment_slug` (str): The environment in which to update the secret. - `secret_value` (str, optional): The new value of the secret. @@ -178,6 +192,10 @@ updated_secret = client.secrets.update_secret_by_name( - `secret_reminder_repeat_days` (Union[float, int], optional): Updated number of days after which to repeat secret reminders. - `secret_reminder_note` (str, optional): An updated note for the secret reminder. - `new_secret_name` (str, optional): A new name for the secret. +- `secret_metadata` (List[Dict[str, Any]], optional): Metadata associated with the secret. +- `tags_ids` (List[str], optional): IDs of tags to associate with the secret. + +**Note:** Exactly one of `project_id` or `project_slug` is required. If both are provided, `project_id` takes precedence. **Returns:** - `BaseSecret`: The response after updating the secret. @@ -200,6 +218,7 @@ secret = client.secrets.get_secret_by_name( **Parameters:** - `secret_name` (str): The name of the secret. - `project_id` (str): The ID of your project. +- `project_slug` (str): The slug of your project. - `environment_slug` (str): The environment in which to retrieve the secret. - `secret_path` (str): The path to the secret. - `expand_secret_references` (bool): Whether to expand secret references. @@ -207,6 +226,8 @@ secret = client.secrets.get_secret_by_name( - `include_imports` (bool): Whether to include imported secrets. - `version` (str, optional): The version of the secret to retrieve. Fetches the latest by default. +**Note:** Exactly one of `project_id` or `project_slug` is required. If both are provided, `project_id` takes precedence. + **Returns:** - `BaseSecret`: The response containing the secret. @@ -224,9 +245,12 @@ deleted_secret = client.secrets.delete_secret_by_name( **Parameters:** - `secret_name` (str): The name of the secret to delete. - `project_id` (str): The ID of your project. +- `project_slug` (str): The slug of your project. - `environment_slug` (str): The environment in which to delete the secret. - `secret_path` (str): The path to the secret. +**Note:** Exactly one of `project_id` or `project_slug` is required. If both are provided, `project_id` takes precedence. + **Returns:** - `BaseSecret`: The response after deleting the secret. diff --git a/infisical_sdk/resources/secrets.py b/infisical_sdk/resources/secrets.py index d5783bc..c547797 100644 --- a/infisical_sdk/resources/secrets.py +++ b/infisical_sdk/resources/secrets.py @@ -1,4 +1,4 @@ -from typing import List, Union +from typing import List, Union, Optional, Dict, Any from infisical_sdk.infisical_requests import InfisicalRequests from infisical_sdk.api_types import ListSecretsResponse, SingleSecretResponse, BaseSecret @@ -14,14 +14,15 @@ def __init__(self, requests: InfisicalRequests, cache: SecretsCache) -> None: def list_secrets( self, - project_id: str, environment_slug: str, secret_path: str, + project_id: str = None, expand_secret_references: bool = True, view_secret_value: bool = True, recursive: bool = False, include_imports: bool = True, - tag_filters: List[str] = []) -> ListSecretsResponse: + tag_filters: List[str] = [], + project_slug: str = None) -> ListSecretsResponse: params = { "workspaceId": project_id, @@ -31,8 +32,12 @@ def list_secrets( "expandSecretReferences": str(expand_secret_references).lower(), "recursive": str(recursive).lower(), "include_imports": str(include_imports).lower(), + "workspaceSlug": project_slug } + if project_slug is None and project_id is None: + raise ValueError("project_slug or project_id must be provided") + if tag_filters: params["tagSlugs"] = ",".join(tag_filters) @@ -58,9 +63,10 @@ def list_secrets( def get_secret_by_name( self, secret_name: str, - project_id: str, environment_slug: str, secret_path: str, + project_id: str = None, + project_slug: str = None, expand_secret_references: bool = True, include_imports: bool = True, view_secret_value: bool = True, @@ -68,6 +74,7 @@ def get_secret_by_name( params = { "workspaceId": project_id, + "workspaceSlug": project_slug, "viewSecretValue": str(view_secret_value).lower(), "environment": environment_slug, "secretPath": secret_path, @@ -76,6 +83,9 @@ def get_secret_by_name( "version": version } + if project_slug is None and project_id is None: + raise ValueError("project_slug or project_id must be provided") + cache_params = { "project_id": project_id, "environment_slug": environment_slug, @@ -105,27 +115,37 @@ def get_secret_by_name( def create_secret_by_name( self, secret_name: str, - project_id: str, secret_path: str, environment_slug: str, + project_id: str = None, secret_value: str = None, secret_comment: str = None, skip_multiline_encoding: bool = False, secret_reminder_repeat_days: Union[float, int] = None, - secret_reminder_note: str = None) -> BaseSecret: + secret_reminder_note: str = None, + project_slug: str = None, + secret_metadata: Optional[List[Dict[str, Any]]] = None, + tags_ids: Optional[List[str]] = None, + ) -> BaseSecret: requestBody = { "workspaceId": project_id, + "projectSlug": project_slug, "environment": environment_slug, "secretPath": secret_path, "secretValue": secret_value, "secretComment": secret_comment, - "tagIds": None, + "tagIds": tags_ids, "skipMultilineEncoding": skip_multiline_encoding, "type": "shared", "secretReminderRepeatDays": secret_reminder_repeat_days, - "secretReminderNote": secret_reminder_note + "secretReminderNote": secret_reminder_note, + "secretMetadata": secret_metadata, } + + if project_slug is None and project_id is None: + raise ValueError("project_slug or project_id must be provided") + result = self.requests.post( path=f"/api/v3/secrets/raw/{secret_name}", json=requestBody, @@ -152,30 +172,39 @@ def create_secret_by_name( def update_secret_by_name( self, current_secret_name: str, - project_id: str, secret_path: str, environment_slug: str, + project_id: str = None, secret_value: str = None, secret_comment: str = None, skip_multiline_encoding: bool = False, secret_reminder_repeat_days: Union[float, int] = None, secret_reminder_note: str = None, - new_secret_name: str = None) -> BaseSecret: + new_secret_name: str = None, + project_slug: str = None, + secret_metadata: Optional[List[Dict[str, Any]]] = None, + tags_ids: Optional[List[str]] = None, + ) -> BaseSecret: requestBody = { "workspaceId": project_id, + "projectSlug": project_slug, "environment": environment_slug, "secretPath": secret_path, "secretValue": secret_value, "secretComment": secret_comment, "newSecretName": new_secret_name, - "tagIds": None, + "tagIds": tags_ids, "skipMultilineEncoding": skip_multiline_encoding, "type": "shared", "secretReminderRepeatDays": secret_reminder_repeat_days, - "secretReminderNote": secret_reminder_note + "secretReminderNote": secret_reminder_note, + "secretMetadata": secret_metadata, } + if project_slug is None and project_id is None: + raise ValueError("project_slug or project_id must be provided") + result = self.requests.patch( path=f"/api/v3/secrets/raw/{current_secret_name}", json=requestBody, @@ -201,12 +230,17 @@ def update_secret_by_name( def delete_secret_by_name( self, secret_name: str, - project_id: str, secret_path: str, - environment_slug: str) -> BaseSecret: + environment_slug: str, + project_id: str = None, + project_slug: str = None) -> BaseSecret: + + if project_slug is None and project_id is None: + raise ValueError("project_slug or project_id must be provided") requestBody = { "workspaceId": project_id, + "projectSlug": project_slug, "environment": environment_slug, "secretPath": secret_path, "type": "shared",