-
Notifications
You must be signed in to change notification settings - Fork 0
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
- Loading branch information
Showing
3 changed files
with
60 additions
and
28 deletions.
There are no files selected for viewing
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
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
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
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,34 +1,38 @@ | ||
#!/usr/bin/env bash | ||
|
||
print_help() { | ||
echo "Usage: $(basename "$0") <secret_name> <namespace>" | ||
echo " <secret_name> Name of the secret to decode" | ||
echo " <namespace> Namespace of the secret (optional)" | ||
cat << EOF | ||
Usage: $(basename "$0") <secret_name> <namespace> | ||
<secret_name> Name of the secret to decode | ||
<namespace> Namespace of the secret (optional) | ||
Examples: | ||
$(basename "$0") my-secret # Decode the 'my-secret' secret in the current namespace | ||
$(basename "$0") my-secret my-ns # Decode the 'my-secret' secret in the 'my-ns' namespace | ||
EOF | ||
} | ||
|
||
parse_args() { | ||
secret_name=$1 | ||
|
||
if [ $# -eq 2 ]; then | ||
namespace=$2 | ||
set_namespace() { | ||
if [ $# -eq 1 ]; then | ||
namespace=$1 | ||
else | ||
namespace=$(kubectl config view --minify -o jsonpath='{..namespace}') | ||
namespace=$(kubectl config view --minify -o jsonpath='{..namespace}') || { echo "Error: Unable to get current namespace"; exit 1; } | ||
echo "No namespace specified, using currently selected namespace: $namespace" | ||
fi | ||
} | ||
|
||
main() { | ||
local secret | ||
local secret_name=$1 | ||
local secret_content | ||
|
||
if [ "$1" == "-h" ] || [ "$1" == "--help" ] || [ $# -lt 1 ]; then | ||
print_help | ||
exit 0 | ||
fi | ||
case $secret_name in | ||
-h|--help|"") print_help; exit 0;; | ||
esac | ||
|
||
parse_args "$@" | ||
set_namespace "$2" | ||
|
||
secret=$(kubectl get secret "$secret_name" -n "$namespace" -o yaml) | ||
echo "$secret" | yq e '.data | to_entries | .[] | .key + ": " + (.value | @base64d)' | ||
secret_content=$(kubectl get secret "$secret_name" -n "$namespace" -o yaml) || { echo "Error: Unable to get secret $secret_name in namespace $namespace"; exit 1; } | ||
echo "$secret_content" | yq e '.data | to_entries | .[] | .key + ": " + (.value | @base64d)' | ||
} | ||
|
||
main "$@" |