blob: 48a79568673299f965df7483a3de358654c0cc29 [file] [log] [blame]
Daniel Mellado76405392016-02-11 12:47:12 +00001# Copyright 2016 Red Hat, Inc.
2#
3# Licensed under the Apache License, Version 2.0 (the "License");
4# you may not use this file except in compliance with the License.
5# You may obtain 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,
11# WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
12# See the License for the specific language governing permissions and
13# limitations under the License.
14
songwenping99d6e002021-01-05 03:07:46 +000015from urllib import parse as urllib
16
Daniel Mellado76405392016-02-11 12:47:12 +000017from oslo_serialization import jsonutils as json
18
Ken'ichi Ohmichid35a1332016-03-02 10:38:07 -080019from tempest.lib.common import rest_client
Daniel Mellado76405392016-02-11 12:47:12 +000020
21
Ken'ichi Ohmichid35a1332016-03-02 10:38:07 -080022class TrustsClient(rest_client.RestClient):
Daniel Mellado76405392016-02-11 12:47:12 +000023 api_version = "v3"
24
25 def create_trust(self, **kwargs):
26 """Creates a trust.
27
OTSUKA, Yuanyingfaac5712016-09-15 13:53:55 +090028 For a full list of available parameters, please refer to the official
29 API reference:
Andreas Jaegerbf30ae72019-07-22 19:22:57 +020030 https://docs.openstack.org/api-ref/identity/v3-ext/index.html#create-trust
Daniel Mellado76405392016-02-11 12:47:12 +000031 """
32 post_body = json.dumps({'trust': kwargs})
33 resp, body = self.post('OS-TRUST/trusts', post_body)
34 self.expected_success(201, resp.status)
35 body = json.loads(body)
Ken'ichi Ohmichid35a1332016-03-02 10:38:07 -080036 return rest_client.ResponseBody(resp, body)
Daniel Mellado76405392016-02-11 12:47:12 +000037
38 def delete_trust(self, trust_id):
39 """Deletes a trust."""
40 resp, body = self.delete("OS-TRUST/trusts/%s" % trust_id)
41 self.expected_success(204, resp.status)
Ken'ichi Ohmichid35a1332016-03-02 10:38:07 -080042 return rest_client.ResponseBody(resp, body)
Daniel Mellado76405392016-02-11 12:47:12 +000043
Daniel Melladoc8d641a2016-09-01 10:29:24 +000044 def list_trusts(self, **params):
45 """Returns trusts
46
OTSUKA, Yuanyingfaac5712016-09-15 13:53:55 +090047 For a full list of available parameters, please refer to the official
48 API reference:
Andreas Jaegerbf30ae72019-07-22 19:22:57 +020049 https://docs.openstack.org/api-ref/identity/v3-ext/index.html#list-trusts
Daniel Melladoc8d641a2016-09-01 10:29:24 +000050 """
51 url = "OS-TRUST/trusts/"
52 if params:
53 url += '?%s' % urllib.urlencode(params)
54 resp, body = self.get(url)
Daniel Mellado76405392016-02-11 12:47:12 +000055 self.expected_success(200, resp.status)
56 body = json.loads(body)
Ken'ichi Ohmichid35a1332016-03-02 10:38:07 -080057 return rest_client.ResponseBody(resp, body)
Daniel Mellado76405392016-02-11 12:47:12 +000058
59 def show_trust(self, trust_id):
60 """GET trust."""
61 resp, body = self.get("OS-TRUST/trusts/%s" % trust_id)
62 self.expected_success(200, resp.status)
63 body = json.loads(body)
Ken'ichi Ohmichid35a1332016-03-02 10:38:07 -080064 return rest_client.ResponseBody(resp, body)
Daniel Mellado76405392016-02-11 12:47:12 +000065
66 def list_trust_roles(self, trust_id):
67 """GET roles delegated by a trust."""
68 resp, body = self.get("OS-TRUST/trusts/%s/roles" % trust_id)
69 self.expected_success(200, resp.status)
70 body = json.loads(body)
Ken'ichi Ohmichid35a1332016-03-02 10:38:07 -080071 return rest_client.ResponseBody(resp, body)
Daniel Mellado76405392016-02-11 12:47:12 +000072
73 def show_trust_role(self, trust_id, role_id):
74 """GET role delegated by a trust."""
75 resp, body = self.get("OS-TRUST/trusts/%s/roles/%s"
76 % (trust_id, role_id))
77 self.expected_success(200, resp.status)
78 body = json.loads(body)
Ken'ichi Ohmichid35a1332016-03-02 10:38:07 -080079 return rest_client.ResponseBody(resp, body)
Daniel Mellado76405392016-02-11 12:47:12 +000080
81 def check_trust_role(self, trust_id, role_id):
82 """HEAD Check if role is delegated by a trust."""
83 resp, body = self.head("OS-TRUST/trusts/%s/roles/%s"
84 % (trust_id, role_id))
85 self.expected_success(200, resp.status)
Ken'ichi Ohmichid35a1332016-03-02 10:38:07 -080086 return rest_client.ResponseBody(resp, body)