blob: dedee0507bd9cea1dbd4e04c454da6bd225fa211 [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
15from oslo_serialization import jsonutils as json
16
Ken'ichi Ohmichid35a1332016-03-02 10:38:07 -080017from tempest.lib.common import rest_client
Daniel Mellado76405392016-02-11 12:47:12 +000018
19
Ken'ichi Ohmichid35a1332016-03-02 10:38:07 -080020class TrustsClient(rest_client.RestClient):
Daniel Mellado76405392016-02-11 12:47:12 +000021 api_version = "v3"
22
23 def create_trust(self, **kwargs):
24 """Creates a trust.
25
26 Available params: see http://developer.openstack.org/
27 api-ref-identity-v3-ext.html#createTrust
28 """
29 post_body = json.dumps({'trust': kwargs})
30 resp, body = self.post('OS-TRUST/trusts', post_body)
31 self.expected_success(201, resp.status)
32 body = json.loads(body)
Ken'ichi Ohmichid35a1332016-03-02 10:38:07 -080033 return rest_client.ResponseBody(resp, body)
Daniel Mellado76405392016-02-11 12:47:12 +000034
35 def delete_trust(self, trust_id):
36 """Deletes a trust."""
37 resp, body = self.delete("OS-TRUST/trusts/%s" % trust_id)
38 self.expected_success(204, resp.status)
Ken'ichi Ohmichid35a1332016-03-02 10:38:07 -080039 return rest_client.ResponseBody(resp, body)
Daniel Mellado76405392016-02-11 12:47:12 +000040
41 def list_trusts(self, trustor_user_id=None, trustee_user_id=None):
42 """GET trusts."""
43 if trustor_user_id:
44 resp, body = self.get("OS-TRUST/trusts?trustor_user_id=%s"
45 % trustor_user_id)
46 elif trustee_user_id:
47 resp, body = self.get("OS-TRUST/trusts?trustee_user_id=%s"
48 % trustee_user_id)
49 else:
50 resp, body = self.get("OS-TRUST/trusts")
51 self.expected_success(200, resp.status)
52 body = json.loads(body)
Ken'ichi Ohmichid35a1332016-03-02 10:38:07 -080053 return rest_client.ResponseBody(resp, body)
Daniel Mellado76405392016-02-11 12:47:12 +000054
55 def show_trust(self, trust_id):
56 """GET trust."""
57 resp, body = self.get("OS-TRUST/trusts/%s" % trust_id)
58 self.expected_success(200, resp.status)
59 body = json.loads(body)
Ken'ichi Ohmichid35a1332016-03-02 10:38:07 -080060 return rest_client.ResponseBody(resp, body)
Daniel Mellado76405392016-02-11 12:47:12 +000061
62 def list_trust_roles(self, trust_id):
63 """GET roles delegated by a trust."""
64 resp, body = self.get("OS-TRUST/trusts/%s/roles" % trust_id)
65 self.expected_success(200, resp.status)
66 body = json.loads(body)
Ken'ichi Ohmichid35a1332016-03-02 10:38:07 -080067 return rest_client.ResponseBody(resp, body)
Daniel Mellado76405392016-02-11 12:47:12 +000068
69 def show_trust_role(self, trust_id, role_id):
70 """GET role delegated by a trust."""
71 resp, body = self.get("OS-TRUST/trusts/%s/roles/%s"
72 % (trust_id, role_id))
73 self.expected_success(200, resp.status)
74 body = json.loads(body)
Ken'ichi Ohmichid35a1332016-03-02 10:38:07 -080075 return rest_client.ResponseBody(resp, body)
Daniel Mellado76405392016-02-11 12:47:12 +000076
77 def check_trust_role(self, trust_id, role_id):
78 """HEAD Check if role is delegated by a trust."""
79 resp, body = self.head("OS-TRUST/trusts/%s/roles/%s"
80 % (trust_id, role_id))
81 self.expected_success(200, resp.status)
Ken'ichi Ohmichid35a1332016-03-02 10:38:07 -080082 return rest_client.ResponseBody(resp, body)