From 5b9baa9171f35872ab040b429c5ac5b1b6f74140 Mon Sep 17 00:00:00 2001 From: Igor Soarez Date: Sun, 22 Nov 2026 07:19:58 +0000 Subject: szecret list: a bucket's store keys show at a terminal as one stores line, counted apart from its secrets; --names, --json and piped list unchanged --- secrets/list.sh | 48 +++++++++++++++++++++++++++++++++++++----------- 1 file changed, 37 insertions(+), 11 deletions(-) (limited to 'secrets/list.sh') diff --git a/secrets/list.sh b/secrets/list.sh index 3f5f56a..52c683e 100755 --- a/secrets/list.sh +++ b/secrets/list.sh @@ -15,6 +15,10 @@ Usage: list --names /, one a line list -h|--help +A bucket's store keys (local-key-, the keys of szecret local stores) +show at a terminal as one "stores:" line naming the stores; --names, --json +and piped list name them as the files they are. + Only names, never values; nothing is decrypted. Piped, plain "list" prints bare names, one a line, sorted (SZECRET_FORCE_TTY=1, or =, gives the terminal view instead). The old store counts as readable while the old key @@ -194,6 +198,15 @@ function bold(s) { return c("1", s) } function dim(s) { return c("2", s) } function warn(s) { return c("33", s) } function plural(n, one, many) { return n " " (n == 1 ? one : many) } +# A store's key (local-key-) is how a bucket's readers open that store, +# not a secret anyone uses: shown as the store's name, apart from the secrets. +function is_store(s) { return index(s, "local-key-") == 1 && length(s) > 10 } +function count_stores(b, i, n) { n = 0; for (i = 1; i <= NS[b]; i++) if (is_store(SEC[b, i])) n++; return n } +# "3 secrets, 1 store", either part left out at 0; "empty" with neither. +function contents(nsec, nst) { + if (nsec == 0 && nst == 0) return "empty" + return (nsec > 0 ? plural(nsec, "secret", "secrets") : "") (nsec > 0 && nst > 0 ? ", " : "") (nst > 0 ? plural(nst, "store", "stores") : "") +} function isort(arr, n, i, j, t) { for (i = 2; i <= n; i++) { t = arr[i] @@ -341,8 +354,9 @@ function wrap_list(prefix, n, arr, indent, i, line, out, item, sep) { # grid(b): the bucket's secrets in columns, filled downwards as ls does, as # many as fit in W. function grid(b, n, i, cols, rows, w, col, total, best, r, line, s, pad) { - n = NS[b] - for (i = 1; i <= n; i++) G[i] = SEC[b, i] + n = 0 + for (i = 1; i <= NS[b]; i++) if (!is_store(SEC[b, i])) G[++n] = SEC[b, i] + if (n == 0) return isort(G, n) best = 1 for (cols = n; cols > 1; cols--) { @@ -374,8 +388,9 @@ function grid(b, n, i, cols, rows, w, col, total, best, r, line, s, pad) { } } -function show_bucket(b, i, n, k, R, nadm, hosts, rl, readers, j) { - print bold(LABEL[b]) " " dim(NS[b] == 0 ? "empty" : plural(NS[b], "secret", "secrets")) +function show_bucket(b, i, n, k, R, nadm, hosts, rl, readers, j, nst, ST) { + nst = count_stores(b) + print bold(LABEL[b]) " " dim(contents(NS[b] - nst, nst)) if (OLD[b]) { print dim(" read with the old key") } else if (keys) { @@ -400,7 +415,13 @@ function show_bucket(b, i, n, k, R, nadm, hosts, rl, readers, j) { print warn(" ! " PMSG[b, i]) if (PFIX[b, i] != "") print " " dim("fix:") " " PFIX[b, i] } - if (NS[b] > 0) grid(b) + if (nst > 0) { + n = 0 + for (i = 1; i <= NS[b]; i++) if (is_store(SEC[b, i])) ST[++n] = substr(SEC[b, i], 11) + isort(ST, n) + print wrap_list(" stores:", n, ST, " ") + } + if (NS[b] > nst) grid(b) } # machine(): this machine's name, as the buckets' readers name its key. @@ -411,11 +432,12 @@ function machine( k, b, me) { return me } -function human( b, nread, nsec, nall, nsecall, nother, probs, pl, me, i, A, n, an) { - nread = 0; nsec = 0; nall = 0; nsecall = 0; probs = 0; pl = "" +function human( b, nread, nsec, nall, nsecall, nother, probs, pl, me, i, A, n, an, nst, nstall, ns, line, tail) { + nread = 0; nsec = 0; nall = 0; nsecall = 0; probs = 0; pl = ""; nst = 0; nstall = 0 for (b = 1; b <= nb; b++) { - nall++; nsecall += NS[b] - if (READABLE[b]) { nread++; nsec += NS[b] } + ns = count_stores(b) + nall++; nsecall += NS[b] - ns; nstall += ns + if (READABLE[b]) { nread++; nsec += NS[b] - ns; nst += ns } if ((READABLE[b] || all) && NP[b] > 0) { probs += NP[b]; pl = pl (pl == "" ? "" : ", ") LABEL[b] } } me = machine() @@ -455,8 +477,12 @@ function human( b, nread, nsec, nall, nsecall, nother, probs, pl, me, i, A, n print "" if (me == "") me = "This machine" - if (all) print me " reads " nread " of " plural(nall, "bucket", "buckets") ", " nsec " of " plural(nsecall, "secret", "secrets") - else print me " reads " plural(nread, "bucket", "buckets") ", " plural(nsec, "secret", "secrets") + if (all) { line = me " reads " nread " of " plural(nall, "bucket", "buckets") ", " nsec " of " plural(nsecall, "secret", "secrets"); tail = nstall > 0 ? nst " of " plural(nstall, "store", "stores") : "" } + else { line = me " reads " plural(nread, "bucket", "buckets") ", " plural(nsec, "secret", "secrets"); tail = nst > 0 ? plural(nst, "store", "stores") : "" } + # The stores on a line of their own when the whole would not fit. + if (tail == "") print line + else if (length(line ", " tail) <= W) print line ", " tail + else { print line ","; print " " tail } if (admins_known) { an = 0 for (k in ADMIN) A[++an] = (k in ADMIN_NAME) ? ADMIN_NAME[k] : "unnamed admin" -- cgit v1.2.3