Navigation Menu

Skip to content

Instantly share code, notes, and snippets.

@vishvananda
Forked from anonymous/gist:1250936
Created September 30, 2011 08:38
Show Gist options
  • Star 1 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save vishvananda/1253118 to your computer and use it in GitHub Desktop.
Save vishvananda/1253118 to your computer and use it in GitHub Desktop.
#!/usr/bin/env bash
ENDPOINT_TYPE=${3:-$ENDPOINT_TYPE}
KEYSTONE_HOST=${4:-$KEYSTONE_HOST}
function die {
echo $1
echo "usage: $0 <username> <password>" \
"<type=\$ENDPOINT_TYPE> <host=\$KEYSTONE_HOST>"
exit 1
}
if [ "$1" == "" ]; then
die "username is required"
fi
if [ "$2" == "" ]; then
die "password is required"
fi
if [ "$ENDPOINT_TYPE" == "" ]; then
die "type is required"
fi
if [ "$KEYSTONE_HOST" == "" ]; then
die "host is required"
fi
RES=$(curl -s -d "{\"auth\": {\"passwordCredentials\":
{\"username\": \"$1\", \"password\": \"$2\"}}}" \
-H "Content-type: application/json" \
http://$KEYSTONE_HOST:5000/v2.0/tokens)
SED=$(echo "s/.*\"publicURL\":.*http:\/\/\([^:]*\).*" \
"\"type\":[^}]*\"$ENDPOINT_TYPE\".*/\1/g")
HOST=$(echo $RES | sed "$SED")
TOKEN=$(echo $RES | sed 's/.*"token":*.{[^{]*"id":[^"]*"\([^"]*\).*/\1/g')
echo $HOST
echo $TOKEN
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment