Merge pull request 'chore(api/create_clan): remove unused reponse class' (#3907) from api-narrowing into main
Reviewed-on: https://git.clan.lol/clan/clan-core/pulls/3907
This commit is contained in:
@@ -7,6 +7,7 @@ from clan_lib.cmd import run
|
||||
from clan_lib.dirs import machine_gcroot
|
||||
from clan_lib.errors import ClanError
|
||||
from clan_lib.flake import Flake
|
||||
from clan_lib.machines.actions import list_machines
|
||||
from clan_lib.machines.machines import Machine
|
||||
from clan_lib.nix import (
|
||||
nix_add_to_gcroots,
|
||||
@@ -16,7 +17,6 @@ from clan_lib.nix import (
|
||||
nix_metadata,
|
||||
)
|
||||
|
||||
from clan_cli.machines.list import list_full_machines
|
||||
from clan_cli.vms.inspect import VmConfig, inspect_vm
|
||||
|
||||
|
||||
@@ -58,7 +58,7 @@ def inspect_flake(flake_url: str | Path, machine_name: str) -> FlakeConfig:
|
||||
system = config["system"]
|
||||
|
||||
# Check if the machine exists
|
||||
machines: dict[str, Machine] = list_full_machines(Flake(str(flake_url)))
|
||||
machines = list_machines(Flake(str(flake_url)))
|
||||
if machine_name not in machines:
|
||||
msg = f"Machine {machine_name} not found in {flake_url}. Available machines: {', '.join(machines)}"
|
||||
raise ClanError(msg)
|
||||
|
||||
@@ -3,7 +3,7 @@ from dataclasses import dataclass
|
||||
from pathlib import Path
|
||||
|
||||
from clan_lib.api import API
|
||||
from clan_lib.cmd import CmdOut, RunOpts, run
|
||||
from clan_lib.cmd import RunOpts, run
|
||||
from clan_lib.errors import ClanError
|
||||
from clan_lib.flake import Flake
|
||||
from clan_lib.nix import nix_command, nix_metadata, nix_shell
|
||||
@@ -18,15 +18,6 @@ from clan_lib.templates import (
|
||||
log = logging.getLogger(__name__)
|
||||
|
||||
|
||||
@dataclass
|
||||
class CreateClanResponse:
|
||||
flake_update: CmdOut | None = None
|
||||
git_init: CmdOut | None = None
|
||||
git_add: CmdOut | None = None
|
||||
git_config_username: CmdOut | None = None
|
||||
git_config_email: CmdOut | None = None
|
||||
|
||||
|
||||
@dataclass
|
||||
class CreateOptions:
|
||||
dest: Path
|
||||
@@ -43,7 +34,7 @@ def git_command(directory: Path, *args: str) -> list[str]:
|
||||
|
||||
|
||||
@API.register
|
||||
def create_clan(opts: CreateOptions) -> CreateClanResponse:
|
||||
def create_clan(opts: CreateOptions) -> None:
|
||||
dest = opts.dest.resolve()
|
||||
|
||||
if opts.src_flake is not None:
|
||||
@@ -75,36 +66,28 @@ def create_clan(opts: CreateOptions) -> CreateClanResponse:
|
||||
|
||||
copy_from_nixstore(src, dest)
|
||||
|
||||
response = CreateClanResponse()
|
||||
|
||||
if opts.setup_git:
|
||||
response.git_init = run(git_command(dest, "init"))
|
||||
response.git_add = run(git_command(dest, "add", "."))
|
||||
run(git_command(dest, "init"))
|
||||
run(git_command(dest, "add", "."))
|
||||
|
||||
# check if username is set
|
||||
has_username = run(
|
||||
git_command(dest, "config", "user.name"), RunOpts(check=False)
|
||||
)
|
||||
response.git_config_username = None
|
||||
if has_username.returncode != 0:
|
||||
response.git_config_username = run(
|
||||
git_command(dest, "config", "user.name", "clan-tool")
|
||||
)
|
||||
run(git_command(dest, "config", "user.name", "clan-tool"))
|
||||
|
||||
has_username = run(
|
||||
git_command(dest, "config", "user.email"), RunOpts(check=False)
|
||||
)
|
||||
if has_username.returncode != 0:
|
||||
response.git_config_email = run(
|
||||
git_command(dest, "config", "user.email", "clan@example.com")
|
||||
)
|
||||
run(git_command(dest, "config", "user.email", "clan@example.com"))
|
||||
|
||||
if opts.update_clan:
|
||||
flake_update = run(nix_command(["flake", "update"]), RunOpts(cwd=dest))
|
||||
response.flake_update = flake_update
|
||||
run(nix_command(["flake", "update"]), RunOpts(cwd=dest))
|
||||
|
||||
if opts.initial:
|
||||
inventory_store = InventoryStore(flake=Flake(str(opts.dest)))
|
||||
inventory_store.write(opts.initial, message="Init inventory")
|
||||
|
||||
return response
|
||||
return
|
||||
|
||||
@@ -568,7 +568,6 @@ class Flake:
|
||||
"""
|
||||
|
||||
identifier: str
|
||||
inputs_from: str | None = None
|
||||
hash: str | None = None
|
||||
store_path: str | None = None
|
||||
|
||||
@@ -634,9 +633,6 @@ class Flake:
|
||||
self.identifier,
|
||||
]
|
||||
|
||||
if self.inputs_from:
|
||||
cmd += ["--inputs-from", self.inputs_from]
|
||||
|
||||
flake_prefetch = run(nix_command(cmd))
|
||||
flake_metadata = json.loads(flake_prefetch.stdout)
|
||||
self.store_path = flake_metadata["storePath"]
|
||||
|
||||
@@ -7,6 +7,9 @@ from clan_lib.cmd import run
|
||||
from clan_lib.dirs import clan_templates
|
||||
from clan_lib.errors import ClanCmdError, ClanError
|
||||
from clan_lib.flake import Flake
|
||||
from clan_lib.nix import (
|
||||
nix_command,
|
||||
)
|
||||
|
||||
log = logging.getLogger(__name__)
|
||||
|
||||
@@ -202,16 +205,26 @@ def list_templates(
|
||||
return result
|
||||
|
||||
|
||||
def realize_nix_path(clan_dir: Flake, nix_path: str) -> None:
|
||||
def realize_nix_path(flake: Flake, nix_store_path: str) -> None:
|
||||
"""
|
||||
Downloads / realizes a nix path into the nix store
|
||||
"""
|
||||
|
||||
if Path(nix_path).exists():
|
||||
if Path(nix_store_path).exists():
|
||||
return
|
||||
|
||||
flake = Flake(identifier=nix_path, inputs_from=clan_dir.identifier)
|
||||
flake.invalidate_cache()
|
||||
cmd = [
|
||||
"flake",
|
||||
"prefetch",
|
||||
"--inputs-from",
|
||||
flake.identifier,
|
||||
"--option",
|
||||
"flake-registry",
|
||||
"",
|
||||
nix_store_path,
|
||||
]
|
||||
|
||||
run(nix_command(cmd))
|
||||
|
||||
|
||||
def get_template(
|
||||
|
||||
Reference in New Issue
Block a user