From 8440c6816f833e9848bbfd976902af46f49d6ff3 Mon Sep 17 00:00:00 2001 From: Igor Soarez Date: Fri, 20 Nov 2026 10:51:00 +0000 Subject: szecret list: a terminal view worth reading, and --json At a terminal, list shows each bucket this machine reads: its readers by name (hosts from recipients, admins from a "# " line above their key in SZECRET_ADMINS_COMMAND's output, "the admins" once per bucket), its secrets in columns fitted to the width, any problem the file names and headers show with the command that fixes it, and a summary. No key is shown without --keys or --json. --all groups the buckets not read here after the rest. It reads every bucket in one awk pass, never decrypting. Piped output and --names, which scripts read, are unchanged. --- secrets/common.sh | 27 +++++++++++++++++++++++---- 1 file changed, 23 insertions(+), 4 deletions(-) (limited to 'secrets/common.sh') diff --git a/secrets/common.sh b/secrets/common.sh index 13fe749..adf5488 100644 --- a/secrets/common.sh +++ b/secrets/common.sh @@ -380,17 +380,36 @@ bucket_label() { fi } -# admin_keys: the admins, one a line. With none it fails and says why. -admin_keys() { - local out +# admins_output: what SZECRET_ADMINS_COMMAND prints. With no command, or a +# failed one, it fails and says why. +admins_output() { if [[ -z "${SZECRET_ADMINS_COMMAND:-}" ]]; then >&2 echo "ERROR: no admins: SZECRET_ADMINS_COMMAND is not set, and nothing is encrypted without them" return 1 fi - if ! out="$(bash -c "${SZECRET_ADMINS_COMMAND}" &2 echo "ERROR: no admins: '${SZECRET_ADMINS_COMMAND}' failed, and nothing is encrypted without them" return 1 fi +} + +# admin_names : " " for each admin key a "# " +# comment line names, the last comment above it as in a recipients file. Only +# list uses the names; encryption reads the key lines alone. +admin_names() { + awk '/^[[:space:]]*#/ { sub(/^[[:space:]]*#[[:space:]]*/, ""); name = $0; next } + /^age1[0-9a-z]+$/ { if (name != "") print $1, name; name = "" }' <<<"$1" +} + +# admin_keys []: the admins, one a line. With none it fails and +# says why. +admin_keys() { + local out + if [[ $# -gt 0 ]]; then + out="$1" + else + out="$(admins_output)" || return 1 + fi out="$(grep -E '^age1[0-9a-z]+$' <<<"${out}" | sorted || true)" if [[ -z "${out}" ]]; then >&2 echo "ERROR: no admins: '${SZECRET_ADMINS_COMMAND}' printed none, and nothing is encrypted without them" -- cgit v1.2.3