examples/env_shim_demo.py
894 B · 34 lines · python Raw
1 """Install an os.getenv shim so legacy code transparently uses the wallet.
2
3 Run: python examples/env_shim_demo.py
4 """
5
6 from __future__ import annotations
7
8 import os
9 import tempfile
10
11 from quantumshield import AgentIdentity
12
13 from pqc_agent_wallet import Wallet
14 from pqc_agent_wallet.integrations import install_env_shim
15
16
17 def main() -> None:
18 owner = AgentIdentity.create("env-shim-agent")
19 with tempfile.NamedTemporaryFile(suffix=".wallet", delete=False) as tmp:
20 path = tmp.name
21
22 w = Wallet.create_with_passphrase(path, "env-shim-pass", owner)
23 w.put("my_api_key", "sk-env-shim-demo", service="demo")
24
25 # Pretend a library we don't control does this:
26 print("Before shim, os.getenv('my_api_key') =", os.getenv("my_api_key"))
27
28 install_env_shim(w)
29 print("After shim, os.getenv('my_api_key') =", os.getenv("my_api_key"))
30
31
32 if __name__ == "__main__":
33 main()
34