From 2914c5f444e9304691141acacae73aac533cc60a Mon Sep 17 00:00:00 2001 From: Nikolai Rodionov Date: Tue, 26 Mar 2024 10:07:38 +0100 Subject: [PATCH] When a secret entry is provided, print only value --- kubers | 16 ++++++++++++---- 1 file changed, 12 insertions(+), 4 deletions(-) diff --git a/kubers b/kubers index f2821a5..6d9eee0 100755 --- a/kubers +++ b/kubers @@ -11,13 +11,21 @@ KUBERS_VERSION=0.1.0 function append_to_secret() { SECRET=$1 KEY=$2 + QUIET=$3 VALUE=$(kubectl -n $NAMESPACE get secret $SECRET -o yaml| yq ".data.\"$KEY\"" | base64 -d) + SECRET_DATA="test" if (( $(grep -c . <<<"$VALUE") > 1 )); then - SECRET="$KEY: |-\n$(echo $VALUE| sed -e 's/^/ /')" + SECRET_DATA="|-\n$(echo $VALUE| sed -e 's/^/ /')" + SECRET="$KEY: $SECRET_DATA" else - SECRET="$KEY: $VALUE" + SECRET_DATA="$VALUE" + SECRET="$KEY: $SECRET_DATA" + fi + if [[ $QUIET != "" ]]; then + printf "$SECRET_DATA" + else + printf "$SECRET" fi - printf "$SECRET" } function show_help() { @@ -104,7 +112,7 @@ fi SECRET=() if [[ $SECRET_ENTRY != "" ]]; then - SECRET+=$(append_to_secret $SECRET_NAME $SECRET_ENTRY) + SECRET+=$(append_to_secret $SECRET_NAME $SECRET_ENTRY 1) else for SECRET_ENTRY in $(kubectl -n $NAMESPACE get secret $SECRET_NAME -o yaml | yq '.data | keys' | sed -e "s/- //"); do SECRET+=("$(append_to_secret $SECRET_NAME $SECRET_ENTRY)");