Last active
December 13, 2015 22:39
-
-
Save chmouel/4985787 to your computer and use it in GitHub Desktop.
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
#!/bin/bash | |
set -e | |
SUPERADMIN=$1 | |
USER=$2 | |
URL=$3 | |
EXTRAS=$4 | |
if [[ -z ${SUPERADMIN} || -z ${USER} || -z ${URL} ]];then | |
cat <<EOF | |
Get a keystone token from superadmin and the swift storage url for user: | |
Usage: ksas superadmin_user:superadmin_tenant:superadmin_password user:tenant:password url_or_host | |
EOF | |
exit | |
fi | |
if [[ $URL != http* ]];then | |
URL="http://$URL:5000/v2.0/tokens" | |
fi | |
IFS=':' read -a SUPER_ARRAY <<< "$SUPERADMIN" | |
SUPER_TENANT=${SUPER_ARRAY[0]} | |
SUPER_USER=${SUPER_ARRAY[1]} | |
SUPER_PASSWORD=${SUPER_ARRAY[2]} | |
IFS=':' read -a ARRAY <<< "$USER" | |
TENANT=${ARRAY[0]} | |
USER=${ARRAY[1]} | |
PASSWORD=${ARRAY[2]} | |
curl -s -d "{\"auth\": {\"tenantName\": \"$SUPER_TENANT\", \"passwordCredentials\": {\"username\": \"$SUPER_USER\", \"password\": \"$SUPER_PASSWORD\"}}}" -H 'Content-type: application/json' $URL >/tmp/.auth.json | |
grep -q 'access' /tmp/.auth.json || { | |
echo "error authing ${SUPER_TENANT}:${SUPER_USER}" | |
} | |
python -mjson.tool < /tmp/.auth.json > /tmp/.pauth.json | |
SUPER_TOKEN=$(grep -2 "token" /tmp/.pauth.json|grep id|sed 's/.* "//;s/".*//'|tr -d '\r') | |
SUPER_URL=$( grep -B10 object-store /tmp/.pauth.json|grep internalURL|sed 's/.* "//;s/".*//'|tr -d '\r') | |
curl -s -d "{\"auth\": {\"tenantName\": \"$TENANT\", \"passwordCredentials\": {\"username\": \"$USER\", \"password\": \"$PASSWORD\"}}}" -H 'Content-type: application/json' $URL >/tmp/.auth.json | |
#python -mjson.tool < /tmp/.auth.json |less | |
grep -q 'access' /tmp/.auth.json || { | |
echo "error authing ${TENANT}:${USER}" | |
} | |
python -mjson.tool < /tmp/.auth.json > /tmp/.pauth.json | |
TOKEN=$(grep -2 "token" /tmp/.pauth.json|grep id|sed 's/.* "//;s/".*//'|tr -d '\r') | |
URL=$( grep -B10 object-store /tmp/.pauth.json|grep internalURL|sed 's/.* "//;s/".*//'|tr -d '\r') | |
echo "curl -H 'X-Auth-Token: ${SUPER_TOKEN}' ${URL} ${EXTRAS}" |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Example:
~$ ksas admin:admin:ADMIN demo:demo:ADMIN localhost '-H "X-Account-Meta-Locked: 1"'
curl -H 'X-Auth-Token: f8ae837c7e3149cea5c1a1d1da821c31' http://172.16.129.128:8080/v1/AUTH_23f95aaeb1f04bc98f417cb9e52a14a6 -H "X-Account-Meta-Locked: 1"