Merge pull request 'API: add show clan to retrieve the buildClan meta' (#1592) from hsjobeki/clan-core:hsjobeki-main into main
All checks were successful
deploy / deploy-docs (push) Successful in 20s
buildbot/nix-build .#checks.aarch64-darwin.nixos-test_install_machine Build done.
buildbot/nix-build .#checks.aarch64-darwin.nixos-test-backup Build done.
buildbot/nix-build .#checks.aarch64-darwin.nixos-flash-installer Build done.
buildbot/nix-build .#checks.aarch64-darwin.nixos-iso-installer Build done.
buildbot/nix-build .#checks.aarch64-linux.nixos-test_install_machine Build done.
buildbot/nix-build .#checks.aarch64-linux.nixos-test-backup Build done.
buildbot/nix-build .#checks.aarch64-linux.nixos-flash-installer Build done.
buildbot/nix-build .#checks.x86_64-linux.check-for-breakpoints Build done.
buildbot/nix-build .#checks.x86_64-linux.clan-app-pytest Build done.
buildbot/nix-build .#checks.x86_64-linux.package-gui-installer-apk Build done.
buildbot/nix-build .#checks.x86_64-linux.package-gui-installer-deb Build done.
buildbot/nix-build .#checks.x86_64-linux.package-gui-installer-archlinux Build done.
buildbot/nix-build .#checks.x86_64-linux.clan-dep-fakeroot Build done.
buildbot/nix-build .#checks.x86_64-linux.package-gui-installer-rpm Build done.
buildbot/nix-build .#checks.x86_64-linux.clan-dep-git Build done.
buildbot/nix-build .#checks.x86_64-linux.clan-dep-nix Build done.
buildbot/nix-build .#checks.x86_64-linux.clan-dep-openssh Build done.
buildbot/nix-build .#checks.x86_64-linux."clan-dep-python3.11-mypy" Build done.
buildbot/nix-build .#checks.x86_64-linux."clan-dep-python3.11-qemu" Build done.
buildbot/nix-build .#checks.x86_64-linux.clan-dep-rsync Build done.
buildbot/nix-build .#checks.x86_64-linux.clan-dep-sops Build done.
buildbot/nix-build .#checks.x86_64-linux.clan-dep-sshpass Build done.
buildbot/nix-build .#checks.x86_64-linux.clan-dep-tor Build done.
buildbot/nix-build .#checks.x86_64-linux.clan-dep-zbar Build done.
buildbot/nix-build .#checks.x86_64-linux.clan-pytest-with-core Build done.
buildbot/nix-build .#checks.x86_64-linux.clan-pytest-without-core Build done.
buildbot/nix-build .#checks.x86_64-linux.clan-dep-e2fsprogs Build done.
buildbot/nix-build .#checks.x86_64-linux.clan-app-no-breakpoints Build done.
buildbot/nix-build .#checks.x86_64-linux.borgbackup Build done.
buildbot/nix-build .#checks.aarch64-linux.nixos-iso-installer Build done.
buildbot/nix-build .#checks.x86_64-linux.devShell-clan-cli Build done.
buildbot/nix-build .#checks.x86_64-linux.clan-dep-bash Build done.
buildbot/nix-build .#checks.x86_64-linux.clan-dep-age Build done.
buildbot/nix-build .#checks.x86_64-linux.devShell-webview-ui Build done.
buildbot/nix-build .#checks.x86_64-linux.devShell-default Build done.
buildbot/nix-build .#checks.x86_64-linux.lib-jsonschema-example-valid Build done.
buildbot/nix-build .#checks.x86_64-linux.devShell-clan-app Build done.
buildbot/nix-build .#checks.x86_64-linux.container Build done.
buildbot/nix-build .#checks.x86_64-linux.package-clan-app Build done.
buildbot/nix-build .#checks.x86_64-linux.package-editor Build done.
buildbot/nix-build .#checks.x86_64-linux.nixos-test-backup Build done.
buildbot/nix-build .#checks.x86_64-linux.package-impure-checks Build done.
buildbot/nix-build .#checks.x86_64-linux.package-merge-after-ci Build done.
buildbot/nix-build .#checks.x86_64-linux.lib-jsonschema-nix-unit-tests Build done.
buildbot/nix-build .#checks.x86_64-linux.package-deploy-docs Build done.
buildbot/nix-build .#checks.x86_64-linux.module-schema Build done.
buildbot/nix-build .#checks.x86_64-linux.flash Build done.
buildbot/nix-eval Build done.
checks / checks-impure (push) Successful in 2m12s
buildbot/nix-build .#checks.x86_64-linux.nixos-test_install_machine Build done.
buildbot/nix-build .#checks.x86_64-linux.deltachat Build done.
buildbot/nix-build .#checks.x86_64-linux.package-clan-cli Build done.
buildbot/nix-build .#checks.x86_64-linux.package-clan-cli-docs Build done.
buildbot/nix-build .#checks.x86_64-linux.package-clan-ts-api Build done.
buildbot/nix-build .#checks.x86_64-linux.package-default Build done.
buildbot/nix-build .#checks.x86_64-linux.devShell-docs Build done.
buildbot/nix-build .#checks.x86_64-linux.matrix-synapse Build done.
buildbot/nix-build .#checks.x86_64-linux.package-moonlight-sunshine-accept Build done.
buildbot/nix-build .#checks.x86_64-linux.package-pending-reviews Build done.
buildbot/nix-build .#checks.x86_64-linux.package-webview-ui Build done.
buildbot/nix-build .#checks.x86_64-linux.package-zerotier-members Build done.
buildbot/nix-build .#checks.x86_64-linux.package-zerotierone Build done.
buildbot/nix-build .#checks.x86_64-linux.package-zt-tcp-relay Build done.
buildbot/nix-build .#checks.x86_64-linux.package-tea-create-pr Build done.
buildbot/nix-build .#checks.x86_64-linux.package-function-schema Build done.
buildbot/nix-build .#checks.x86_64-linux.renderClanOptions Build done.
buildbot/nix-build .#checks.x86_64-linux.package-module-docs Build done.
buildbot/nix-build .#checks.x86_64-linux.nixos-iso-installer Build done.
buildbot/nix-build .#checks.x86_64-linux.treefmt Build done.
buildbot/nix-build .#checks.x86_64-linux.nixos-flash-installer Build done.
buildbot/nix-build .#checks.x86_64-linux.package-module-schema Build done.
buildbot/nix-build .#checks.x86_64-linux.package-docs Build done.
buildbot/nix-build .#checks.x86_64-linux.test-backups Build done.
buildbot/nix-build .#checks.x86_64-linux.zt-tcp-relay Build done.
buildbot/nix-build .#checks.x86_64-linux.wayland-proxy-virtwl Build done.
buildbot/nix-build .#checks.x86_64-linux.secrets Build done.
buildbot/nix-build .#checks.x86_64-linux.package-iso-installer Build done.
buildbot/nix-build .#checks.x86_64-linux.syncthing Build done.
buildbot/nix-build .#checks.x86_64-linux.test-installation Build done.
buildbot/nix-build .#checks.x86_64-linux.package-gui-install-test-ubuntu-22-04 Build done.

This commit is contained in:
clan-bot 2024-06-08 16:11:43 +00:00
commit 62735ebfe2
4 changed files with 75 additions and 991 deletions

View File

@ -82,6 +82,7 @@ nav:
- reference/cli/history.md
- reference/cli/machines.md
- reference/cli/secrets.md
- reference/cli/show.md
- reference/cli/ssh.md
- reference/cli/vms.md
- Clan Core:

View File

@ -8,6 +8,7 @@ from typing import Any
# These imports are unused, but necessary for @API.register to run once.
from clan_cli.api import directory
from clan_cli.flakes import show
__all__ = ["directory"]
@ -112,8 +113,17 @@ For more detailed information, visit: https://docs.clan.lol
),
formatter_class=argparse.RawTextHelpFormatter,
)
subparsers = parser.add_subparsers()
# Commands directly under the root i.e. "clan show"
show_parser = subparsers.add_parser(
"show",
help="Show the clan meta if present.",
description="Final meta results from clan/meta.json and flake arguments.",
)
show_parser.set_defaults(func=show.show_command)
parser_backups = subparsers.add_parser(
"backups",
help="manage backups of clan machines",

View File

@ -0,0 +1,64 @@
import argparse
import dataclasses
import json
import logging
from pathlib import Path
from clan_cli.api import API
from clan_cli.errors import ClanCmdError, ClanError
from ..cmd import run_no_stdout
from ..nix import nix_eval
log = logging.getLogger(__name__)
@dataclasses.dataclass
class ClanMeta:
name: str
description: str | None
icon: str | None
@API.register
def show_clan(uri: str | Path) -> ClanMeta:
cmd = nix_eval(
[
f"{uri}#clanInternals.meta",
"--json",
]
)
res = "{}"
try:
proc = run_no_stdout(cmd)
res = proc.stdout.strip()
except ClanCmdError:
raise ClanError(
"Clan might not have meta attributes",
location=f"show_clan {uri}",
description="Evaluation failed on clanInternals.meta attribute",
)
clan_meta = json.loads(res)
return ClanMeta(
name=clan_meta.get("name"),
description=clan_meta.get("description", None),
icon=clan_meta.get("icon", None),
)
def show_command(args: argparse.Namespace) -> None:
flake_path = Path(args.flake).resolve()
meta = show_clan(flake_path)
print(f"Name: {meta.name}")
print(f"Description: {meta.description or ''}")
print(f"Icon: {meta.icon or ''}")
def register_parser(parser: argparse.ArgumentParser) -> None:
parser.set_defaults(func=show_command)
parser.add_argument(
"show",
help="Show",
)

View File

@ -1,991 +0,0 @@
export const schema = {
"$comment": "An object containing API methods. ",
"type": "object",
"additionalProperties": false,
"required": [
"open_file",
"get_directory",
"create_machine",
"list_machines",
"show_machine",
"create_clan"
],
"properties": {
"open_file": {
"type": "object",
"required": [
"arguments",
"return"
],
"additionalProperties": false,
"properties": {
"return": {
"oneOf": [
{
"type": "object",
"properties": {
"status": {
"type": "string",
"enum": [
"success"
],
"description": "The status of the response."
},
"data": {
"oneOf": [
{
"type": "string"
},
{
"type": "null"
}
]
}
},
"required": [
"status"
],
"additionalProperties": false
},
{
"type": "object",
"properties": {
"status": {
"type": "string",
"enum": [
"error"
]
},
"errors": {
"type": "array",
"items": {
"type": "object",
"properties": {
"message": {
"type": "string"
},
"description": {
"oneOf": [
{
"type": "string"
},
{
"type": "null"
}
]
},
"location": {
"oneOf": [
{
"type": "array",
"items": {
"type": "string"
}
},
{
"type": "null"
}
]
}
},
"required": [
"message"
],
"additionalProperties": false
}
}
},
"required": [
"status",
"errors"
],
"additionalProperties": false
}
]
},
"arguments": {
"type": "object",
"required": [
"file_request"
],
"additionalProperties": false,
"properties": {
"file_request": {
"type": "object",
"properties": {
"mode": {
"type": "string",
"enum": [
"open_file",
"select_folder"
]
},
"title": {
"oneOf": [
{
"type": "string"
},
{
"type": "null"
}
]
},
"filters": {
"oneOf": [
{
"type": "object",
"properties": {
"title": {
"oneOf": [
{
"type": "string"
},
{
"type": "null"
}
]
},
"mime_types": {
"oneOf": [
{
"type": "array",
"items": {
"type": "string"
}
},
{
"type": "null"
}
]
},
"patterns": {
"oneOf": [
{
"type": "array",
"items": {
"type": "string"
}
},
{
"type": "null"
}
]
},
"suffixes": {
"oneOf": [
{
"type": "array",
"items": {
"type": "string"
}
},
{
"type": "null"
}
]
}
},
"required": [],
"additionalProperties": false
},
{
"type": "null"
}
]
}
},
"required": [
"mode"
],
"additionalProperties": false
}
}
}
}
},
"get_directory": {
"type": "object",
"required": [
"arguments",
"return"
],
"additionalProperties": false,
"properties": {
"return": {
"oneOf": [
{
"type": "object",
"properties": {
"status": {
"type": "string",
"enum": [
"success"
],
"description": "The status of the response."
},
"data": {
"type": "object",
"properties": {
"path": {
"type": "string"
},
"files": {
"type": "array",
"items": {
"type": "object",
"properties": {
"path": {
"type": "string"
},
"file_type": {
"type": "string",
"enum": [
"file",
"directory",
"symlink"
]
}
},
"required": [
"path",
"file_type"
],
"additionalProperties": false
}
}
},
"required": [
"path",
"files"
],
"additionalProperties": false
}
},
"required": [
"status",
"data"
],
"additionalProperties": false
},
{
"type": "object",
"properties": {
"status": {
"type": "string",
"enum": [
"error"
]
},
"errors": {
"type": "array",
"items": {
"type": "object",
"properties": {
"message": {
"type": "string"
},
"description": {
"oneOf": [
{
"type": "string"
},
{
"type": "null"
}
]
},
"location": {
"oneOf": [
{
"type": "array",
"items": {
"type": "string"
}
},
{
"type": "null"
}
]
}
},
"required": [
"message"
],
"additionalProperties": false
}
}
},
"required": [
"status",
"errors"
],
"additionalProperties": false
}
]
},
"arguments": {
"type": "object",
"required": [
"current_path"
],
"additionalProperties": false,
"properties": {
"current_path": {
"type": "string"
}
}
}
}
},
"create_machine": {
"type": "object",
"required": [
"arguments",
"return"
],
"additionalProperties": false,
"properties": {
"return": {
"oneOf": [
{
"type": "object",
"properties": {
"status": {
"type": "string",
"enum": [
"success"
],
"description": "The status of the response."
},
"data": {
"type": "null"
}
},
"required": [
"status"
],
"additionalProperties": false
},
{
"type": "object",
"properties": {
"status": {
"type": "string",
"enum": [
"error"
]
},
"errors": {
"type": "array",
"items": {
"type": "object",
"properties": {
"message": {
"type": "string"
},
"description": {
"oneOf": [
{
"type": "string"
},
{
"type": "null"
}
]
},
"location": {
"oneOf": [
{
"type": "array",
"items": {
"type": "string"
}
},
{
"type": "null"
}
]
}
},
"required": [
"message"
],
"additionalProperties": false
}
}
},
"required": [
"status",
"errors"
],
"additionalProperties": false
}
]
},
"arguments": {
"type": "object",
"required": [
"flake_dir",
"machine"
],
"additionalProperties": false,
"properties": {
"flake_dir": {
"oneOf": [
{
"type": "string"
},
{
"type": "string"
}
]
},
"machine": {
"type": "object",
"properties": {
"name": {
"type": "string"
},
"config": {
"type": "object",
"additionalProperties": {
"type": "integer"
}
}
},
"required": [
"name",
"config"
],
"additionalProperties": false
}
}
}
}
},
"list_machines": {
"type": "object",
"required": [
"arguments",
"return"
],
"additionalProperties": false,
"properties": {
"return": {
"oneOf": [
{
"type": "object",
"properties": {
"status": {
"type": "string",
"enum": [
"success"
],
"description": "The status of the response."
},
"data": {
"type": "array",
"items": {
"type": "string"
}
}
},
"required": [
"status",
"data"
],
"additionalProperties": false
},
{
"type": "object",
"properties": {
"status": {
"type": "string",
"enum": [
"error"
]
},
"errors": {
"type": "array",
"items": {
"type": "object",
"properties": {
"message": {
"type": "string"
},
"description": {
"oneOf": [
{
"type": "string"
},
{
"type": "null"
}
]
},
"location": {
"oneOf": [
{
"type": "array",
"items": {
"type": "string"
}
},
{
"type": "null"
}
]
}
},
"required": [
"message"
],
"additionalProperties": false
}
}
},
"required": [
"status",
"errors"
],
"additionalProperties": false
}
]
},
"arguments": {
"type": "object",
"required": [
"flake_url",
"debug"
],
"additionalProperties": false,
"properties": {
"flake_url": {
"oneOf": [
{
"type": "string"
},
{
"type": "string"
}
]
},
"debug": {
"type": "boolean"
}
}
}
}
},
"show_machine": {
"type": "object",
"required": [
"arguments",
"return"
],
"additionalProperties": false,
"properties": {
"return": {
"oneOf": [
{
"type": "object",
"properties": {
"status": {
"type": "string",
"enum": [
"success"
],
"description": "The status of the response."
},
"data": {
"type": "object",
"properties": {
"machine_name": {
"type": "string"
},
"machine_description": {
"oneOf": [
{
"type": "string"
},
{
"type": "null"
}
]
},
"machine_icon": {
"oneOf": [
{
"type": "string"
},
{
"type": "null"
}
]
}
},
"required": [
"machine_name"
],
"additionalProperties": false
}
},
"required": [
"status",
"data"
],
"additionalProperties": false
},
{
"type": "object",
"properties": {
"status": {
"type": "string",
"enum": [
"error"
]
},
"errors": {
"type": "array",
"items": {
"type": "object",
"properties": {
"message": {
"type": "string"
},
"description": {
"oneOf": [
{
"type": "string"
},
{
"type": "null"
}
]
},
"location": {
"oneOf": [
{
"type": "array",
"items": {
"type": "string"
}
},
{
"type": "null"
}
]
}
},
"required": [
"message"
],
"additionalProperties": false
}
}
},
"required": [
"status",
"errors"
],
"additionalProperties": false
}
]
},
"arguments": {
"type": "object",
"required": [
"flake_url",
"machine_name",
"debug"
],
"additionalProperties": false,
"properties": {
"flake_url": {
"oneOf": [
{
"type": "string"
},
{
"type": "string"
}
]
},
"machine_name": {
"type": "string"
},
"debug": {
"type": "boolean"
}
}
}
}
},
"create_clan": {
"type": "object",
"required": [
"arguments",
"return"
],
"additionalProperties": false,
"properties": {
"return": {
"oneOf": [
{
"type": "object",
"properties": {
"status": {
"type": "string",
"enum": [
"success"
],
"description": "The status of the response."
},
"data": {
"type": "object",
"properties": {
"git_init": {
"type": "object",
"properties": {
"stdout": {
"type": "string"
},
"stderr": {
"type": "string"
},
"cwd": {
"type": "string"
},
"command": {
"type": "string"
},
"returncode": {
"type": "integer"
},
"msg": {
"oneOf": [
{
"type": "string"
},
{
"type": "null"
}
]
}
},
"required": [
"stdout",
"stderr",
"cwd",
"command",
"returncode"
],
"additionalProperties": false
},
"git_add": {
"type": "object",
"properties": {
"stdout": {
"type": "string"
},
"stderr": {
"type": "string"
},
"cwd": {
"type": "string"
},
"command": {
"type": "string"
},
"returncode": {
"type": "integer"
},
"msg": {
"oneOf": [
{
"type": "string"
},
{
"type": "null"
}
]
}
},
"required": [
"stdout",
"stderr",
"cwd",
"command",
"returncode"
],
"additionalProperties": false
},
"git_config": {
"type": "object",
"properties": {
"stdout": {
"type": "string"
},
"stderr": {
"type": "string"
},
"cwd": {
"type": "string"
},
"command": {
"type": "string"
},
"returncode": {
"type": "integer"
},
"msg": {
"oneOf": [
{
"type": "string"
},
{
"type": "null"
}
]
}
},
"required": [
"stdout",
"stderr",
"cwd",
"command",
"returncode"
],
"additionalProperties": false
},
"flake_update": {
"type": "object",
"properties": {
"stdout": {
"type": "string"
},
"stderr": {
"type": "string"
},
"cwd": {
"type": "string"
},
"command": {
"type": "string"
},
"returncode": {
"type": "integer"
},
"msg": {
"oneOf": [
{
"type": "string"
},
{
"type": "null"
}
]
}
},
"required": [
"stdout",
"stderr",
"cwd",
"command",
"returncode"
],
"additionalProperties": false
}
},
"required": [
"git_init",
"git_add",
"git_config",
"flake_update"
],
"additionalProperties": false
}
},
"required": [
"status",
"data"
],
"additionalProperties": false
},
{
"type": "object",
"properties": {
"status": {
"type": "string",
"enum": [
"error"
]
},
"errors": {
"type": "array",
"items": {
"type": "object",
"properties": {
"message": {
"type": "string"
},
"description": {
"oneOf": [
{
"type": "string"
},
{
"type": "null"
}
]
},
"location": {
"oneOf": [
{
"type": "array",
"items": {
"type": "string"
}
},
{
"type": "null"
}
]
}
},
"required": [
"message"
],
"additionalProperties": false
}
}
},
"required": [
"status",
"errors"
],
"additionalProperties": false
}
]
},
"arguments": {
"type": "object",
"required": [
"directory",
"template_url"
],
"additionalProperties": false,
"properties": {
"directory": {
"type": "string"
},
"template_url": {
"type": "string"
}
}
}
}
}
}
} as const;