Skip to content

Instantly share code, notes, and snippets.

@notmyname
Created April 12, 2015 21:51
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 notmyname/64eaa387e816151ecfbb to your computer and use it in GitHub Desktop.
Save notmyname/64eaa387e816151ecfbb to your computer and use it in GitHub Desktop.
def auth_v2(url, tenant_id, username, password, region=None):
connection = httplib.HTTPSConnection(url)
body_json = {
"auth": {
"passwordCredentials": {
"username": username,
"password": password
},
"tenantId": tenant_id
}
}
connection.request('POST', '/v2.0/tokens', body=json.dumps(body_json),
headers={'content-type': 'application/json',
'accept': 'application/json'})
response = connection.getresponse()
catalog = response.read()
cat = json.loads(catalog)
auth_token = cat['access']['token']['id']
for thing in cat['access']['serviceCatalog']:
if thing['type'] == 'object-store': # instead of name == swift
for ep in thing['endpoints']:
storage_url = ep['publicURL']
if region is None:
return storage_url, auth_token
elif ep['region'] == region:
return storage_url, auth_token
return None, None
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment