clan-cli/secrets: update some error message in encrypt_secret

Found that while reading through some code.
This commit is contained in:
Louis Opter
2025-09-22 00:47:27 +00:00
committed by Jörg Thalheim
parent bd361b2744
commit 25ce97dd5e

View File

@@ -27,7 +27,7 @@ from .sops import (
read_keys, read_keys,
update_keys, update_keys,
) )
from .types import VALID_SECRET_NAME, secret_name_type from .types import VALID_SECRET_NAME, VALID_USER_NAME, secret_name_type
log = logging.getLogger(__name__) log = logging.getLogger(__name__)
@@ -158,8 +158,32 @@ def encrypt_secret(
admin_keys = sops.ensure_admin_public_keys(flake_dir) admin_keys = sops.ensure_admin_public_keys(flake_dir)
if not admin_keys: if not admin_keys:
# TODO double check the correct command to run users = list_objects(
msg = "No keys found. Please run 'clan secrets add-key' to add a key." sops_users_folder(flake_dir),
is_valid=lambda name: VALID_USER_NAME.match(name) is not None,
)
msg = (
"No admin keys found.\n\n"
"Please run 'clan secrets key generate' to create a key. "
)
if (count := len(users)) > 1:
msg += (
f"Then run 'clan secrets users add-key' "
f"to add the key to an user you already have "
f"({', '.join(users)}), or use 'clan secrets users add' "
f"to create a new user with the new key."
)
elif count == 1:
msg += (
f"Then run 'clan secrets users add-key {users[0]}' "
f"to add the key to the user you already have, or use "
f"'clan secrets users add' to create a new user "
f"with the new key."
)
else:
msg += (
"Then run 'clan secrets users add' to associate the key with an user."
)
raise ClanError(msg) raise ClanError(msg)
username = next(iter(admin_keys)).username username = next(iter(admin_keys)).username