blob: f1339dd5fc40a04952b60fa2152d32f67787ebdc [file] [log] [blame]
Arx Cruz24bcb882016-02-10 15:20:16 +01001# 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
ghanshyam2e6fb562016-09-06 11:14:31 +090016from six.moves.urllib import parse as urllib
Arx Cruz24bcb882016-02-10 15:20:16 +010017
Ken'ichi Ohmichid35a1332016-03-02 10:38:07 -080018from tempest.lib.common import rest_client
Arx Cruz24bcb882016-02-10 15:20:16 +010019
20
Ken'ichi Ohmichid35a1332016-03-02 10:38:07 -080021class RolesClient(rest_client.RestClient):
Arx Cruz24bcb882016-02-10 15:20:16 +010022 api_version = "v3"
23
24 def create_role(self, **kwargs):
25 """Create a Role.
26
OTSUKA, Yuanyingfaac5712016-09-15 13:53:55 +090027 For a full list of available parameters, please refer to the official
28 API reference:
29 http://developer.openstack.org/api-ref/identity/v3/index.html#create-role
Arx Cruz24bcb882016-02-10 15:20:16 +010030 """
31 post_body = json.dumps({'role': kwargs})
32 resp, body = self.post('roles', post_body)
33 self.expected_success(201, resp.status)
34 body = json.loads(body)
Ken'ichi Ohmichid35a1332016-03-02 10:38:07 -080035 return rest_client.ResponseBody(resp, body)
Arx Cruz24bcb882016-02-10 15:20:16 +010036
37 def show_role(self, role_id):
38 """GET a Role."""
guo yunxian6cdf0562016-08-17 16:21:52 +080039 resp, body = self.get('roles/%s' % role_id)
Arx Cruz24bcb882016-02-10 15:20:16 +010040 self.expected_success(200, resp.status)
41 body = json.loads(body)
Ken'ichi Ohmichid35a1332016-03-02 10:38:07 -080042 return rest_client.ResponseBody(resp, body)
Arx Cruz24bcb882016-02-10 15:20:16 +010043
ghanshyam2e6fb562016-09-06 11:14:31 +090044 def list_roles(self, **params):
Arx Cruz24bcb882016-02-10 15:20:16 +010045 """Get the list of Roles."""
ghanshyam2e6fb562016-09-06 11:14:31 +090046
47 url = 'roles'
48 if params:
49 url += '?%s' % urllib.urlencode(params)
50 resp, body = self.get(url)
Arx Cruz24bcb882016-02-10 15:20:16 +010051 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)
Arx Cruz24bcb882016-02-10 15:20:16 +010054
55 def update_role(self, role_id, **kwargs):
56 """Update a Role.
57
OTSUKA, Yuanyingfaac5712016-09-15 13:53:55 +090058 For a full list of available parameters, please refer to the official
59 API reference:
60 http://developer.openstack.org/api-ref/identity/v3/index.html#update-role
Arx Cruz24bcb882016-02-10 15:20:16 +010061 """
62 post_body = json.dumps({'role': kwargs})
guo yunxian6cdf0562016-08-17 16:21:52 +080063 resp, body = self.patch('roles/%s' % role_id, post_body)
Arx Cruz24bcb882016-02-10 15:20:16 +010064 self.expected_success(200, resp.status)
65 body = json.loads(body)
Ken'ichi Ohmichid35a1332016-03-02 10:38:07 -080066 return rest_client.ResponseBody(resp, body)
Arx Cruz24bcb882016-02-10 15:20:16 +010067
68 def delete_role(self, role_id):
69 """Delete a role."""
guo yunxian6cdf0562016-08-17 16:21:52 +080070 resp, body = self.delete('roles/%s' % role_id)
Arx Cruz24bcb882016-02-10 15:20:16 +010071 self.expected_success(204, resp.status)
Ken'ichi Ohmichid35a1332016-03-02 10:38:07 -080072 return rest_client.ResponseBody(resp, body)
Arx Cruz24bcb882016-02-10 15:20:16 +010073
ghanshyam2e6fb562016-09-06 11:14:31 +090074 def create_user_role_on_project(self, project_id, user_id, role_id):
Arx Cruz24bcb882016-02-10 15:20:16 +010075 """Add roles to a user on a project."""
76 resp, body = self.put('projects/%s/users/%s/roles/%s' %
77 (project_id, user_id, role_id), None)
78 self.expected_success(204, resp.status)
Ken'ichi Ohmichid35a1332016-03-02 10:38:07 -080079 return rest_client.ResponseBody(resp, body)
Arx Cruz24bcb882016-02-10 15:20:16 +010080
ghanshyam2e6fb562016-09-06 11:14:31 +090081 def create_user_role_on_domain(self, domain_id, user_id, role_id):
Arx Cruz24bcb882016-02-10 15:20:16 +010082 """Add roles to a user on a domain."""
83 resp, body = self.put('domains/%s/users/%s/roles/%s' %
84 (domain_id, user_id, role_id), None)
85 self.expected_success(204, resp.status)
Ken'ichi Ohmichid35a1332016-03-02 10:38:07 -080086 return rest_client.ResponseBody(resp, body)
Arx Cruz24bcb882016-02-10 15:20:16 +010087
88 def list_user_roles_on_project(self, project_id, user_id):
89 """list roles of a user on a project."""
90 resp, body = self.get('projects/%s/users/%s/roles' %
91 (project_id, user_id))
92 self.expected_success(200, resp.status)
93 body = json.loads(body)
Ken'ichi Ohmichid35a1332016-03-02 10:38:07 -080094 return rest_client.ResponseBody(resp, body)
Arx Cruz24bcb882016-02-10 15:20:16 +010095
96 def list_user_roles_on_domain(self, domain_id, user_id):
97 """list roles of a user on a domain."""
98 resp, body = self.get('domains/%s/users/%s/roles' %
99 (domain_id, user_id))
100 self.expected_success(200, resp.status)
101 body = json.loads(body)
Ken'ichi Ohmichid35a1332016-03-02 10:38:07 -0800102 return rest_client.ResponseBody(resp, body)
Arx Cruz24bcb882016-02-10 15:20:16 +0100103
104 def delete_role_from_user_on_project(self, project_id, user_id, role_id):
105 """Delete role of a user on a project."""
106 resp, body = self.delete('projects/%s/users/%s/roles/%s' %
107 (project_id, user_id, role_id))
108 self.expected_success(204, resp.status)
Ken'ichi Ohmichid35a1332016-03-02 10:38:07 -0800109 return rest_client.ResponseBody(resp, body)
Arx Cruz24bcb882016-02-10 15:20:16 +0100110
111 def delete_role_from_user_on_domain(self, domain_id, user_id, role_id):
112 """Delete role of a user on a domain."""
113 resp, body = self.delete('domains/%s/users/%s/roles/%s' %
114 (domain_id, user_id, role_id))
115 self.expected_success(204, resp.status)
Ken'ichi Ohmichid35a1332016-03-02 10:38:07 -0800116 return rest_client.ResponseBody(resp, body)
Arx Cruz24bcb882016-02-10 15:20:16 +0100117
118 def check_user_role_existence_on_project(self, project_id,
119 user_id, role_id):
120 """Check role of a user on a project."""
121 resp, body = self.head('projects/%s/users/%s/roles/%s' %
122 (project_id, user_id, role_id))
123 self.expected_success(204, resp.status)
Ken'ichi Ohmichid35a1332016-03-02 10:38:07 -0800124 return rest_client.ResponseBody(resp)
Arx Cruz24bcb882016-02-10 15:20:16 +0100125
126 def check_user_role_existence_on_domain(self, domain_id,
127 user_id, role_id):
128 """Check role of a user on a domain."""
129 resp, body = self.head('domains/%s/users/%s/roles/%s' %
130 (domain_id, user_id, role_id))
131 self.expected_success(204, resp.status)
Ken'ichi Ohmichid35a1332016-03-02 10:38:07 -0800132 return rest_client.ResponseBody(resp)
Arx Cruz24bcb882016-02-10 15:20:16 +0100133
ghanshyam2e6fb562016-09-06 11:14:31 +0900134 def create_group_role_on_project(self, project_id, group_id, role_id):
135 """Add roles to a group on a project."""
Arx Cruz24bcb882016-02-10 15:20:16 +0100136 resp, body = self.put('projects/%s/groups/%s/roles/%s' %
137 (project_id, group_id, role_id), None)
138 self.expected_success(204, resp.status)
Ken'ichi Ohmichid35a1332016-03-02 10:38:07 -0800139 return rest_client.ResponseBody(resp, body)
Arx Cruz24bcb882016-02-10 15:20:16 +0100140
ghanshyam2e6fb562016-09-06 11:14:31 +0900141 def create_group_role_on_domain(self, domain_id, group_id, role_id):
142 """Add roles to a group on a domain."""
Arx Cruz24bcb882016-02-10 15:20:16 +0100143 resp, body = self.put('domains/%s/groups/%s/roles/%s' %
144 (domain_id, group_id, role_id), None)
145 self.expected_success(204, resp.status)
Ken'ichi Ohmichid35a1332016-03-02 10:38:07 -0800146 return rest_client.ResponseBody(resp, body)
Arx Cruz24bcb882016-02-10 15:20:16 +0100147
148 def list_group_roles_on_project(self, project_id, group_id):
ghanshyam2e6fb562016-09-06 11:14:31 +0900149 """list roles of a group on a project."""
Arx Cruz24bcb882016-02-10 15:20:16 +0100150 resp, body = self.get('projects/%s/groups/%s/roles' %
151 (project_id, group_id))
152 self.expected_success(200, resp.status)
153 body = json.loads(body)
Ken'ichi Ohmichid35a1332016-03-02 10:38:07 -0800154 return rest_client.ResponseBody(resp, body)
Arx Cruz24bcb882016-02-10 15:20:16 +0100155
156 def list_group_roles_on_domain(self, domain_id, group_id):
ghanshyam2e6fb562016-09-06 11:14:31 +0900157 """list roles of a group on a domain."""
Arx Cruz24bcb882016-02-10 15:20:16 +0100158 resp, body = self.get('domains/%s/groups/%s/roles' %
159 (domain_id, group_id))
160 self.expected_success(200, resp.status)
161 body = json.loads(body)
Ken'ichi Ohmichid35a1332016-03-02 10:38:07 -0800162 return rest_client.ResponseBody(resp, body)
Arx Cruz24bcb882016-02-10 15:20:16 +0100163
164 def delete_role_from_group_on_project(self, project_id, group_id, role_id):
ghanshyam2e6fb562016-09-06 11:14:31 +0900165 """Delete role of a group on a project."""
Arx Cruz24bcb882016-02-10 15:20:16 +0100166 resp, body = self.delete('projects/%s/groups/%s/roles/%s' %
167 (project_id, group_id, role_id))
168 self.expected_success(204, resp.status)
Ken'ichi Ohmichid35a1332016-03-02 10:38:07 -0800169 return rest_client.ResponseBody(resp, body)
Arx Cruz24bcb882016-02-10 15:20:16 +0100170
171 def delete_role_from_group_on_domain(self, domain_id, group_id, role_id):
ghanshyam2e6fb562016-09-06 11:14:31 +0900172 """Delete role of a group on a domain."""
Arx Cruz24bcb882016-02-10 15:20:16 +0100173 resp, body = self.delete('domains/%s/groups/%s/roles/%s' %
174 (domain_id, group_id, role_id))
175 self.expected_success(204, resp.status)
Ken'ichi Ohmichid35a1332016-03-02 10:38:07 -0800176 return rest_client.ResponseBody(resp, body)
Arx Cruz24bcb882016-02-10 15:20:16 +0100177
178 def check_role_from_group_on_project_existence(self, project_id,
179 group_id, role_id):
ghanshyam2e6fb562016-09-06 11:14:31 +0900180 """Check role of a group on a project."""
Arx Cruz24bcb882016-02-10 15:20:16 +0100181 resp, body = self.head('projects/%s/groups/%s/roles/%s' %
182 (project_id, group_id, role_id))
183 self.expected_success(204, resp.status)
Ken'ichi Ohmichid35a1332016-03-02 10:38:07 -0800184 return rest_client.ResponseBody(resp)
Arx Cruz24bcb882016-02-10 15:20:16 +0100185
186 def check_role_from_group_on_domain_existence(self, domain_id,
187 group_id, role_id):
ghanshyam2e6fb562016-09-06 11:14:31 +0900188 """Check role of a group on a domain."""
Arx Cruz24bcb882016-02-10 15:20:16 +0100189 resp, body = self.head('domains/%s/groups/%s/roles/%s' %
190 (domain_id, group_id, role_id))
191 self.expected_success(204, resp.status)
Ken'ichi Ohmichid35a1332016-03-02 10:38:07 -0800192 return rest_client.ResponseBody(resp)