Sean Dague | 556add5 | 2013-07-19 14:28:44 -0400 | [diff] [blame] | 1 | # Licensed under the Apache License, Version 2.0 (the "License"); you may |
| 2 | # not use this file except in compliance with the License. You may obtain |
| 3 | # a copy of the License at |
| 4 | # |
| 5 | # http://www.apache.org/licenses/LICENSE-2.0 |
| 6 | # |
| 7 | # Unless required by applicable law or agreed to in writing, software |
| 8 | # distributed under the License is distributed on an "AS IS" BASIS, WITHOUT |
| 9 | # WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. See the |
| 10 | # License for the specific language governing permissions and limitations |
| 11 | # under the License. |
| 12 | |
Matthew Treinish | 2190551 | 2015-07-13 10:33:35 -0400 | [diff] [blame] | 13 | from oslo_serialization import jsonutils as json |
Pradeep Kumar | 1c79628 | 2017-04-27 16:48:36 +0530 | [diff] [blame] | 14 | from six.moves.urllib import parse as urllib |
chris fattarsi | 8ed39ac | 2012-04-30 14:11:27 -0700 | [diff] [blame] | 15 | |
Ken'ichi Ohmichi | d35a133 | 2016-03-02 10:38:07 -0800 | [diff] [blame] | 16 | from tempest.lib.common import rest_client |
Matthew Treinish | 684d899 | 2014-01-30 16:27:40 +0000 | [diff] [blame] | 17 | |
chris fattarsi | 8ed39ac | 2012-04-30 14:11:27 -0700 | [diff] [blame] | 18 | |
Ken'ichi Ohmichi | d35a133 | 2016-03-02 10:38:07 -0800 | [diff] [blame] | 19 | class IdentityClient(rest_client.RestClient): |
Ralf Haferkamp | d5525e3 | 2015-06-19 17:17:47 +0200 | [diff] [blame] | 20 | api_version = "v2.0" |
chris fattarsi | 8ed39ac | 2012-04-30 14:11:27 -0700 | [diff] [blame] | 21 | |
Ken'ichi Ohmichi | 402b875 | 2015-11-09 10:47:16 +0000 | [diff] [blame] | 22 | def show_api_description(self): |
Filip Hubík | 8135405 | 2015-03-09 19:04:23 +0100 | [diff] [blame] | 23 | """Retrieves info about the v2.0 Identity API""" |
| 24 | url = '' |
| 25 | resp, body = self.get(url) |
| 26 | self.expected_success([200, 203], resp.status) |
Anusha Ramineni | 0cfb461 | 2015-08-24 08:49:10 +0530 | [diff] [blame] | 27 | body = json.loads(body) |
Ken'ichi Ohmichi | d35a133 | 2016-03-02 10:38:07 -0800 | [diff] [blame] | 28 | return rest_client.ResponseBody(resp, body) |
Filip Hubík | 8135405 | 2015-03-09 19:04:23 +0100 | [diff] [blame] | 29 | |
Ken'ichi Ohmichi | 402b875 | 2015-11-09 10:47:16 +0000 | [diff] [blame] | 30 | def show_token(self, token_id): |
Zhi Kun Liu | 30caeae | 2014-02-26 15:30:24 +0800 | [diff] [blame] | 31 | """Get token details.""" |
| 32 | resp, body = self.get("tokens/%s" % token_id) |
David Kranz | e9d2f42 | 2014-07-02 13:57:41 -0400 | [diff] [blame] | 33 | self.expected_success(200, resp.status) |
Anusha Ramineni | 0cfb461 | 2015-08-24 08:49:10 +0530 | [diff] [blame] | 34 | body = json.loads(body) |
Ken'ichi Ohmichi | d35a133 | 2016-03-02 10:38:07 -0800 | [diff] [blame] | 35 | return rest_client.ResponseBody(resp, body) |
Zhi Kun Liu | 30caeae | 2014-02-26 15:30:24 +0800 | [diff] [blame] | 36 | |
Rohit Karajgi | 6b1e154 | 2012-05-14 05:55:54 -0700 | [diff] [blame] | 37 | def delete_token(self, token_id): |
Sean Dague | f237ccb | 2013-01-04 15:19:14 -0500 | [diff] [blame] | 38 | """Delete a token.""" |
David Kranz | e9d2f42 | 2014-07-02 13:57:41 -0400 | [diff] [blame] | 39 | resp, body = self.delete("tokens/%s" % token_id) |
| 40 | self.expected_success(204, resp.status) |
Ken'ichi Ohmichi | d35a133 | 2016-03-02 10:38:07 -0800 | [diff] [blame] | 41 | return rest_client.ResponseBody(resp, body) |
Rohit Karajgi | 6b1e154 | 2012-05-14 05:55:54 -0700 | [diff] [blame] | 42 | |
Abhijeet.Jain | 3f49b84 | 2014-05-20 12:06:20 +0530 | [diff] [blame] | 43 | def list_extensions(self): |
| 44 | """List all the extensions.""" |
| 45 | resp, body = self.get('/extensions') |
David Kranz | e9d2f42 | 2014-07-02 13:57:41 -0400 | [diff] [blame] | 46 | self.expected_success(200, resp.status) |
Abhijeet.Jain | 3f49b84 | 2014-05-20 12:06:20 +0530 | [diff] [blame] | 47 | body = json.loads(body) |
Ken'ichi Ohmichi | d35a133 | 2016-03-02 10:38:07 -0800 | [diff] [blame] | 48 | return rest_client.ResponseBody(resp, body) |
Pradeep Kumar | 1c79628 | 2017-04-27 16:48:36 +0530 | [diff] [blame] | 49 | |
| 50 | def list_endpoints_for_token(self, token_id): |
| 51 | """List endpoints for a token """ |
| 52 | resp, body = self.get("tokens/%s/endpoints" % token_id) |
| 53 | self.expected_success(200, resp.status) |
| 54 | body = json.loads(body) |
| 55 | return rest_client.ResponseBody(resp, body) |
| 56 | |
| 57 | def check_token_existence(self, token_id, **params): |
| 58 | """Validates a token and confirms that it belongs to a tenant. |
| 59 | |
| 60 | For a full list of available parameters, please refer to the |
| 61 | official API reference: |
| 62 | https://developer.openstack.org/api-ref/identity/v2-admin/#validate-token |
| 63 | """ |
| 64 | url = "tokens/%s" % token_id |
| 65 | if params: |
| 66 | url += '?%s' % urllib.urlencode(params) |
| 67 | resp, body = self.head(url) |
| 68 | self.expected_success(200, resp.status) |
| 69 | return rest_client.ResponseBody(resp, body) |