hermes-access-cli 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.
@@ -0,0 +1,102 @@
1
+ """``validate config|policies|snapshot|manifest <path>``."""
2
+
3
+ import json
4
+ from pathlib import Path
5
+ from typing import Annotated, cast
6
+
7
+ import typer
8
+ from hermes_access_admin.domain.reports import ValidationReport
9
+ from hermes_access_admin.services.api import AdminApi
10
+ from hermes_access_admin.services.validator import (
11
+ validate_manifest,
12
+ validate_policies,
13
+ validate_snapshot,
14
+ )
15
+ from hermes_access_client.domain.hermes_schema import merged_schema
16
+ from hermes_access_client.domain.manifest import Manifest, parse_manifest
17
+ from hermes_access_client.domain.snapshot import PolicyText
18
+ from pydantic import TypeAdapter, ValidationError
19
+
20
+ from hermes_access_cli.adapters.config_files import inspect_config
21
+ from hermes_access_cli.adapters.files import read_document
22
+ from hermes_access_cli.cli.options import Format, FormatOpt
23
+ from hermes_access_cli.cli.render import emit, validation_text
24
+ from hermes_access_cli.cli.state import EXIT_ERROR, cli_context, guarded
25
+ from hermes_access_cli.domain.errors import InputError
26
+
27
+ validate_app = typer.Typer(no_args_is_help=True, help="Validate config, policies, snapshots and manifests.")
28
+
29
+ PathArg = Annotated[Path, typer.Argument(help="File to validate.")]
30
+ OfflineOpt = Annotated[bool, typer.Option("--offline", help="No store, no config needed.")]
31
+
32
+
33
+ def load_policies(path: Path) -> tuple[PolicyText, ...]:
34
+ """A list of ``{id, text}`` (or a mapping with ``policies``/``default_policies``) from a file."""
35
+ raw = read_document(path)
36
+ if isinstance(raw, dict):
37
+ mapping = cast("dict[str, object]", raw)
38
+ raw = mapping.get("policies", mapping.get("default_policies"))
39
+ try:
40
+ return TypeAdapter(tuple[PolicyText, ...]).validate_python(raw)
41
+ except ValidationError as exc:
42
+ raise InputError(
43
+ f"{path} is not a list of policies ({{id, text}}): {exc.errors()[0]['msg']}"
44
+ ) from exc
45
+
46
+
47
+ def manifest_report(path: Path, admin: AdminApi | None) -> ValidationReport:
48
+ """Delegate: validate a manifest offline (``admin`` None) or against the apps in the store."""
49
+ manifest = parse_manifest(read_document(path))
50
+ return validate_manifest(manifest, registered_manifests(admin, manifest))
51
+
52
+
53
+ def registered_manifests(admin: AdminApi | None, manifest: Manifest) -> tuple[Manifest, ...]:
54
+ """Other apps' manifests from the store (none offline); the app being validated is replaced."""
55
+ if admin is None:
56
+ return ()
57
+ others = (a for a in admin.list_apps() if a.name != manifest.app)
58
+ return tuple(parse_manifest(json.loads(a.manifest_json)) for a in others)
59
+
60
+
61
+ def finish(report: ValidationReport, fmt: Format) -> None:
62
+ """Print ``report``; exit 1 when it has issues."""
63
+ emit(report, fmt, validation_text)
64
+ if not report.ok:
65
+ raise typer.Exit(EXIT_ERROR)
66
+
67
+
68
+ @validate_app.command("config")
69
+ @guarded
70
+ def validate_config(
71
+ ctx: typer.Context, path: PathArg, offline: OfflineOpt = False, fmt: FormatOpt = Format.text
72
+ ) -> None:
73
+ """Parse a config file and check its paths, writability and 0600 mode."""
74
+ del offline # config validation never needs the store
75
+ loaded = cli_context(ctx).runtime.load_config(path)
76
+ finish(inspect_config(loaded.path, loaded.settings), fmt)
77
+
78
+
79
+ @validate_app.command("policies")
80
+ @guarded
81
+ def validate_policy_file(path: PathArg, offline: OfflineOpt = False, fmt: FormatOpt = Format.text) -> None:
82
+ """Type-check policies against the bundled Hermes schema."""
83
+ del offline
84
+ finish(validate_policies(load_policies(path), merged_schema()), fmt)
85
+
86
+
87
+ @validate_app.command("snapshot")
88
+ @guarded
89
+ def validate_snapshot_file(path: PathArg, offline: OfflineOpt = False, fmt: FormatOpt = Format.text) -> None:
90
+ """Parse a published snapshot and compile it."""
91
+ del offline
92
+ finish(validate_snapshot(path), fmt)
93
+
94
+
95
+ @validate_app.command("manifest")
96
+ @guarded
97
+ def validate_manifest_file(
98
+ ctx: typer.Context, path: PathArg, offline: OfflineOpt = False, fmt: FormatOpt = Format.text
99
+ ) -> None:
100
+ """Validate an app manifest (``--offline``: bundled schema only; else against the configured store)."""
101
+ admin = None if offline else cli_context(ctx).admin()
102
+ finish(manifest_report(path, admin), fmt)
@@ -0,0 +1 @@
1
+ """Domain of the CLI: its error tree and small value types."""
@@ -0,0 +1,11 @@
1
+ """Exception tree of the CLI package: every CLI-own error is a ``HermesAccessCliError``."""
2
+
3
+ from __future__ import annotations
4
+
5
+
6
+ class HermesAccessCliError(Exception):
7
+ """Base of every error the CLI itself raises."""
8
+
9
+
10
+ class InputError(HermesAccessCliError):
11
+ """The user's input (argument, option value or input file) is unusable: exit code 2."""
@@ -0,0 +1,28 @@
1
+ """The runtime seam: what the commands need from the outside world (tests build one with fakes)."""
2
+
3
+ from collections.abc import Callable
4
+ from dataclasses import dataclass
5
+ from datetime import datetime
6
+ from pathlib import Path
7
+
8
+ from hermes_access_admin.services.api import AdminApi
9
+ from hermes_access_client.domain.settings import AccessSettings
10
+
11
+
12
+ @dataclass(frozen=True, slots=True)
13
+ class LoadedConfig:
14
+ """A config file found and parsed, paths resolved."""
15
+
16
+ path: Path
17
+ settings: AccessSettings
18
+
19
+
20
+ @dataclass(frozen=True, slots=True, kw_only=True)
21
+ class Runtime:
22
+ """What the commands need from the outside world; tests build one with fakes."""
23
+
24
+ admin: Callable[[Path | None], AdminApi]
25
+ load_config: Callable[[Path | None], LoadedConfig]
26
+ config_target: Callable[[Path | None], Path]
27
+ now: Callable[[], datetime]
28
+ user: Callable[[], str]
File without changes
@@ -0,0 +1,26 @@
1
+ Metadata-Version: 2.5
2
+ Name: hermes-access-cli
3
+ Version: 0.1.0
4
+ Summary: The hermes-access command: manage and validate Hermes access control.
5
+ Project-URL: Homepage, https://github.com/ejlevin1/hermes-access
6
+ Project-URL: Issues, https://github.com/ejlevin1/hermes-access/issues
7
+ License-Expression: MIT
8
+ Classifier: License :: OSI Approved :: MIT License
9
+ Classifier: Programming Language :: Python :: 3 :: Only
10
+ Classifier: Typing :: Typed
11
+ Requires-Python: >=3.11
12
+ Requires-Dist: hermes-access-admin
13
+ Requires-Dist: typer>=0.12
14
+ Description-Content-Type: text/markdown
15
+
16
+ # hermes-access-cli
17
+
18
+ The `hermes-access` command: manage and validate Hermes access control.
19
+
20
+ ```sh
21
+ uv tool install hermes-access-cli
22
+ hermes-access config init
23
+ ```
24
+
25
+ Documentation: see the [root README](../../README.md) and the [command reference](../../docs/cli.md).
26
+ Part of hermes-access. License: MIT.
@@ -0,0 +1,26 @@
1
+ hermes_access_cli/__init__.py,sha256=_xtG7I8ZhzjvJeZtFJCdEovyI_FyW7a1gYPYu6opOkU,331
2
+ hermes_access_cli/app.py,sha256=Dl1P_ggJhPkc-tk6Arsd-762vdnqApv1skVOmtVUf7c,1618
3
+ hermes_access_cli/py.typed,sha256=47DEQpj8HBSa-_TImW-5JCeuQeRkm5NMpJWZG3hSuFU,0
4
+ hermes_access_cli/adapters/__init__.py,sha256=ETECiviErOWgkeTvdMJL_yL04TdfLUvcIPbmYdxvF-4,83
5
+ hermes_access_cli/adapters/config_files.py,sha256=45UxGbwlsIlwHBhgkfE7RrqchhDT3ypPkd8BPnQqhAg,2659
6
+ hermes_access_cli/adapters/files.py,sha256=ic7qcpww0a--p3JWjNMuZzLyvqsx24pHmfKpY8dGxnw,783
7
+ hermes_access_cli/adapters/memory.py,sha256=dmCGfC1GyzjZHOb57HAAegCEuitBZ37A8J1XyK7lbUw,5267
8
+ hermes_access_cli/cli/__init__.py,sha256=ut5V1-ze1gYcuTTbajxIkdR7V2e2RnPghh_wFivhOyU,86
9
+ hermes_access_cli/cli/changes.py,sha256=9agBalTJKuuDkTpXTncoYyulXjSTDyaU7RG4LsJYpGY,1574
10
+ hermes_access_cli/cli/config.py,sha256=uTnT-R_hQ2fXzamKT5JTZozHl3LAgH4gAb8RM97JMWs,1872
11
+ hermes_access_cli/cli/entities.py,sha256=fqfvRCrOLG014O70rKMM1S38H8WYDNcVvwWxfElV2Fc,5336
12
+ hermes_access_cli/cli/main.py,sha256=DpDTNcOgXYBT0TC-boIWbZ4KdEwK1LmPNPcJVDuc5XY,1963
13
+ hermes_access_cli/cli/ops.py,sha256=ERnXOxen9KYpjddb4a4d2zsJmTj52HKRQZg0OzS_STE,4806
14
+ hermes_access_cli/cli/options.py,sha256=Bxy4CFL--QoFTOWeXb9JxUHqsMTXKvgnW1tZglcSH94,451
15
+ hermes_access_cli/cli/parse.py,sha256=xBa8bZgmUEWQ-QrTCHjoEXwsU-BrUg2zQJyI55f8Spc,3107
16
+ hermes_access_cli/cli/policies.py,sha256=HR4owVMOTqU1ZLmqAltINuWhSoCi85WCtvK073dzPbw,5550
17
+ hermes_access_cli/cli/render.py,sha256=RNg6kKaB84ACcK2iFl0l247oLNtlWtivuUZhJXbpH0Y,5052
18
+ hermes_access_cli/cli/state.py,sha256=uSFZodfAyosPPYwxHXg88s7QP0rSaCAaz_ovuLWmAiY,1950
19
+ hermes_access_cli/cli/validate.py,sha256=U0ErVPiTd73P3h0M8Ghi7UtvnNQbJ5SK5uj0kFtVmKU,4179
20
+ hermes_access_cli/domain/__init__.py,sha256=n7afzVmevtqAgAka7s-BH7jjuKx5A9fBnqga7VesQEs,63
21
+ hermes_access_cli/domain/errors.py,sha256=0sdryKTsNOW-hBf5OZ8MJvmPW2XT6h-n9NNLUVZ7ocM,356
22
+ hermes_access_cli/domain/runtime.py,sha256=U-_jGORBLeXl_aibYv8Mwx-g-OAoHGeujkJpfTQbJlc,869
23
+ hermes_access_cli-0.1.0.dist-info/METADATA,sha256=251z5cJ8tUb3hDZT1QSmp0s3ZXcrd6jpmdAELVo1lBg,865
24
+ hermes_access_cli-0.1.0.dist-info/WHEEL,sha256=2iZrJkDIkeDh0k9SikKMqFuRP-ua6mb4Ir1AsER4BEw,87
25
+ hermes_access_cli-0.1.0.dist-info/entry_points.txt,sha256=dqRuznL3GlX8ziXMz1xWIoFj3-0Ka06SKelY0eA3HW0,65
26
+ hermes_access_cli-0.1.0.dist-info/RECORD,,
@@ -0,0 +1,4 @@
1
+ Wheel-Version: 1.0
2
+ Generator: hatchling 1.33.0
3
+ Root-Is-Purelib: true
4
+ Tag: py3-none-any
@@ -0,0 +1,2 @@
1
+ [console_scripts]
2
+ hermes-access = hermes_access_cli.cli.main:app