-
Notifications
You must be signed in to change notification settings - Fork 2
[DSPX-3302] (2/5) Manage platform service + install scenario in otdf-sdk-mgr #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
Draft
dmihalcik-virtru
wants to merge
1
commit into
DSPX-3302-01-shared-schema
Choose a base branch
from
DSPX-3302-02-platform-installer
base: DSPX-3302-01-shared-schema
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.
Draft
Changes from all commits
Commits
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
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,104 @@ | ||
| """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 KasPin, PlatformPin, Scenario, load_instance, load_scenario | ||
|
|
||
|
|
||
| def _install_platform_pin(pin: PlatformPin | KasPin, label: str) -> dict[str, str]: | ||
| if pin.image is not None: | ||
| raise typer.BadParameter( | ||
| f"{label}: container-image platform pins are not supported in v1; use dist or source" | ||
| ) | ||
| 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) | ||
|
|
||
| raw_kind = _peek_kind(path) | ||
| scenario: Scenario | None = None | ||
| if raw_kind == "Scenario": | ||
| scenario = load_scenario(path) | ||
| instance = scenario.instance | ||
| elif raw_kind == "Instance": | ||
| instance = load_instance(path) | ||
| else: | ||
| typer.echo(f"Error: {path} has unknown kind {raw_kind!r}", err=True) | ||
| raise typer.Exit(1) | ||
|
Comment on lines
+53
to
+62
Contributor
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. |
||
|
|
||
| installed: dict[str, object] = {"manifest": str(path), "platform": None, "kas": {}, "sdks": {}} | ||
|
|
||
| try: | ||
| installed["platform"] = _install_platform_pin(instance.platform, "platform") | ||
| for kas_name, kas_pin in instance.kas.items(): | ||
| installed["kas"][kas_name] = _install_platform_pin(kas_pin, f"kas.{kas_name}") | ||
| if not skip_scripts: | ||
| install_helper_scripts() | ||
| except PlatformInstallError as e: | ||
| typer.echo(f"Error installing platform artifacts: {e}", err=True) | ||
| raise typer.Exit(1) | ||
|
|
||
| if scenario is not None: | ||
| sdks = scenario.sdks.union() | ||
| for sdk_name, sdk_pin in sdks.items(): | ||
| try: | ||
| dist_dir = install_release(sdk_name, sdk_pin.version, source=sdk_pin.source) | ||
| installed["sdks"][sdk_name] = { | ||
| "version": sdk_pin.version, | ||
| "source": sdk_pin.source, | ||
| "path": str(dist_dir), | ||
| } | ||
| except InstallError as e: | ||
| typer.echo(f"Error installing SDK {sdk_name}: {e}", err=True) | ||
| raise typer.Exit(1) | ||
|
|
||
| out = path.parent / f"{path.stem}.installed.json" | ||
| out.write_text(json.dumps(installed, indent=2) + "\n") | ||
| typer.echo(f" Wrote {out}") | ||
|
|
||
|
|
||
| def _peek_kind(path: Path) -> str | None: | ||
| """Cheap pre-validation read so we can dispatch to the right model loader.""" | ||
| from ruamel.yaml import YAML | ||
|
|
||
| y = YAML(typ="safe") | ||
| raw = y.load(path.read_text()) | ||
| if isinstance(raw, dict): | ||
| kind = raw.get("kind") | ||
| return kind if isinstance(kind, str) else None | ||
| return None | ||
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.
The logic for handling the
platformtarget is duplicated here and in thetipcommand (lines 82-91). This pattern makes the CLI code harder to maintain. Consider refactoring this into a shared helper function or extending thecmd_lts/cmd_tipfunctions to handle the platform service internally, similar to how other SDKs are handled.