-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathauth.sh
executable file
·32 lines (27 loc) · 1.01 KB
/
auth.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
#!/bin/sh
#
# Matt Jones 2013
#
# Authenticate using the credentials in a the provided file
# Usage: ./auth.sh
TMP=auth-response.xml
CRED=credentials
. ./$CRED
# Delete any existing TOKENs
sed -e '/TOKEN=/ d' $CRED > ${CRED}2 && mv ${CRED}2 $CRED
# Delete any existing TENANTS
sed -e '/TENANT=/ d' $CRED > ${CRED}2 && mv ${CRED}2 $CRED
curl -s -d \
"<?xml version=\"1.0\" encoding=\"UTF-8\"?>
<auth>
<apiKeyCredentials
xmlns=\"http://docs.rackspace.com/identity/api/ext/RAX-KSKEY/v1.0\"
username=\"$UNAME\"
apiKey=\"$APIKEY\"/>
</auth>" \
-H 'Content-Type: application/xml' \
-H 'Accept: application/xml' \
'https://identity.api.rackspacecloud.com/v2.0/tokens' | xmlstarlet fo > $TMP
xmlstarlet sel -N mns=http://docs.openstack.org/identity/api/v2.0 -T -t -m "/mns:access/mns:token" -v "concat('TOKEN=',@id)" --nl $TMP >> ./$CRED
xmlstarlet sel -N mns=http://docs.openstack.org/identity/api/v2.0 -T -t -m "/mns:access/mns:token/mns:tenant" -v "concat('TENANT=',@id)" --nl $TMP >> ./$CRED
rm $TMP