diff --git a/bin/k-show-secrets b/bin/k-show-secrets new file mode 100755 index 0000000..cdee002 --- /dev/null +++ b/bin/k-show-secrets @@ -0,0 +1,30 @@ +#!/bin/bash + +# Get the current namespace from the current kubectl context +NAMESPACE=$(kubectl config view --minify --output 'jsonpath={..namespace}') +NAMESPACE=${NAMESPACE:-default} + +# Fetch all secret names in the current namespace +secrets=$(kubectl get secrets -n "$NAMESPACE" -o jsonpath="{.items[*].metadata.name}") + +if [ -z "$secrets" ]; then + echo "❌ No secrets found in namespace '$NAMESPACE'." + exit 1 +fi + +# Use fzf for interactive secret selection +SELECTED_SECRET=$(echo "$secrets" | tr ' ' '\n' | fzf --prompt="🔐 Select a secret: ") + +# Check if a selection was made +if [ -z "$SELECTED_SECRET" ]; then + echo "🚫 No secret selected." + exit 1 +fi + +echo +echo "🔓 Decoding secret '$SELECTED_SECRET' in namespace '$NAMESPACE'..." +echo + +# Decode and display the secret data +kubectl get secret "$SELECTED_SECRET" -n "$NAMESPACE" -o json | \ + jq -r '.data | to_entries[] | "\(.key): \(.value | @base64d)"'