summaryrefslogtreecommitdiff
path: root/secrets/common.sh
diff options
context:
space:
mode:
authorIgor Soarez <igor@soarez.org>2026-11-20 10:51:00 +0000
committerIgor Soarez <igor@soarez.org>2026-11-20 10:57:22 +0000
commit8440c6816f833e9848bbfd976902af46f49d6ff3 (patch)
tree2f44413e84251bde824b7c6c31ea46b1f9def446 /secrets/common.sh
parentfcf5c24b66a013672a6d9dcac7ab09b813b4f5c7 (diff)
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 "# <name>" 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.
Diffstat (limited to 'secrets/common.sh')
-rw-r--r--secrets/common.sh27
1 files changed, 23 insertions, 4 deletions
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}" </dev/null)"; then
+ if ! bash -c "${SZECRET_ADMINS_COMMAND}" </dev/null; then
>&2 echo "ERROR: no admins: '${SZECRET_ADMINS_COMMAND}' failed, and nothing is encrypted without them"
return 1
fi
+}
+
+# admin_names <admins output>: "<key> <name>" for each admin key a "# <name>"
+# 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 [<admins output>]: 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"