blob: caf8b527d3e480fdf090dad7fd7b2d715b2af794 [file] [log] [blame]
Rodrigo Duarte4666c642016-04-06 11:52:19 -03001# Copyright 2016 Red Hat, Inc.
2#
3# Licensed under the Apache License, Version 2.0 (the "License"); you may
4# not use this file except in compliance with the License. You may obtain
5# a copy of the License at
6#
7# http://www.apache.org/licenses/LICENSE-2.0
8#
9# Unless required by applicable law or agreed to in writing, software
10# distributed under the License is distributed on an "AS IS" BASIS, WITHOUT
11# WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. See the
12# License for the specific language governing permissions and limitations
13# under the License.
14
Rodrigo Duarte Sousa79abcf42016-06-16 09:31:01 -030015import json
16
17from six.moves import http_client
Rodrigo Duarte4666c642016-04-06 11:52:19 -030018from tempest import config
19from tempest.lib.common import rest_client
20
21
22CONF = config.CONF
23
24# We only use the identity catalog type
25SERVICE_TYPE = 'identity'
26
27
28class Identity(rest_client.RestClient):
29 """Tempest REST client for keystone."""
30
31 # Used by the superclass to build the correct URL paths
32 api_version = 'v3'
33
34 def __init__(self, auth_provider):
35 super(Identity, self).__init__(
36 auth_provider,
37 SERVICE_TYPE,
38 CONF.identity.region,
39 endpoint_type='adminURL')
Rodrigo Duarted96e29c2016-04-08 11:53:43 -030040
41
42class Federation(Identity):
43 """Tempest REST client for keystone's Federated Identity API."""
44
45 subpath_prefix = 'OS-FEDERATION'
46 subpath_suffix = None
47
48 def _build_path(self, entity_id=None):
49 subpath = '%s/%s' % (self.subpath_prefix, self.subpath_suffix)
50 return '%s/%s' % (subpath, entity_id) if entity_id else subpath
51
52 def _delete(self, entity_id, **kwargs):
53 url = self._build_path(entity_id)
Rodrigo Duarte Sousa79abcf42016-06-16 09:31:01 -030054 resp, body = super(Federation, self).delete(url, **kwargs)
55 self.expected_success(http_client.NO_CONTENT, resp.status)
56 return rest_client.ResponseBody(resp, body)
Rodrigo Duarted96e29c2016-04-08 11:53:43 -030057
58 def _get(self, entity_id=None, **kwargs):
59 url = self._build_path(entity_id)
Rodrigo Duarte Sousa79abcf42016-06-16 09:31:01 -030060 resp, body = super(Federation, self).get(url, **kwargs)
61 self.expected_success(http_client.OK, resp.status)
62 body = json.loads(body)
63 return rest_client.ResponseBody(resp, body)
Rodrigo Duarted96e29c2016-04-08 11:53:43 -030064
65 def _patch(self, entity_id, body, **kwargs):
66 url = self._build_path(entity_id)
Rodrigo Duarte Sousa79abcf42016-06-16 09:31:01 -030067 resp, body = super(Federation, self).patch(url, body, **kwargs)
68 self.expected_success(http_client.OK, resp.status)
69 body = json.loads(body)
70 return rest_client.ResponseBody(resp, body)
Rodrigo Duarted96e29c2016-04-08 11:53:43 -030071
72 def _put(self, entity_id, body, **kwargs):
73 url = self._build_path(entity_id)
Rodrigo Duarte Sousa79abcf42016-06-16 09:31:01 -030074 resp, body = super(Federation, self).put(url, body, **kwargs)
75 self.expected_success(http_client.CREATED, resp.status)
76 body = json.loads(body)
77 return rest_client.ResponseBody(resp, body)