File tree 1 file changed +28
-5
lines changed
1 file changed +28
-5
lines changed Original file line number Diff line number Diff line change 1
1
#! /bin/bash
2
2
3
+ function usage(){
4
+ echo -e " usage: ${0} SECRET [NAMESPACE]\n"
5
+ echo -e " SECRET The secret to decode"
6
+ echo -e " NAMESPACE The namespace to retrieve the secret from (optional,"
7
+ echo -e " defaults to the namespace of the current context)."
8
+ }
9
+
10
+ if [ " ${1} " == " -h" ]; then
11
+ usage
12
+ exit
13
+ fi
14
+
15
+ if [[ -z " ${1// } " ]]; then
16
+ echo " ERROR: No secret set."
17
+ usage
18
+ exit 1
19
+ fi
3
20
SECRET=" $1 "
4
- NAMESPACE=" $2 "
5
21
6
- for row in $( echo $( kubectl get secret $SECRET -o json -n $NAMESPACE ) | jq -c ' .data | to_entries[]' ) ; do
7
- KEY=$( echo $row | jq -r ' .key' )
8
- DECODED=$( echo $row | jq -r ' .value' | base64 --decode)
9
- echo $KEY : $DECODED
22
+ if [[ -z " ${2// } " ]]; then
23
+ NAMESPACE=$( kubectl config get-contexts --no-headers | tr -s ' ' | cut -d ' ' -f5)
24
+ echo " No namespace set, using default: ${NAMESPACE} "
25
+ else
26
+ NAMESPACE=" $2 "
27
+ fi
28
+
29
+ for row in $( kubectl get secret " ${SECRET} " -o json -n " ${NAMESPACE} " | jq -c ' .data | to_entries[]' ) ; do
30
+ KEY=$( echo " ${row} " | jq -r ' .key' )
31
+ DECODED=$( echo " ${row} " | jq -r ' .value' | base64 --decode)
32
+ echo " ${KEY} : ${DECODED} "
10
33
done
You can’t perform that action at this time.
0 commit comments