blob: cfd9e821d939566eb8ba47b5a559c37f4edb217d [file] [log] [blame]
Brian Waldonf20e4ed2011-10-27 22:04:15 -04001import json
2
3import kong.common.http
4from kong import exceptions
5
6
7class API(kong.common.http.Client):
8 """Barebones Keystone HTTP API client."""
9
10 def __init__(self, service_host, service_port):
11 super(API, self).__init__(service_host, service_port, 'v2.0')
12
13 #TODO(bcwaldon): This is a hack, we should clean up the superclass
14 self.management_url = self.base_url
15
16 def get_token(self, user, password, tenant_id):
17 headers = {'content-type': 'application/json'}
18
19 body = {
20 "auth": {
21 "passwordCredentials":{
22 "username": user,
23 "password": password,
24 },
25 "tenantId": tenant_id,
26 },
27 }
28
29 response, content = self.request('POST', '/tokens',
30 headers=headers,
31 body=json.dumps(body))
32
33 res_body = json.loads(content)
34 return res_body['access']['token']['id']