feat(python): add galaxy-* CLI commands (§4.2)
This commit is contained in:
@@ -21,6 +21,7 @@ from zb_mom_ww_mxgateway import __version__
|
||||
from zb_mom_ww_mxgateway.auth import redact_secret
|
||||
from zb_mom_ww_mxgateway.client import GatewayClient
|
||||
from zb_mom_ww_mxgateway.errors import MxGatewayError
|
||||
from zb_mom_ww_mxgateway.galaxy import GalaxyRepositoryClient
|
||||
from zb_mom_ww_mxgateway.generated import mxaccess_gateway_pb2 as pb
|
||||
from zb_mom_ww_mxgateway.options import ClientOptions
|
||||
from zb_mom_ww_mxgateway.values import MxValueInput, to_mx_value
|
||||
@@ -512,6 +513,67 @@ def smoke(**kwargs: Any) -> None:
|
||||
_run(_smoke(**kwargs), output_json=kwargs["output_json"], secrets=_secrets(kwargs))
|
||||
|
||||
|
||||
@main.command("galaxy-test-connection")
|
||||
@gateway_options
|
||||
@click.option("--json", "output_json", is_flag=True, help="Emit JSON output.")
|
||||
def galaxy_test_connection(**kwargs: Any) -> None:
|
||||
"""Test whether the gateway can reach the Galaxy Repository DB."""
|
||||
|
||||
_run(
|
||||
_galaxy_test_connection(**kwargs),
|
||||
output_json=kwargs["output_json"],
|
||||
secrets=_secrets(kwargs),
|
||||
)
|
||||
|
||||
|
||||
@main.command("galaxy-last-deploy")
|
||||
@gateway_options
|
||||
@click.option("--json", "output_json", is_flag=True, help="Emit JSON output.")
|
||||
def galaxy_last_deploy(**kwargs: Any) -> None:
|
||||
"""Read the last Galaxy deploy timestamp."""
|
||||
|
||||
_run(
|
||||
_galaxy_last_deploy(**kwargs),
|
||||
output_json=kwargs["output_json"],
|
||||
secrets=_secrets(kwargs),
|
||||
)
|
||||
|
||||
|
||||
@main.command("galaxy-discover")
|
||||
@gateway_options
|
||||
@click.option("--json", "output_json", is_flag=True, help="Emit JSON output.")
|
||||
def galaxy_discover(**kwargs: Any) -> None:
|
||||
"""Enumerate the deployed Galaxy object hierarchy."""
|
||||
|
||||
_run(
|
||||
_galaxy_discover(**kwargs),
|
||||
output_json=kwargs["output_json"],
|
||||
secrets=_secrets(kwargs),
|
||||
)
|
||||
|
||||
|
||||
@main.command("galaxy-watch")
|
||||
@gateway_options
|
||||
@click.option(
|
||||
"--last-seen-deploy-time",
|
||||
"last_seen_deploy_time",
|
||||
default=None,
|
||||
help="ISO-8601 timestamp; when it matches the current cached deploy time the "
|
||||
"bootstrap event is suppressed.",
|
||||
)
|
||||
@click.option("--max-events", default=1, type=int, show_default=True)
|
||||
@click.option("--timeout", default=5.0, type=float, show_default=True)
|
||||
@click.option("--json", "output_json", is_flag=True, help="Emit JSON output.")
|
||||
def galaxy_watch(**kwargs: Any) -> None:
|
||||
"""Stream a bounded number of Galaxy deploy events."""
|
||||
|
||||
_run(
|
||||
_galaxy_watch(**kwargs),
|
||||
output_json=kwargs["output_json"],
|
||||
secrets=_secrets(kwargs),
|
||||
)
|
||||
|
||||
|
||||
async def _open_session(**kwargs: Any) -> dict[str, Any]:
|
||||
async with await _connect(kwargs) as client:
|
||||
reply = await client.open_session_raw(
|
||||
@@ -922,6 +984,48 @@ async def _smoke(**kwargs: Any) -> dict[str, Any]:
|
||||
await session.close()
|
||||
|
||||
|
||||
async def _galaxy_test_connection(**kwargs: Any) -> dict[str, Any]:
|
||||
async with await _connect_galaxy(kwargs) as galaxy:
|
||||
ok = await galaxy.test_connection()
|
||||
return {"command": "galaxy-test-connection", "ok": ok}
|
||||
|
||||
|
||||
async def _galaxy_last_deploy(**kwargs: Any) -> dict[str, Any]:
|
||||
async with await _connect_galaxy(kwargs) as galaxy:
|
||||
last_deploy = await galaxy.get_last_deploy_time()
|
||||
payload: dict[str, Any] = {
|
||||
"command": "galaxy-last-deploy",
|
||||
"present": last_deploy is not None,
|
||||
}
|
||||
if last_deploy is not None:
|
||||
payload["timeOfLastDeploy"] = last_deploy.isoformat()
|
||||
return payload
|
||||
|
||||
|
||||
async def _galaxy_discover(**kwargs: Any) -> dict[str, Any]:
|
||||
async with await _connect_galaxy(kwargs) as galaxy:
|
||||
objects = await galaxy.discover_hierarchy()
|
||||
return {
|
||||
"command": "galaxy-discover",
|
||||
"objects": [_message_dict(obj) for obj in objects],
|
||||
}
|
||||
|
||||
|
||||
async def _galaxy_watch(**kwargs: Any) -> dict[str, Any]:
|
||||
last_seen = kwargs.get("last_seen_deploy_time")
|
||||
last_seen_dt = _parse_datetime(last_seen) if last_seen else None
|
||||
async with await _connect_galaxy(kwargs) as galaxy:
|
||||
events = await _collect_events(
|
||||
galaxy.watch_deploy_events(last_seen_dt),
|
||||
max_events=kwargs["max_events"],
|
||||
timeout=kwargs["timeout"],
|
||||
)
|
||||
return {
|
||||
"command": "galaxy-watch",
|
||||
"events": [_message_dict(event) for event in events],
|
||||
}
|
||||
|
||||
|
||||
async def _connect(kwargs: dict[str, Any]) -> GatewayClient:
|
||||
api_key = kwargs.get("api_key") or _api_key_from_env(kwargs.get("api_key_env"))
|
||||
return await GatewayClient.connect(
|
||||
@@ -938,6 +1042,22 @@ async def _connect(kwargs: dict[str, Any]) -> GatewayClient:
|
||||
)
|
||||
|
||||
|
||||
async def _connect_galaxy(kwargs: dict[str, Any]) -> GalaxyRepositoryClient:
|
||||
api_key = kwargs.get("api_key") or _api_key_from_env(kwargs.get("api_key_env"))
|
||||
return await GalaxyRepositoryClient.connect(
|
||||
ClientOptions(
|
||||
endpoint=kwargs["endpoint"],
|
||||
api_key=api_key,
|
||||
plaintext=_use_plaintext(kwargs),
|
||||
ca_file=kwargs.get("ca_file"),
|
||||
require_certificate_validation=bool(kwargs.get("require_certificate_validation")),
|
||||
server_name_override=kwargs.get("server_name_override"),
|
||||
call_timeout=kwargs.get("call_timeout"),
|
||||
stream_timeout=kwargs.get("stream_timeout"),
|
||||
),
|
||||
)
|
||||
|
||||
|
||||
def _session(client: GatewayClient, session_id: str):
|
||||
from zb_mom_ww_mxgateway.session import Session
|
||||
|
||||
|
||||
Reference in New Issue
Block a user