-
Notifications
You must be signed in to change notification settings - Fork 4
Expand file tree
/
Copy pathcreate-service-account.sh
More file actions
executable file
·116 lines (92 loc) · 2.93 KB
/
create-service-account.sh
File metadata and controls
executable file
·116 lines (92 loc) · 2.93 KB
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
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
set -e
#############################################################################################
#
# This script will verify that you can create and delete an OpenShift Application Services service account,
# using the RHOAS CLI and OpenShift Streams API by performing the following actions:
#
# - Login to the rhoas CLI and OpenShift Streams Control Plane usig the provided credentials
# - Create a Service Account with the given name.
# - Verify that the Service Account exists by retrieving the service account information.
# - Delete the Service Account.
#
#############################################################################################
# Source function library.
if [ -f /etc/init.d/functions ]
then
. /etc/init.d/functions
fi
################################################ Parse input parameters #############################################
function usage {
echo "\n"
echo "Usage: create-service-account.sh [args...]"
echo "where args include:"
echo " -s The name of the service account to be created."
echo " -o Offline authentication token. Browser based login will be used if not specified."
}
#Parse the params
while getopts ":s:o:h" opt; do
case $opt in
s)
SERVICE_ACCOUNT_NAME=$OPTARG
;;
o)
OFFLINE_TOKEN=$OPTARG
;;
h)
usage
exit 0
;;
\?)
echo "Invalid option: -$OPTARG" >&2
exit 1
;;
:)
echo "Option -$OPTARG requires an argument." >&2
exit 1
;;
esac
done
PARAMS_NOT_OK=false
#Check params
if [ -z "$SERVICE_ACCOUNT_NAME" ]
then
echo "No Service Account name specified!"
PARAMS_NOT_OK=true
fi
if $PARAMS_NOT_OK
then
usage
exit 1
fi
################################################ Setup params. #############################################
#Load kafka functions.
source ./kafka.sh
################################################ Run topic creation health check. #############################################
startHealthCheck
checkRhoasCliAvailable
login $OFFLINE_TOKEN
createServiceAccount $SERVICE_ACCOUNT_NAME
echo "Waiting for service account to be created."
sleep 5
echo "Client ID of the new Service Account: $CLIENT_ID"
getServiceAccountIdByClientId $CLIENT_ID
# Check that SERVICE_ACCOUNT is not empty
if [ -z "$SERVICE_ACCOUNT_ID" ]
then
echo "No SERVICE_ACCOUNT id set. Service Acccount not found. Unable to perform operations on the given Service Account."
ERROR_CODE=1
else
#deleteServiceAccount $SERVICE_ACCOUNT
echo "Service Account ID of the new Service Account: $SERVICE_ACCOUNT_ID"
fi
echo "Service Account succesfully created!"
echo "Cleaning up Service Account."
deleteServiceAccount $SERVICE_ACCOUNT_ID
echo "Clean up service account environment variable file."
rm sa.env
if [-n "$ERROR_CODE" ]
then
echo "Errror while running healthcheck."
exit $ERROR_CODE
fi
completeHealthCheck