Daniel Mellado | 7640539 | 2016-02-11 12:47:12 +0000 | [diff] [blame] | 1 | # 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 | |
| 15 | from oslo_serialization import jsonutils as json |
| 16 | |
Ken'ichi Ohmichi | d35a133 | 2016-03-02 10:38:07 -0800 | [diff] [blame] | 17 | from tempest.lib.common import rest_client |
Daniel Mellado | 7640539 | 2016-02-11 12:47:12 +0000 | [diff] [blame] | 18 | |
| 19 | |
Ken'ichi Ohmichi | d35a133 | 2016-03-02 10:38:07 -0800 | [diff] [blame] | 20 | class TrustsClient(rest_client.RestClient): |
Daniel Mellado | 7640539 | 2016-02-11 12:47:12 +0000 | [diff] [blame] | 21 | 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 Ohmichi | d35a133 | 2016-03-02 10:38:07 -0800 | [diff] [blame] | 33 | return rest_client.ResponseBody(resp, body) |
Daniel Mellado | 7640539 | 2016-02-11 12:47:12 +0000 | [diff] [blame] | 34 | |
| 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 Ohmichi | d35a133 | 2016-03-02 10:38:07 -0800 | [diff] [blame] | 39 | return rest_client.ResponseBody(resp, body) |
Daniel Mellado | 7640539 | 2016-02-11 12:47:12 +0000 | [diff] [blame] | 40 | |
| 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 Ohmichi | d35a133 | 2016-03-02 10:38:07 -0800 | [diff] [blame] | 53 | return rest_client.ResponseBody(resp, body) |
Daniel Mellado | 7640539 | 2016-02-11 12:47:12 +0000 | [diff] [blame] | 54 | |
| 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 Ohmichi | d35a133 | 2016-03-02 10:38:07 -0800 | [diff] [blame] | 60 | return rest_client.ResponseBody(resp, body) |
Daniel Mellado | 7640539 | 2016-02-11 12:47:12 +0000 | [diff] [blame] | 61 | |
| 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 Ohmichi | d35a133 | 2016-03-02 10:38:07 -0800 | [diff] [blame] | 67 | return rest_client.ResponseBody(resp, body) |
Daniel Mellado | 7640539 | 2016-02-11 12:47:12 +0000 | [diff] [blame] | 68 | |
| 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 Ohmichi | d35a133 | 2016-03-02 10:38:07 -0800 | [diff] [blame] | 75 | return rest_client.ResponseBody(resp, body) |
Daniel Mellado | 7640539 | 2016-02-11 12:47:12 +0000 | [diff] [blame] | 76 | |
| 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 Ohmichi | d35a133 | 2016-03-02 10:38:07 -0800 | [diff] [blame] | 82 | return rest_client.ResponseBody(resp, body) |