-
Notifications
You must be signed in to change notification settings - Fork 2
feat(xtest): Lets otdf-sdk-mgr manage platform too #451
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Open
dmihalcik-virtru
wants to merge
6
commits into
main
Choose a base branch
from
DSPX-3302-02-platform-installer
base: main
Could not load branches
Branch not found: {{ refName }}
Loading
Could not load tags
Nothing to show
Loading
Are you sure you want to change the base?
Some commits from the old base branch may be removed from the timeline,
and old review comments may become outdated.
Open
Changes from all commits
Commits
Show all changes
6 commits
Select commit
Hold shift + click to select a range
7c04ca1
feat(otdf-sdk-mgr): manage platform service + install scenario (DSPX-…
dmihalcik-virtru 739801e
fix(otdf-sdk-mgr): repair install scenario + harden silent failures
dmihalcik-virtru 2cf8a09
style(otdf-sdk-mgr): ruff format
dmihalcik-virtru 4f86895
refactor(otdf-sdk-mgr): address PR review feedback on platform installer
dmihalcik-virtru e8439e5
docs+chore: require uv run ruff/pyright pre-commit; fix cli_scenario …
dmihalcik-virtru 13b5c96
docs(agents): expand and reorganize AGENTS.md across packages
dmihalcik-virtru File filter
Filter by extension
Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
There are no files selected for viewing
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,60 @@ | ||
| # otdf-sdk-mgr - Agent Guide | ||
|
|
||
| Python CLI that installs SDK CLIs (`go`, `java`, `js`) and the OpenTDF | ||
| platform service from released artifacts or source. Outputs land in | ||
| `xtest/sdk/{go,java,js}/dist/<version>/` and `xtest/platform/dist/<version>/`. | ||
|
|
||
| Full command reference: [README.md](README.md). | ||
|
|
||
| ## Subcommand Layout | ||
|
|
||
| | File | Subcommand | Responsibility | | ||
| |------|------------|----------------| | ||
| | `cli_install.py` | `install {stable,lts,tip,release,scripts,artifact,scenario}` | All `install` subcommands; delegates per-SDK work to `installers.py` and platform work to `platform_installer.py`. | | ||
| | `cli_scenario.py` | `install scenario <path>` | Reads `scenarios.yaml` / `instance.yaml`, installs every referenced artifact, writes `<name>.installed.json`. | | ||
| | `cli_versions.py` | `versions {list,latest}` | Lists released versions across registries. | | ||
| | `installers.py` | (lib) | Per-SDK install logic for go/java/js. | | ||
| | `platform_installer.py` | (lib) | Builds the platform `service` binary via git worktrees on a bare clone. | | ||
| | `schema.py` | (lib) | Pydantic models for `Scenario` / `Instance` + `load_yaml_mapping`. | | ||
|
|
||
| ## Platform Install via Git Worktrees | ||
|
|
||
| `platform_installer.py` keeps a **bare clone** at `xtest/platform/src/platform.git` | ||
| and `git worktree add`s each requested ref into a sibling directory. A few | ||
| gotchas worth knowing before editing this module: | ||
|
|
||
| - **Worktrees from a bare clone have no `origin` remote.** `git pull` inside | ||
| the worktree will fail. Update by fetching into the bare repo first | ||
| (`_ensure_bare_repo()` already does this), then `git -C <worktree> reset | ||
| --hard <branch>` to move the worktree HEAD to the refreshed ref. | ||
| - **Platform tags are namespaced** as `service/vX.Y.Z`. `_resolve_platform_ref` | ||
| prefixes the `service/` infix on plain versions; raw SHAs, refs with a | ||
| `/`, and `main`/`HEAD` pass through unchanged. | ||
| - Subprocess output is **not captured** — long-running `go build` / `git | ||
| clone` streams to the terminal so users can see progress. On failure the | ||
| error message just reports the command and exit code. | ||
|
|
||
| ## Before Committing | ||
|
|
||
| Run from this directory: | ||
|
|
||
| ```bash | ||
| uv run ruff check . # lint — must pass | ||
| uv run ruff format . # auto-format — re-stage rewritten files | ||
| uv run pyright # type-check — must pass | ||
| uv run pytest -q # unit tests | ||
| ``` | ||
|
|
||
| Use `uv run`, **not `uvx`** — `uvx` strips the project venv, so pyright | ||
| reports every project import as unresolved. See the root `AGENTS.md` | ||
| ("Before Committing Python Changes") for the rationale. | ||
|
|
||
| ## Adding a New Subcommand | ||
|
|
||
| 1. Create or extend a `cli_<area>.py` module. | ||
| 2. Register it in `cli.py` (the Typer app entry point), or — for `install` | ||
| subcommands — under `install_app` in `cli_install.py`. | ||
| 3. Wrap any library exceptions (`InstallError`, `PlatformInstallError`) at | ||
| the CLI boundary and exit with `typer.Exit(1)`. The | ||
| `_install_platform_or_exit` helper in `cli_install.py` shows the | ||
| pattern for platform installers. |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1 @@ | ||
| AGENTS.md |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,119 @@ | ||
| """Scenario-driven install command. | ||
|
|
||
| Reads a `scenarios.yaml` (or standalone `instance.yaml`) and installs every | ||
| artifact referenced — platform service binary, per-KAS binaries (each at | ||
| its own pinned version), and encrypt/decrypt SDK CLIs. Writes | ||
| `installed.json` next to the manifest so downstream tools (`otdf-local`, | ||
| plugin skills) can locate the dist paths without re-resolving. | ||
| """ | ||
|
|
||
| from __future__ import annotations | ||
|
|
||
| import json | ||
| from pathlib import Path | ||
| from typing import Annotated | ||
|
|
||
| import typer | ||
|
|
||
| from otdf_sdk_mgr.installers import InstallError, install_release | ||
| from otdf_sdk_mgr.platform_installer import ( | ||
| PlatformInstallError, | ||
| install_helper_scripts, | ||
| install_platform_release, | ||
| install_platform_source, | ||
| ) | ||
| from otdf_sdk_mgr.schema import ( | ||
| Instance, | ||
| KasPin, | ||
| PlatformPin, | ||
| Scenario, | ||
| load_yaml_mapping, | ||
| ) | ||
|
|
||
|
|
||
| def _install_platform_pin(pin: PlatformPin | KasPin) -> dict[str, str]: | ||
| if pin.dist is not None: | ||
| dist_dir = install_platform_release(pin.dist) | ||
| return {"kind": "dist", "version": pin.dist, "path": str(dist_dir)} | ||
| assert pin.source is not None # by schema invariant | ||
| dist_dir = install_platform_source(pin.source.ref) | ||
| return {"kind": "source", "ref": pin.source.ref, "path": str(dist_dir)} | ||
|
|
||
|
|
||
| def install_scenario_cmd( | ||
| path: Annotated[Path, typer.Argument(help="Path to scenarios.yaml or instance.yaml")], | ||
| skip_scripts: Annotated[ | ||
| bool, | ||
| typer.Option("--skip-scripts", help="Skip refreshing helper scripts from main"), | ||
| ] = False, | ||
| ) -> None: | ||
| """Install every artifact declared by a scenarios.yaml or instance.yaml.""" | ||
| if not path.exists(): | ||
| typer.echo(f"Error: {path} not found", err=True) | ||
| raise typer.Exit(1) | ||
|
|
||
| from ruamel.yaml.error import YAMLError | ||
|
|
||
| try: | ||
| raw = load_yaml_mapping(path) | ||
| except YAMLError as e: | ||
| typer.echo(f"Error: {path} is not valid YAML: {e}", err=True) | ||
| raise typer.Exit(1) | ||
|
|
||
| kind = raw.get("kind") if isinstance(raw.get("kind"), str) else None | ||
| scenario: Scenario | None = None | ||
| if kind == "Scenario": | ||
| scenario = Scenario.model_validate(raw) | ||
| instance = scenario.instance | ||
| elif kind == "Instance": | ||
| instance = Instance.model_validate(raw) | ||
| else: | ||
| typer.echo(f"Error: {path} has unknown kind {kind!r}", err=True) | ||
| raise typer.Exit(1) | ||
|
|
||
| installed_platform: dict[str, str] | None = None | ||
| installed_kas: dict[str, dict[str, str]] = {} | ||
| installed_sdks: dict[str, list[dict[str, str | None]]] = {"encrypt": [], "decrypt": []} | ||
| out = path.parent / f"{path.stem}.installed.json" | ||
|
|
||
| def _snapshot(status: str | None = None) -> dict[str, object]: | ||
| snap: dict[str, object] = { | ||
| "manifest": str(path), | ||
| "platform": installed_platform, | ||
| "kas": installed_kas, | ||
| "sdks": installed_sdks, | ||
| } | ||
| if status is not None: | ||
| snap["status"] = status | ||
| return snap | ||
|
|
||
| try: | ||
| installed_platform = _install_platform_pin(instance.platform) | ||
| for kas_name, kas_pin in instance.kas.items(): | ||
| installed_kas[kas_name] = _install_platform_pin(kas_pin) | ||
| if not skip_scripts: | ||
| install_helper_scripts() | ||
|
|
||
| if scenario is not None: | ||
| install_paths: dict[tuple[str, str, str | None], str] = {} | ||
| for entry in scenario.sdks.union(): | ||
| dist_dir = install_release(entry.sdk, entry.version) | ||
| install_paths[entry.install_key()] = str(dist_dir) | ||
| for role in ("encrypt", "decrypt"): | ||
| installed_sdks[role] = [ | ||
| { | ||
| "sdk": entry.sdk, | ||
| "version": entry.version, | ||
| "source": entry.source, | ||
| "path": install_paths[entry.install_key()], | ||
| } | ||
| for entry in getattr(scenario.sdks, role) | ||
| ] | ||
| except (PlatformInstallError, InstallError) as e: | ||
| out.write_text(json.dumps(_snapshot(status="partial"), indent=2) + "\n") | ||
| typer.echo(f"Error: {e}", err=True) | ||
| typer.echo(f" Wrote partial manifest to {out}", err=True) | ||
| raise typer.Exit(1) | ||
|
|
||
| out.write_text(json.dumps(_snapshot(), indent=2) + "\n") | ||
| typer.echo(f" Wrote {out}") | ||
Oops, something went wrong.
Oops, something went wrong.
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Handle non-YAML parse/validation failures as CLI exits.
Line 57-72 only handles YAML syntax errors. Read errors, top-level type errors, and schema validation failures currently escape as uncaught exceptions.
Proposed fix
📝 Committable suggestion
🤖 Prompt for AI Agents