Last active
March 4, 2016 14:33
-
-
Save metacoma/d43e55f863b374c9c277 to your computer and use it in GitHub Desktop.
trust for user
This file contains 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/sh | |
KEYSTONE_USER=`cat /etc/fuel/astute.yaml | python -c 'import yaml, sys; print yaml.load(sys.stdin)["FUEL_ACCESS"]["user"]'` | |
KEYSTONE_PASS=`cat /etc/fuel/astute.yaml | python -c 'import yaml, sys; print yaml.load(sys.stdin)["FUEL_ACCESS"]["password"]'` | |
KEYSTONE_TENANT=admin | |
KEYSTONE_URL="http://127.0.0.1:5000/v3" | |
function auth_data() { | |
cat<<EOF | |
auth: | |
identity: | |
methods: [ password ] | |
password: | |
user: | |
name: $KEYSTONE_USER | |
domain: | |
id: default | |
password: ${KEYSTONE_PASS} | |
EOF | |
} | |
function yaml2json { | |
python -c 'import sys, json, yaml; print json.dumps(yaml.load(sys.stdin))' | |
} | |
function keystone_auth_token() { | |
auth_data | yaml2json | curl -sX POST --data-binary @- -vvvH 'Content-type: application/json' -o /dev/null ${KEYSTONE_URL}/auth/tokens 2>&1 | awk '/X-Subject-Token/ {print $3}' | |
} | |
function keystone_user_id() { | |
curl -sH "X-Auth-Token: ${auth_token}" ${KEYSTONE_URL}/users | python -c 'import json,sys; print (u for u in json.load(sys.stdin)["users"] if u["name"] == "'$1'").next()["id"]' | |
} | |
function keystone_project_id() { | |
curl -sH "X-Auth-Token: ${auth_token}" ${KEYSTONE_URL}/projects | python -c 'import json,sys; print (u for u in json.load(sys.stdin)["projects"] if u["name"] == "'$1'").next()["id"]' | |
} | |
function trust_data() { | |
cat<<EOF | |
trust: | |
impersonation: false | |
project_id: ${project_id} | |
roles: | |
- name: ${KEYSTONE_USER} | |
trustee_user_id: ${user_id} | |
trustor_user_id: ${user_id} | |
EOF | |
} | |
function keystone_create_trust() { | |
trust_data | yaml2json | curl -sX POST --data-binary @- -H 'Content-type: application/json' -H "X-Auth-Token: ${auth_token}" ${KEYSTONE_URL}/OS-TRUST/trusts | python -c 'import json,sys; print json.load(sys.stdin)["trust"]["id"]' | |
} | |
auth_token=`keystone_auth_token` | |
user_id=`keystone_user_id $KEYSTONE_USER` | |
project_id=`keystone_project_id $KEYSTONE_TENANT` | |
keystone_create_trust |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment