k-show-secrets added
This commit is contained in:
30
bin/k-show-secrets
Executable file
30
bin/k-show-secrets
Executable file
@@ -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)"'
|
||||
Reference in New Issue
Block a user