-
-
Save notmyname/64eaa387e816151ecfbb to your computer and use it in GitHub Desktop.
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
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