examples/store_credentials.py
1.3 KB · 49 lines · python Raw
1 """Store three API credentials for three different app bundles and list them."""
2
3 from __future__ import annotations
4
5 from pqc_enclave_sdk import (
6 ArtifactKind,
7 EnclaveVault,
8 InMemoryEnclaveBackend,
9 )
10
11
12 def main() -> None:
13 backend = InMemoryEnclaveBackend(
14 device_id="pixel-8-bob-demo",
15 device_model="pixel-8",
16 )
17 vault = EnclaveVault(backend=backend)
18 vault.unlock()
19
20 credentials = [
21 ("openai_api_key", b"sk-openai-test", "com.example.chatapp"),
22 ("anthropic_api_key", b"sk-ant-test", "com.example.chatapp"),
23 ("stripe_secret", b"sk_live_stripe", "com.example.payments"),
24 ]
25 for name, value, bundle in credentials:
26 vault.put_artifact(
27 name=name,
28 kind=ArtifactKind.CREDENTIAL,
29 content=value,
30 app_bundle_id=bundle,
31 )
32 print(f"[put] stored {name!r} for bundle {bundle!r}")
33
34 print()
35 print("[list] artifacts in vault:")
36 for meta in vault.list_artifacts():
37 print(
38 f" - name={meta.name:<22} bundle={meta.app_bundle_id:<24} "
39 f"size={meta.size_bytes:>3}B kind={meta.kind.value}"
40 )
41
42 print()
43 retrieved = vault.get_artifact("anthropic_api_key").content
44 print(f"[get] anthropic_api_key -> {retrieved!r}")
45
46
47 if __name__ == "__main__":
48 main()
49