Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Add usage & guards #1

Merged
merged 3 commits into from
Feb 12, 2018
Merged
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
33 changes: 28 additions & 5 deletions bin/kubedecode
Original file line number Diff line number Diff line change
@@ -1,10 +1,33 @@
#!/bin/bash

function usage(){
echo -e "usage: ${0} SECRET [NAMESPACE]\n"
echo -e "SECRET The secret to decode"
echo -e "NAMESPACE The namespace to retrieve the secret from (optional,"
echo -e " defaults to the namespace of the current context)."
}

if [ "${1}" == "-h" ]; then
usage
exit
fi

if [[ -z "${1// }" ]]; then
echo "ERROR: No secret set."
usage
exit 1
fi
SECRET="$1"
NAMESPACE="$2"

for row in $(echo $(kubectl get secret $SECRET -o json -n $NAMESPACE) | jq -c '.data | to_entries[]'); do
KEY=$(echo $row | jq -r '.key')
DECODED=$(echo $row | jq -r '.value' | base64 --decode)
echo $KEY: $DECODED
if [[ -z "${2// }" ]]; then
NAMESPACE=$(kubectl config get-contexts --no-headers | tr -s ' ' | cut -d ' ' -f5)
echo "No namespace set, using default: ${NAMESPACE}"
else
NAMESPACE="$2"
fi

for row in $(kubectl get secret "${SECRET}" -o json -n "${NAMESPACE}" | jq -c '.data | to_entries[]'); do
KEY=$(echo "${row}" | jq -r '.key')
DECODED=$(echo "${row}" | jq -r '.value' | base64 --decode)
echo "${KEY}: ${DECODED}"
done