mirror of
https://github.com/hanzokms/python-sdk.git
synced 2026-10-30 20:30:11 +00:00
- Rename package: infisical_sdk -> hanzo_kms (pip: hanzokms) - Rename classes: InfisicalSDKClient -> KMSClient, InfisicalRequests -> KMSRequests, InfisicalError -> KMSError - Default API host: https://kms.hanzo.ai - Update all imports, docstrings, and user-facing strings - Copyright: Hanzo AI Inc. - Backward-compatible aliases: InfisicalSDKClient, InfisicalError - Env var: INFISICAL_AWS_IAM_AUTH_IDENTITY_ID -> HANZO_KMS_AWS_IAM_AUTH_IDENTITY_ID - Remove obsolete OpenAPI generator files (.travis.yml, .gitlab-ci.yml, etc.)
75 lines
2.3 KiB
Python
75 lines
2.3 KiB
Python
from typing import Optional
|
|
from datetime import datetime, timezone
|
|
|
|
from hanzo_kms.kms_requests import KMSRequests
|
|
from hanzo_kms.api_types import ListFoldersResponse, SingleFolderResponse, SingleFolderResponseItem, CreateFolderResponse, CreateFolderResponseItem
|
|
|
|
|
|
class V2Folders:
|
|
def __init__(self, requests: KMSRequests) -> None:
|
|
self.requests = requests
|
|
|
|
def create_folder(
|
|
self,
|
|
name: str,
|
|
environment_slug: str,
|
|
project_id: str,
|
|
path: str = "/",
|
|
description: Optional[str] = None) -> CreateFolderResponseItem:
|
|
|
|
request_body = {
|
|
"projectId": project_id,
|
|
"environment": environment_slug,
|
|
"name": name,
|
|
"path": path,
|
|
"description": description,
|
|
}
|
|
|
|
result = self.requests.post(
|
|
path="/api/v2/folders",
|
|
json=request_body,
|
|
model=CreateFolderResponse
|
|
)
|
|
|
|
return result.data.folder
|
|
|
|
def list_folders(
|
|
self,
|
|
project_id: str,
|
|
environment_slug: str,
|
|
path: str,
|
|
last_secret_modified: Optional[datetime] = None,
|
|
recursive: bool = False) -> ListFoldersResponse:
|
|
|
|
params = {
|
|
"projectId": project_id,
|
|
"environment": environment_slug,
|
|
"path": path,
|
|
"recursive": recursive,
|
|
}
|
|
|
|
if last_secret_modified is not None:
|
|
# Convert to UTC and format as RFC 3339 with 'Z' suffix
|
|
# The API expects UTC times in 'Z' format (e.g., 2023-11-07T05:31:56Z)
|
|
utc_datetime = last_secret_modified.astimezone(timezone.utc) if last_secret_modified.tzinfo else last_secret_modified.replace(tzinfo=timezone.utc)
|
|
params["lastSecretModified"] = utc_datetime.strftime('%Y-%m-%dT%H:%M:%SZ')
|
|
|
|
result = self.requests.get(
|
|
path="/api/v2/folders",
|
|
params=params,
|
|
model=ListFoldersResponse
|
|
)
|
|
|
|
return result.data
|
|
|
|
def get_folder_by_id(
|
|
self,
|
|
id: str) -> SingleFolderResponseItem:
|
|
|
|
result = self.requests.get(
|
|
path=f"/api/v2/folders/{id}",
|
|
model=SingleFolderResponse
|
|
)
|
|
|
|
return result.data.folder
|