forked from dell-powerflex/scaleio-flex
-
Notifications
You must be signed in to change notification settings - Fork 1
/
Copy pathget-token.sh.sample
executable file
·33 lines (27 loc) · 1.04 KB
/
get-token.sh.sample
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
#!/bin/sh
#
# ScaleIO FlexVolume utility for obtaining token
#
# Do not modify thist script, configuration settings can be found at
# /opt/emc/scaleio/flexvolume/cfg/config
# Set SERVICE_ACC to desired/existing service account; KUBECONFIG needs to have permissions to get secret/ticket from SERVICE_ACC
SERVICE_ACC=scaleio-flex-volume
CONFIGFILE="/opt/emc/scaleio/flexvolume/cfg/config"
if [ -f "${CONFIGFILE}" ]; then
# source the config file
source "${CONFIGFILE}"
fi
# in case some values were not specific in the config file, set their values
KUBECONFIG="${KUBECONFIG:-/root/.kube/config}"
WHICH_OC=$(which oc > /dev/null 2>&1)
WHICH_OC_RETURN=$(echo $?)
if [ "${WHICH_OC_RETURN}" = "0" ]; then
CMD="oc"
CONFIG_OPTION="--config"
else
CMD="kubectl"
CONFIG_OPTION="--kubeconfig"
fi
secret=$(${CMD} ${CONFIG_OPTION}=${KUBECONFIG} get sa ${SERVICE_ACC} --template='{{range .secrets}}{{.name}}{{"\n"}}{{end}}' | grep token)
token=$(${CMD} ${CONFIG_OPTION}=${KUBECONFIG} get secret ${secret} --template='{{ .data.token}}' | base64 -d)
echo -n ${token}