Files
python-sdk/sink/cache_deletion_test.py
zeekay 23138100de refactor: rebrand Infisical Python SDK -> Hanzo KMS Python SDK
- 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.)
2026-02-24 02:00:18 -08:00

79 lines
2.4 KiB
Python

from hanzo_kms import KMSClient
import time
import os
import random
import string
def loadEnvVarsFromFileIntoEnv():
d = dict()
with open("./.env", "r") as fp:
for line in fp:
line = line.strip()
if line and not line.startswith("#"):
line = line.split("=", 1)
d[line[0]] = line[1]
for key, value in d.items():
os.environ[key] = value
loadEnvVarsFromFileIntoEnv()
SECRETS_PROJECT_ID = os.getenv("SECRETS_PROJECT_ID")
SECRETS_ENVIRONMENT_SLUG = os.getenv("SECRETS_ENVIRONMENT_SLUG")
MACHINE_IDENTITY_UNIVERSAL_AUTH_CLIENT_ID = os.getenv("MACHINE_IDENTITY_UNIVERSAL_AUTH_CLIENT_ID")
MACHINE_IDENTITY_UNIVERSAL_AUTH_CLIENT_SECRET = os.getenv("MACHINE_IDENTITY_UNIVERSAL_AUTH_CLIENT_SECRET")
SITE_URL = os.getenv("SITE_URL")
cache_enabled_client = KMSClient(host=SITE_URL, cache_ttl=10)
cache_enabled_client.auth.universal_auth.login(MACHINE_IDENTITY_UNIVERSAL_AUTH_CLIENT_ID, MACHINE_IDENTITY_UNIVERSAL_AUTH_CLIENT_SECRET)
time_start_cache_disabled = time.time()
def randomStringNoSpecialChars(length: int = 10) -> str:
return ''.join(random.choices(string.ascii_letters + string.digits, k=length))
created_sec = cache_enabled_client.secrets.create_secret_by_name(
secret_name=f"TEST_{randomStringNoSpecialChars()}",
project_id=SECRETS_PROJECT_ID,
environment_slug=SECRETS_ENVIRONMENT_SLUG,
secret_path="/",
secret_value=f"secret_value_{randomStringNoSpecialChars()}",
)
single_secret_cached = cache_enabled_client.secrets.get_secret_by_name(
secret_name=created_sec.secretKey,
project_id=SECRETS_PROJECT_ID,
environment_slug=SECRETS_ENVIRONMENT_SLUG,
secret_path="/",
expand_secret_references=True,
include_imports=True)
print(single_secret_cached)
deleted_secret = cache_enabled_client.secrets.delete_secret_by_name(
secret_name=created_sec.secretKey,
project_id=SECRETS_PROJECT_ID,
environment_slug=SECRETS_ENVIRONMENT_SLUG,
secret_path="/",
)
print(deleted_secret)
# Should error
try:
single_secret_cached = cache_enabled_client.secrets.get_secret_by_name(
secret_name=created_sec.secretKey,
project_id=SECRETS_PROJECT_ID,
environment_slug=SECRETS_ENVIRONMENT_SLUG,
secret_path="/",
expand_secret_references=True,
include_imports=True)
except Exception as e:
print(e)
print("Good, we errored as expected!")