-
Notifications
You must be signed in to change notification settings - Fork 3
Expand file tree
/
Copy path060-admin-access-import.sh
More file actions
executable file
·42 lines (34 loc) · 1.34 KB
/
060-admin-access-import.sh
File metadata and controls
executable file
·42 lines (34 loc) · 1.34 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
#!/bin/bash
# Resource: Access (Under Administration)
SCRIPT_DIR="$( cd "$( dirname "${BASH_SOURCE[0]}" )" &> /dev/null && pwd )"
source "$SCRIPT_DIR"/utils/sm-api-call.sh
DATA_DIR="$SCRIPT_DIR"/data/credential-access
if [ ! -d $DATA_DIR ]; then
echo "Nothing to do without directory $DATA_DIR, please backup data first"
exit 0
fi
echo "************************************************************************"
echo "* Importing Admin Access into TMC SM ..."
echo "************************************************************************"
for file in $DATA_DIR/*; do
if [ -f "$file" ]; then
filename=`basename $file .yaml`
echo "Start to check $filename"
result=($(echo "$filename" | awk -F'---' '{print $1,$2}'))
policyListLen=`cat "$file" | yq eval -o=json - | jq '.policyList | length'`
if [ "$policyListLen" = "1" ]; then
echo "Ignore built-in role $filename"
fi
if [ "$policyListLen" != "1" ]; then
echo "Start to create $filename"
roleBindings=`cat "$file" | yq eval -o=json - | \
jq -c '.policyList[0]' | jq -c 'del(.meta)'`
curl_api_call -X PUT -d "$roleBindings" \
"v1alpha1/account/credentials:iam/${result[1]}"
if [ $? -eq 0 ]; then
echo "Successfully created role binding for credential $file"
fi
fi
fi
done
echo "Imported Admin Access into TMC SM ..."