Brian Waldon | f20e4ed | 2011-10-27 22:04:15 -0400 | [diff] [blame] | 1 | import json |
| 2 | |
| 3 | import kong.common.http |
| 4 | from kong import exceptions |
| 5 | |
| 6 | |
| 7 | class 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'] |