-
Notifications
You must be signed in to change notification settings - Fork 4
/
ofcirtokens.sh
executable file
·59 lines (52 loc) · 1.31 KB
/
ofcirtokens.sh
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
#!/bin/bash
set -f
function usage(){
cat << EOF
$0 list
List all tokens and their pools
$0 new [-p pools] [-t token]
Create a new token
-p POOLS
new token will allow access to POOLS (comma seperated)
-t TOKEN
new token will copy pools from TOKEN
$0 update TOKEN POOLS
Update TOKEN with POOLS
$0 delete TOKEN
Delete TOKEN
EOF
exit 1
}
function list(){
oc get secret/ofcir-tokens -o json | jq -r '.data | keys[] as $k | "\($k) \(.[$k])"' |
while read TOKEN POOL ; do
printf "%36s %s\n" $TOKEN $(echo $POOL | base64 -d)
done |
sort
}
function new(){
while getopts "p:t:" O ; do
case $O in
p) POOLS=$OPTARG
POOLS=$(echo -n $POOLS | base64 -w 0)
;;
t) POOLS=$(oc get secret/ofcir-tokens -o json | jq -r ".data[\"$OPTARG\"]")
;;
*) usage
;;
esac
done
TOKEN=$(uuidgen)
oc patch secret/ofcir-tokens --patch "{\"data\":{\"$TOKEN\":\"$POOLS\"}}"
}
function update(){
POOLS=$(echo -n $2 | base64 -w 0)
oc patch secret/ofcir-tokens --patch "{\"data\":{\"$1\":\"$POOLS\"}}"
}
function delete(){
oc patch secret/ofcir-tokens --type=json -p="[{\"op\": \"remove\", \"path\":\"/data/$1\"}]"
}
CMD=$1
[ -z "$CMD" ] && usage
shift
$CMD $@