diff --git a/k b/k index 534d851..883a68f 100755 --- a/k +++ b/k @@ -180,6 +180,7 @@ def print_commands puts "k secrets []" + gray(" lists secrets including usage details") puts "k secrets:create " + gray(" create a new secret") puts "k secrets:edit " + gray(" edit a secret") + puts "k secrets:get " + gray(" get a single secret value") puts "k secrets:set = [= ...]" + gray(" set new secret values") puts "k secrets:unset [ ...]" + gray(" unset / delete secret values") puts "k update" + gray(" update k to the latest version") @@ -1692,6 +1693,31 @@ def secrets_edit end end +def secrets_get + if ARGV.length != 2 + puts "Usage: k secrets:get " + exit + end + + shared_secret = ARGV.delete_at(0) + key = ARGV.delete_at(0) + + in_argo_repo do + secret_path = "applications/shared-secrets/#{shared_secret}.yaml" + abort "No shared secret found at '#{secret_path}'" unless File.exist?(secret_path) + + kubernetes_secret = YAML.safe_load read_kubectl("get secret #{shared_secret} -o yaml") + secret = kubernetes_secret["data"] + + abort "Error: key '#{key}' not found in secret '#{shared_secret}'" unless secret + + require "base64" + + value = Base64.strict_decode64(secret[key]) + puts value + end +end + def secrets_set if ARGV.length < 2 puts "Usage: k secrets:set = [= ...]"