zyppcli 0.1.0__py3-none-any.whl

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
zyppcli/__init__.py ADDED
@@ -0,0 +1,3 @@
1
+ from importlib.metadata import version
2
+
3
+ __version__ = version("zyppcli")
zyppcli/__main__.py ADDED
@@ -0,0 +1,29 @@
1
+ import argparse
2
+ import logging
3
+ import sys
4
+
5
+ from zyppcli import __version__
6
+ from zyppcli.commands import keyvault
7
+
8
+
9
+ def main() -> None:
10
+ """Entry point for the Zypp CLI."""
11
+ logging.basicConfig(level=logging.INFO, format="%(levelname)s: %(message)s", stream=sys.stderr)
12
+
13
+ parser = argparse.ArgumentParser(prog="zypp", description="Zypp CLI")
14
+ parser.add_argument("--version", action="version", version=f"%(prog)s {__version__}")
15
+
16
+ subparsers = parser.add_subparsers(dest="command")
17
+ keyvault.register(subparsers)
18
+
19
+ args = parser.parse_args()
20
+
21
+ if args.command == "keyvault":
22
+ keyvault.run(args)
23
+ else:
24
+ parser.print_help()
25
+ sys.exit(1)
26
+
27
+
28
+ if __name__ == "__main__":
29
+ main()
File without changes
@@ -0,0 +1,54 @@
1
+ import argparse
2
+ import logging
3
+ import sys
4
+
5
+ from azure.identity import DefaultAzureCredential
6
+ from azure.keyvault.secrets import SecretClient
7
+
8
+ logger = logging.getLogger(__name__)
9
+
10
+
11
+ def register(subparsers: argparse._SubParsersAction) -> None:
12
+ """Register the 'keyvault' command and its subcommands."""
13
+ keyvault_parser = subparsers.add_parser("keyvault", help="Azure Key Vault operations")
14
+ keyvault_subparsers = keyvault_parser.add_subparsers(dest="keyvault_command")
15
+
16
+ load_parser = keyvault_subparsers.add_parser("load", help="Load secrets as shell export statements")
17
+ load_parser.add_argument("--vault", required=True, help="Name of the Azure Key Vault")
18
+
19
+
20
+ def run(args: argparse.Namespace) -> None:
21
+ """Execute the specified 'keyvault' command."""
22
+ if args.keyvault_command == "load":
23
+ _load(args.vault)
24
+ else:
25
+ logger.error("Usage: zypp keyvault load --vault <name>")
26
+ sys.exit(1)
27
+
28
+
29
+ def _get_secrets(vault_name: str) -> dict[str, str]:
30
+ """Fetch secrets from the specified Azure Key Vault."""
31
+ credential = DefaultAzureCredential(exclude_environment_credential=True)
32
+ client = SecretClient(vault_url=f"https://{vault_name}.vault.azure.net", credential=credential)
33
+
34
+ secrets = {}
35
+ for prop in client.list_properties_of_secrets():
36
+ if prop.enabled:
37
+ secrets[prop.name] = client.get_secret(prop.name).value
38
+
39
+ return secrets
40
+
41
+
42
+ def _load(vault_name: str) -> None:
43
+ """Load secrets from the specified Azure Key Vault and print them as shell export statements."""
44
+ try:
45
+ secrets = _get_secrets(vault_name)
46
+ except Exception as e:
47
+ logger.exception("Failed to fetch secrets from '%s': %s", vault_name, e)
48
+ logger.info("Hint: Make sure you are authenticated via `az login`.")
49
+ sys.exit(1)
50
+
51
+ for name, value in secrets.items():
52
+ env_name = name.replace("-", "_").upper()
53
+ escaped_value = value.replace("'", "'\\''")
54
+ print(f"export {env_name}='{escaped_value}'")
@@ -0,0 +1,10 @@
1
+ Metadata-Version: 2.4
2
+ Name: zyppcli
3
+ Version: 0.1.0
4
+ Summary: Internal CLI for Zypp
5
+ Requires-Python: >=3.12
6
+ Requires-Dist: azure-identity>=1.17.0
7
+ Requires-Dist: azure-keyvault-secrets>=4.8.0
8
+ Description-Content-Type: text/markdown
9
+
10
+ # Zypp CLI
@@ -0,0 +1,8 @@
1
+ zyppcli/__init__.py,sha256=N5GRT5BqnH_hmuqXRV7gDFdJiM2K1xfgy6LJxMGGDts,73
2
+ zyppcli/__main__.py,sha256=BBa5hxJmftG-X5C79XtxR-oW_L8Xr7T_Zp-CrKFujIc,723
3
+ zyppcli/commands/__init__.py,sha256=47DEQpj8HBSa-_TImW-5JCeuQeRkm5NMpJWZG3hSuFU,0
4
+ zyppcli/commands/keyvault.py,sha256=75aG0_4hBau1njG24hY4kzXOouclbcc7DRyX5OnR1Hs,2003
5
+ zyppcli-0.1.0.dist-info/METADATA,sha256=Kzp9x0QQ-YV3c8VyimAWpGSCYjLnWSBFiwwFw0oD834,241
6
+ zyppcli-0.1.0.dist-info/WHEEL,sha256=QccIxa26bgl1E6uMy58deGWi-0aeIkkangHcxk2kWfw,87
7
+ zyppcli-0.1.0.dist-info/entry_points.txt,sha256=P3Q8EofVVgww3iOzdbMugCH5jP4KOd6XJwGtmdHhH0k,47
8
+ zyppcli-0.1.0.dist-info/RECORD,,
@@ -0,0 +1,4 @@
1
+ Wheel-Version: 1.0
2
+ Generator: hatchling 1.29.0
3
+ Root-Is-Purelib: true
4
+ Tag: py3-none-any
@@ -0,0 +1,2 @@
1
+ [console_scripts]
2
+ zypp = zyppcli.__main__:main