Last active
April 27, 2023 03:56
-
-
Save nasermirzaei89/27cab414ed6f2c2aa35688a653e399a9 to your computer and use it in GitHub Desktop.
Get decoded secret as yaml
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
#!/bin/bash | |
set -e | |
NAMESPACE=$1 | |
SECRET_NAME=$2 | |
CONTENT=$(kubectl get secret -n "$NAMESPACE" "$SECRET_NAME" -o json) | |
KEYS=$(echo "${CONTENT}" | jq '.data' | jq 'keys[]') | |
for KEY in $KEYS | |
do | |
DECODED=$(echo "$CONTENT" | jq -r ".data.${KEY}" | base64 -d) | |
CONTENT=$(echo "$CONTENT" | jq ".stringData.${KEY} = \"${DECODED}\"") | |
done | |
echo "${CONTENT}" | jq 'del(.data)' | yq eval -P |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Prerequisites
Usage