These scripts encode-decode yaml files, e.g. from
secret:
greeting: aGVsbG8=
using ksd test.yaml
it will overwrite the file contents to
secret:
greeting: hello
using kse test.yaml
will convert it back.
Prerequisites:
Place this code into your .bash_profile
or .zshrc
or into the rc file of your terminal of choice.
function ksd() {
file=$1
if [ -z "$file" ]; then
echo "decodes base64 string in kubernetes secrets like file"
echo
echo "Usage: $0 <file>"
echo
return 1
fi
yq -y -i '.secret[] |= @base64d' $file
}
function kse() {
file=$1
if [ -z "$file" ]; then
echo "encodes strings to base64 in kubernetes config map like file"
echo
echo "Usage: $0 <file>"
echo
return 1
fi
yq -y -i '.secret[] |= @base64' $file
}