diff options
Diffstat (limited to 'secrets/common.sh')
| -rw-r--r-- | secrets/common.sh | 27 |
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" |
