From 9a1c781d289ea44e019fc17472c9d8289e620f1e Mon Sep 17 00:00:00 2001 From: Nikolai Kondrashov Date: Fri, 19 Jan 2024 15:25:32 +0200 Subject: [PATCH] cloud: Add password_secret_exists() --- kcidb/cloud/password.sh | 24 ++++++++++++++++++++++++ 1 file changed, 24 insertions(+) diff --git a/kcidb/cloud/password.sh b/kcidb/cloud/password.sh index d69d24de..0daa2eb6 100644 --- a/kcidb/cloud/password.sh +++ b/kcidb/cloud/password.sh @@ -177,6 +177,30 @@ function password_secret_is_specified() { return 0 } +# Check if every specified password's secret exists. +# Assumes every specified password is known/exists and has its secret set. +# Args: name... +# Output: "true" if all secrets exists, "false" otherwise. +function password_secret_exists() { + declare name + declare project + declare secret + declare exists + assert password_exists "$@" + assert password_secret_is_specified "$@" + while (($#)); do + name="$1"; shift + project="${PASSWORD_SECRETS[$name]%%:*}" + secret="${PASSWORD_SECRETS[$name]#*:}" + exists=$(secret_exists "$project" "$secret") + if ! "$exists"; then + echo false + return + fi + done + echo true +} + # Specify the single-word command returning exit status specifying if the # password with specified name could be auto-generated or not. # Args: name generate