GUI: generate sops key when creating clan
This commit is contained in:
@@ -1,17 +1,19 @@
|
|||||||
import argparse
|
import argparse
|
||||||
import logging
|
import logging
|
||||||
import os
|
import os
|
||||||
|
from pathlib import Path
|
||||||
|
|
||||||
from clan_cli.errors import ClanError
|
from clan_cli.errors import ClanError
|
||||||
from clan_cli.flake import Flake
|
|
||||||
from clan_cli.secrets.key import generate_key
|
from clan_cli.secrets.key import generate_key
|
||||||
from clan_cli.secrets.sops import maybe_get_admin_public_key
|
from clan_cli.secrets.sops import maybe_get_admin_public_key
|
||||||
from clan_cli.secrets.users import add_user
|
from clan_cli.secrets.users import add_user
|
||||||
|
from clan_lib.api import API
|
||||||
|
|
||||||
log = logging.getLogger(__name__)
|
log = logging.getLogger(__name__)
|
||||||
|
|
||||||
|
|
||||||
def keygen(user: str | None, flake: Flake, force: bool) -> None:
|
@API.register
|
||||||
|
def keygen(flake_dir: Path, user: str | None = None, force: bool = False) -> None:
|
||||||
if user is None:
|
if user is None:
|
||||||
user = os.getenv("USER", None)
|
user = os.getenv("USER", None)
|
||||||
if not user:
|
if not user:
|
||||||
@@ -22,7 +24,7 @@ def keygen(user: str | None, flake: Flake, force: bool) -> None:
|
|||||||
pub_key = generate_key()
|
pub_key = generate_key()
|
||||||
# TODO set flake_dir=flake.path / "vars"
|
# TODO set flake_dir=flake.path / "vars"
|
||||||
add_user(
|
add_user(
|
||||||
flake_dir=flake.path,
|
flake_dir=flake_dir,
|
||||||
name=user,
|
name=user,
|
||||||
keys=[pub_key],
|
keys=[pub_key],
|
||||||
force=force,
|
force=force,
|
||||||
@@ -33,8 +35,8 @@ def _command(
|
|||||||
args: argparse.Namespace,
|
args: argparse.Namespace,
|
||||||
) -> None:
|
) -> None:
|
||||||
keygen(
|
keygen(
|
||||||
|
flake_dir=args.flake.path,
|
||||||
user=args.user,
|
user=args.user,
|
||||||
flake=args.flake,
|
|
||||||
force=args.force,
|
force=args.force,
|
||||||
)
|
)
|
||||||
|
|
||||||
|
|||||||
@@ -33,7 +33,6 @@ class Prompt:
|
|||||||
description=data["description"],
|
description=data["description"],
|
||||||
prompt_type=PromptType(data["type"]),
|
prompt_type=PromptType(data["type"]),
|
||||||
persist=data.get("persist", data["persist"]),
|
persist=data.get("persist", data["persist"]),
|
||||||
previous_value=data.get("previousValue"),
|
|
||||||
)
|
)
|
||||||
|
|
||||||
|
|
||||||
|
|||||||
@@ -7,7 +7,7 @@ import {
|
|||||||
SubmitHandler,
|
SubmitHandler,
|
||||||
} from "@modular-forms/solid";
|
} from "@modular-forms/solid";
|
||||||
import toast from "solid-toast";
|
import toast from "solid-toast";
|
||||||
import { setActiveURI, setClanList } from "@/src/App";
|
import { activeURI, setActiveURI, setClanList } from "@/src/App";
|
||||||
import { TextInput } from "@/src/Form/fields/TextInput";
|
import { TextInput } from "@/src/Form/fields/TextInput";
|
||||||
import { useNavigate } from "@solidjs/router";
|
import { useNavigate } from "@solidjs/router";
|
||||||
import { Button } from "@/src/components/button";
|
import { Button } from "@/src/components/button";
|
||||||
@@ -61,6 +61,17 @@ export const CreateClan = () => {
|
|||||||
toast.error("Failed to create clan");
|
toast.error("Failed to create clan");
|
||||||
return;
|
return;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
// Will generate a key if it doesn't exist, and add a user to the clan
|
||||||
|
const k = await callApi("keygen", {
|
||||||
|
flake_dir: target_dir[0],
|
||||||
|
});
|
||||||
|
|
||||||
|
if (k.status === "error") {
|
||||||
|
toast.error("Failed to generate key");
|
||||||
|
return;
|
||||||
|
}
|
||||||
|
|
||||||
if (r.status === "success") {
|
if (r.status === "success") {
|
||||||
toast.success("Clan Successfully Created");
|
toast.success("Clan Successfully Created");
|
||||||
setActiveURI(target_dir[0]);
|
setActiveURI(target_dir[0]);
|
||||||
|
|||||||
Reference in New Issue
Block a user