blob: c610d65e14606c6b8b162ffda175cfe799bb4ff2 [file] [log] [blame]
Sean Dague556add52013-07-19 14:28:44 -04001# 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 Treinish21905512015-07-13 10:33:35 -040013from oslo_serialization import jsonutils as json
Pradeep Kumar1c796282017-04-27 16:48:36 +053014from six.moves.urllib import parse as urllib
chris fattarsi8ed39ac2012-04-30 14:11:27 -070015
Ken'ichi Ohmichid35a1332016-03-02 10:38:07 -080016from tempest.lib.common import rest_client
Matthew Treinish684d8992014-01-30 16:27:40 +000017
chris fattarsi8ed39ac2012-04-30 14:11:27 -070018
Ken'ichi Ohmichid35a1332016-03-02 10:38:07 -080019class IdentityClient(rest_client.RestClient):
Ralf Haferkampd5525e32015-06-19 17:17:47 +020020 api_version = "v2.0"
chris fattarsi8ed39ac2012-04-30 14:11:27 -070021
Ken'ichi Ohmichi402b8752015-11-09 10:47:16 +000022 def show_api_description(self):
Filip Hubík81354052015-03-09 19:04:23 +010023 """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 Ramineni0cfb4612015-08-24 08:49:10 +053027 body = json.loads(body)
Ken'ichi Ohmichid35a1332016-03-02 10:38:07 -080028 return rest_client.ResponseBody(resp, body)
Filip Hubík81354052015-03-09 19:04:23 +010029
Ken'ichi Ohmichi402b8752015-11-09 10:47:16 +000030 def show_token(self, token_id):
Zhi Kun Liu30caeae2014-02-26 15:30:24 +080031 """Get token details."""
32 resp, body = self.get("tokens/%s" % token_id)
David Kranze9d2f422014-07-02 13:57:41 -040033 self.expected_success(200, resp.status)
Anusha Ramineni0cfb4612015-08-24 08:49:10 +053034 body = json.loads(body)
Ken'ichi Ohmichid35a1332016-03-02 10:38:07 -080035 return rest_client.ResponseBody(resp, body)
Zhi Kun Liu30caeae2014-02-26 15:30:24 +080036
Rohit Karajgi6b1e1542012-05-14 05:55:54 -070037 def delete_token(self, token_id):
Sean Daguef237ccb2013-01-04 15:19:14 -050038 """Delete a token."""
David Kranze9d2f422014-07-02 13:57:41 -040039 resp, body = self.delete("tokens/%s" % token_id)
40 self.expected_success(204, resp.status)
Ken'ichi Ohmichid35a1332016-03-02 10:38:07 -080041 return rest_client.ResponseBody(resp, body)
Rohit Karajgi6b1e1542012-05-14 05:55:54 -070042
Abhijeet.Jain3f49b842014-05-20 12:06:20 +053043 def list_extensions(self):
44 """List all the extensions."""
45 resp, body = self.get('/extensions')
David Kranze9d2f422014-07-02 13:57:41 -040046 self.expected_success(200, resp.status)
Abhijeet.Jain3f49b842014-05-20 12:06:20 +053047 body = json.loads(body)
Ken'ichi Ohmichid35a1332016-03-02 10:38:07 -080048 return rest_client.ResponseBody(resp, body)
Pradeep Kumar1c796282017-04-27 16:48:36 +053049
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)