Skip to content
Merged
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
24 changes: 24 additions & 0 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -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.
Expand All @@ -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.

Expand All @@ -133,19 +136,26 @@ 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.
- `secret_comment` (str, optional): A comment associated with the secret.
- `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.
Expand All @@ -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-id>",
project_slug="<project-slug>",
secret_path="/",
environment_slug="dev",
secret_value="new_secret_value",
Expand All @@ -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.
Expand All @@ -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.
Expand All @@ -200,13 +218,16 @@ 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.
- `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.
- `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.

Expand All @@ -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.

Expand Down
62 changes: 48 additions & 14 deletions infisical_sdk/resources/secrets.py
Original file line number Diff line number Diff line change
@@ -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
Expand All @@ -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,
Expand All @@ -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)

Expand All @@ -58,16 +63,18 @@ 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,
version: str = None) -> BaseSecret:

params = {
"workspaceId": project_id,
"workspaceSlug": project_slug,
"viewSecretValue": str(view_secret_value).lower(),
"environment": environment_slug,
"secretPath": secret_path,
Expand All @@ -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,
Expand Down Expand Up @@ -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,
Expand All @@ -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,
Expand All @@ -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",
Expand Down