Skip to content

Instantly share code, notes, and snippets.

@heckj
Created March 16, 2012 02:23
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save heckj/2048157 to your computer and use it in GitHub Desktop.
Save heckj/2048157 to your computer and use it in GitHub Desktop.
shell script to auth against keystone essex
#!/bin/bash
set -e
[[ $1 == "-c" ]] && {
CONTINUE=yes
shift
}
URL=$1
USER=$2
PASSWORD=$3
if [[ $URL != http* ]];then
URL="http://$URL:5000/v2.0/tokens"
fi
[[ -z $PASSWORD ]] && {
echo "$0 URL USER[:TENANT] PASSWORD"
exit 1
}
if [[ $USER == *:* ]];then
TENANT=${USER%%:*}
USER=${USER##*:}
else
TENANT=$USER
fi
#curl -s -d "{\"auth\": {\"passwordCredentials\": {\"username\": \"$1\", \"password\": \"$2\"}}}" -H 'Content-type: application/json' http://$3:5000/v2.0/tokens | python -m json.tool
curl -s -d "{\"auth\": {\"tenantName\": \"$TENANT\", \"passwordCredentials\": {\"username\": \"$USER\", \"password\": \"$PASSWORD\"}}}" -H 'Content-type: application/json' $URL >/tmp/.auth.json
grep -q 'access' /tmp/.auth.json || {
curl -v -d "{\"auth\": {\"tenantName\": \"$TENANT\", \"passwordCredentials\": {\"username\": \"$USER\", \"password\": \"$PASSWORD\"}}}" -H 'Content-type: application/json' $URL
echo
exit
}
python -mjson.tool < /tmp/.auth.json > /tmp/.pauth.json
TOKEN=$(grep -2 "token" /tmp/.pauth.json|grep id|sed 's/.* "//;s/".*//')
URL=$( grep internalURL /tmp/.pauth.json|grep 8080|sed 's/.*: .//;s/".*//')
cat /tmp/.pauth.json
echo "curl -H 'X-Auth-Token: ${TOKEN}' ${URL}"
[[ -n ${CONTINUE} ]] || exit
curl -v -H "X-Auth-Token: ${TOKEN}" ${URL}
echo
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment