forked from clan/clan-core
api: add endpoint machine_schema
This commit is contained in:
parent
27b0d18f0d
commit
ea87166e44
@ -1,5 +1,7 @@
|
||||
import json
|
||||
|
||||
# some unused imports are needed to trigger registrations of api functions
|
||||
import clan_cli.config.schema # noqa: F401
|
||||
from clan_cli.api import API
|
||||
|
||||
|
||||
|
@ -196,7 +196,7 @@ def type_to_dict(t: Any, scope: str = "", type_map: dict[TypeVar, type] = {}) ->
|
||||
}
|
||||
if t is dict:
|
||||
raise JSchemaTypeError(
|
||||
"Error: generic dict type not supported. Use dict[str. Any] instead"
|
||||
"Error: generic dict type not supported. Use dict[str, Any] instead"
|
||||
)
|
||||
|
||||
# Optional[T] gets internally transformed Union[T,NoneType]
|
||||
|
@ -2,18 +2,22 @@ import json
|
||||
import os
|
||||
from pathlib import Path
|
||||
from tempfile import NamedTemporaryFile
|
||||
from typing import Any
|
||||
|
||||
from clan_cli.api import API
|
||||
from clan_cli.cmd import run
|
||||
from clan_cli.dirs import nixpkgs_source
|
||||
from clan_cli.errors import ClanError, ClanHttpError
|
||||
from clan_cli.nix import nix_eval
|
||||
|
||||
|
||||
@API.register
|
||||
def machine_schema(
|
||||
flake_dir: Path,
|
||||
config: dict,
|
||||
config: dict[str, Any],
|
||||
clan_imports: list[str] | None = None,
|
||||
) -> dict:
|
||||
option_path: list[str] = ["clan"],
|
||||
) -> dict[str, Any]:
|
||||
# use nix eval to lib.evalModules .#nixosConfigurations.<machine_name>.options.clan
|
||||
with NamedTemporaryFile(mode="w", dir=flake_dir) as clan_machine_settings_file:
|
||||
env = os.environ.copy()
|
||||
@ -89,9 +93,9 @@ def machine_schema(
|
||||
# add all clan modules specified via clanImports
|
||||
++ (map (name: clan-core.clanModules.${{name}}) config.clanImports or []);
|
||||
}};
|
||||
clanOptions = fakeMachine.options.clan;
|
||||
options = fakeMachine.options{"." + ".".join(option_path) if option_path else ""};
|
||||
jsonschemaLib = import {Path(__file__).parent / "jsonschema"} {{ inherit lib; }};
|
||||
jsonschema = jsonschemaLib.parseOptions clanOptions;
|
||||
jsonschema = jsonschemaLib.parseOptions options;
|
||||
in
|
||||
jsonschema
|
||||
""",
|
||||
|
@ -22,4 +22,5 @@ def test_modules_details(test_flake_with_core: FlakeForTest) -> None:
|
||||
module_info = show_module_info(base_path, test_module)
|
||||
assert module_info.description is not None and module_info.description != ""
|
||||
assert module_info.categories and "backup" in module_info.categories
|
||||
assert module_info.roles == ["server", "client"]
|
||||
assert module_info.roles
|
||||
assert set(module_info.roles) == {"server", "client"}
|
||||
|
Loading…
Reference in New Issue
Block a user