implement cli/infra update cicd

This commit is contained in:
Deeman
2025-10-12 21:00:41 +02:00
parent 790e802edd
commit 55bb84f0fa
18 changed files with 2052 additions and 60 deletions

44
src/materia/secrets.py Normal file
View File

@@ -0,0 +1,44 @@
"""Secrets management via Pulumi ESC."""
import json
import subprocess
from functools import lru_cache
@lru_cache(maxsize=1)
def _load_environment() -> dict[str, str]:
"""Load secrets from Pulumi ESC environment."""
try:
result = subprocess.run(
["esc", "env", "open", "prod", "--format", "json"],
capture_output=True,
text=True,
check=True,
)
data = json.loads(result.stdout)
return data.get("values", {})
except subprocess.CalledProcessError as e:
raise RuntimeError(f"Failed to load ESC environment: {e.stderr}")
except FileNotFoundError:
raise RuntimeError("ESC CLI not found. Install with: curl -fsSL https://get.pulumi.com/esc/install.sh | sh")
def get_secret(key: str) -> str | None:
"""Get a secret value by key."""
env = _load_environment()
return env.get(key)
def list_secrets() -> list[str]:
"""List all available secret keys."""
env = _load_environment()
return list(env.keys())
def test_connection() -> bool:
"""Test ESC connection."""
try:
_load_environment()
return True
except Exception:
return False