Less stack-centric and location-centric model.
This commit is contained in:
@@ -27,6 +27,9 @@ class ComponentSummary(BaseModel):
|
||||
systemd: SystemdInfo | None = None
|
||||
version: str | None = None
|
||||
source: str | None = None
|
||||
repo: str | None = None
|
||||
ref: str | None = None
|
||||
commands: dict[str, list[list[str]]] | None = None
|
||||
system_dependencies: list[str] = []
|
||||
schedule: str | None = None
|
||||
installed: bool | None = None
|
||||
@@ -91,6 +94,9 @@ class ProgramSummary(BaseModel):
|
||||
runner: str | None = None
|
||||
version: str | None = None
|
||||
source: str | None = None
|
||||
repo: str | None = None
|
||||
ref: str | None = None
|
||||
commands: dict[str, list[list[str]]] | None = None
|
||||
system_dependencies: list[str] = []
|
||||
installed: bool | None = None
|
||||
actions: list[str] = []
|
||||
|
||||
@@ -66,7 +66,6 @@ def _deployed_to_summaries(registry: object, hostname: str) -> list[ComponentSum
|
||||
def get_mesh_status(request: Request) -> MeshStatus:
|
||||
"""Get the current state of the mesh coordination layer."""
|
||||
mqtt_client = getattr(request.app.state, "mqtt_client", None)
|
||||
mdns = getattr(request.app.state, "mdns", None)
|
||||
|
||||
peers = list(mesh_state.all_nodes(include_stale=True).keys())
|
||||
|
||||
|
||||
@@ -4,7 +4,7 @@ from __future__ import annotations
|
||||
|
||||
from fastapi import APIRouter, HTTPException, status
|
||||
|
||||
from castle_core.stacks import available_actions, get_handler
|
||||
from castle_core.stacks import available_actions, run_action
|
||||
|
||||
from castle_api.config import get_config
|
||||
|
||||
@@ -27,7 +27,11 @@ _VALID_ACTIONS = {
|
||||
|
||||
@programs_router.post("/programs/{name}/{action}")
|
||||
async def program_action(name: str, action: str) -> dict:
|
||||
"""Run a lifecycle action on a program via its stack handler."""
|
||||
"""Run a lifecycle action on a program.
|
||||
|
||||
Resolution-aware: a declared `commands:` entry overrides the stack default,
|
||||
so a program with no stack can still be linted/tested/built/installed.
|
||||
"""
|
||||
if action not in _VALID_ACTIONS:
|
||||
raise HTTPException(status_code=400, detail=f"Unknown action: {action}")
|
||||
|
||||
@@ -41,24 +45,14 @@ async def program_action(name: str, action: str) -> dict:
|
||||
if not comp.source:
|
||||
raise HTTPException(status_code=400, detail=f"'{name}' has no source directory")
|
||||
|
||||
actions = available_actions(comp)
|
||||
if action not in actions:
|
||||
if action not in available_actions(comp):
|
||||
raise HTTPException(
|
||||
status_code=400,
|
||||
detail=f"Action '{action}' not available for '{name}' (stack: {comp.stack})",
|
||||
detail=f"Action '{action}' not available for '{name}' "
|
||||
f"(no declared command and no stack handler provides it)",
|
||||
)
|
||||
|
||||
handler = get_handler(comp.stack)
|
||||
if handler is None:
|
||||
raise HTTPException(
|
||||
status_code=400, detail=f"No handler for stack '{comp.stack}'"
|
||||
)
|
||||
|
||||
# Map hyphenated action names to method names (type-check → type_check)
|
||||
method_name = action.replace("-", "_")
|
||||
method = getattr(handler, method_name)
|
||||
|
||||
result = await method(name, comp, config.root)
|
||||
result = await run_action(action, name, comp, config.root)
|
||||
|
||||
if result.status != "ok":
|
||||
raise HTTPException(status_code=500, detail=result.output or f"{action} failed")
|
||||
|
||||
@@ -34,6 +34,19 @@ from castle_api.models import (
|
||||
router = APIRouter(tags=["dashboard"])
|
||||
|
||||
|
||||
def _declared_commands_dict(comp: ProgramSpec) -> dict[str, list[list[str]]] | None:
|
||||
"""Serialize a program's declared verbs for the API (build + CommandsSpec)."""
|
||||
out: dict[str, list[list[str]]] = {}
|
||||
if comp.build and comp.build.commands:
|
||||
out["build"] = comp.build.commands
|
||||
if comp.commands is not None:
|
||||
for verb in ("lint", "test", "type-check", "check", "run", "install", "uninstall"):
|
||||
cmds = comp.commands.for_verb(verb)
|
||||
if cmds:
|
||||
out[verb] = cmds
|
||||
return out or None
|
||||
|
||||
|
||||
def _summary_from_deployed(name: str, deployed: object) -> ComponentSummary:
|
||||
"""Build a ComponentSummary from a DeployedComponent."""
|
||||
managed = deployed.managed
|
||||
@@ -172,7 +185,7 @@ def _summary_from_program(name: str, comp: ProgramSpec, root: Path) -> Component
|
||||
runner = "command"
|
||||
|
||||
installed: bool | None = None
|
||||
if comp.source and comp.stack:
|
||||
if comp.source and (comp.stack or comp.commands):
|
||||
installed = shutil.which(name) is not None
|
||||
|
||||
return ComponentSummary(
|
||||
@@ -184,6 +197,9 @@ def _summary_from_program(name: str, comp: ProgramSpec, root: Path) -> Component
|
||||
runner=runner,
|
||||
version=comp.version,
|
||||
source=source,
|
||||
repo=comp.repo,
|
||||
ref=comp.ref,
|
||||
commands=_declared_commands_dict(comp),
|
||||
system_dependencies=comp.system_dependencies,
|
||||
installed=installed,
|
||||
)
|
||||
@@ -323,7 +339,7 @@ def _program_from_spec(
|
||||
runner = "command"
|
||||
|
||||
installed: bool | None = None
|
||||
if comp.source and comp.stack:
|
||||
if comp.source and (comp.stack or comp.commands):
|
||||
installed = shutil.which(name) is not None
|
||||
|
||||
return ProgramSummary(
|
||||
@@ -334,6 +350,9 @@ def _program_from_spec(
|
||||
runner=runner,
|
||||
version=comp.version,
|
||||
source=source,
|
||||
repo=comp.repo,
|
||||
ref=comp.ref,
|
||||
commands=_declared_commands_dict(comp),
|
||||
system_dependencies=comp.system_dependencies,
|
||||
installed=installed,
|
||||
actions=available_actions(comp),
|
||||
|
||||
Reference in New Issue
Block a user