-
Notifications
You must be signed in to change notification settings - Fork 0
/
token_script.sh
executable file
·29 lines (19 loc) · 1.09 KB
/
token_script.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
#!/bin/bash
echo ""
read -p "Username: " USER
read -s -p "Password: " PASSWORD
echo ""
RESP=`curl -s -d "{\"auth\": {\"passwordCredentials\": {\"username\":\"$USER\", \"password\":\"$PASSWORD\"}}}" -H"Content-type: application/json" http://cloud.lab.fi-ware.org:4730/v2.0/tokens`
TOKEN=`echo $RESP | sed "s/{\"access\":{\"token\":{.*\"id\":\"\(.*\)\"},\"user.*$/\1/g"`
echo -e "\nAccess Token: $TOKEN"
ORGS=`curl -s -H"x-auth-token: $TOKEN" http://cloud.lab.fi-ware.org:4730/v2.0/tenants`
echo -e "\nOrganizations: "
set ORGS2=$ORGS
echo $ORGS | awk -v k="text" '{printf("%-32s %s \n", "ID", "Name"); n=split($0,a,"[{}]"); for (i=1; i<=n; i++) {m=split(a[i], b, "[,:\"]"); if (m>=15) printf("%-32s %s \n", b[9], b[15])}}'
echo ""
read -p "Select an organization from the list above (ID): " ORG
BODY='{"auth": {"token":{"id": "'$TOKEN'"}, "tenantId": "'$ORG'"}}'
RESP1=`curl -s -X POST -H "Content-Type: application/json" -d "$BODY" http://cloud.lab.fi-ware.org:4730/v2.0/tokens`
TOKEN=`echo $RESP1 | sed "s/{\"access\":{\"token\":{.*\"id\":\"\(.*\)\",\"tenant.*$/\1/g"`
echo -e "\nToken: $TOKEN"
echo ""