nayna-patel | 914b471 | 2013-07-16 08:29:05 +0000 | [diff] [blame] | 1 | # Copyright 2013 OpenStack Foundation |
| 2 | # All Rights Reserved. |
| 3 | # |
| 4 | # Licensed under the Apache License, Version 2.0 (the "License"); you may |
| 5 | # not use this file except in compliance with the License. You may obtain |
| 6 | # a copy of the License at |
| 7 | # |
| 8 | # http://www.apache.org/licenses/LICENSE-2.0 |
| 9 | # |
| 10 | # Unless required by applicable law or agreed to in writing, software |
| 11 | # distributed under the License is distributed on an "AS IS" BASIS, WITHOUT |
| 12 | # WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. See the |
| 13 | # License for the specific language governing permissions and limitations |
| 14 | # under the License. |
| 15 | |
Yaroslav Lobankov | 17e8c85 | 2015-11-09 14:03:50 +0300 | [diff] [blame] | 16 | """ |
| 17 | http://developer.openstack.org/api-ref-identity-v3.html#credentials-v3 |
| 18 | """ |
| 19 | |
Matthew Treinish | 2190551 | 2015-07-13 10:33:35 -0400 | [diff] [blame] | 20 | from oslo_serialization import jsonutils as json |
nayna-patel | 914b471 | 2013-07-16 08:29:05 +0000 | [diff] [blame] | 21 | |
Ken'ichi Ohmichi | a6ac242 | 2015-01-13 01:09:39 +0000 | [diff] [blame] | 22 | from tempest.common import service_client |
nayna-patel | 914b471 | 2013-07-16 08:29:05 +0000 | [diff] [blame] | 23 | |
| 24 | |
Ken'ichi Ohmichi | a628707 | 2015-07-02 02:43:15 +0000 | [diff] [blame] | 25 | class CredentialsClient(service_client.ServiceClient): |
ghanshyam | d26b5cd | 2015-02-09 14:48:58 +0900 | [diff] [blame] | 26 | api_version = "v3" |
nayna-patel | 914b471 | 2013-07-16 08:29:05 +0000 | [diff] [blame] | 27 | |
Yaroslav Lobankov | 17e8c85 | 2015-11-09 14:03:50 +0300 | [diff] [blame] | 28 | def create_credential(self, **kwargs): |
| 29 | """Creates a credential. |
| 30 | |
| 31 | Available params: see http://developer.openstack.org/ |
| 32 | api-ref-identity-v3.html#createCredential |
| 33 | """ |
| 34 | post_body = json.dumps({'credential': kwargs}) |
Valeriy Ponomaryov | 88686d8 | 2014-02-16 12:24:51 +0200 | [diff] [blame] | 35 | resp, body = self.post('credentials', post_body) |
David Kranz | 2aaf531 | 2014-08-29 09:22:10 -0400 | [diff] [blame] | 36 | self.expected_success(201, resp.status) |
nayna-patel | 914b471 | 2013-07-16 08:29:05 +0000 | [diff] [blame] | 37 | body = json.loads(body) |
| 38 | body['credential']['blob'] = json.loads(body['credential']['blob']) |
John Warren | f3ac5cc | 2015-08-10 18:06:43 +0000 | [diff] [blame] | 39 | return service_client.ResponseBody(resp, body) |
nayna-patel | 914b471 | 2013-07-16 08:29:05 +0000 | [diff] [blame] | 40 | |
| 41 | def update_credential(self, credential_id, **kwargs): |
Yaroslav Lobankov | 17e8c85 | 2015-11-09 14:03:50 +0300 | [diff] [blame] | 42 | """Updates a credential. |
| 43 | |
| 44 | Available params: see http://developer.openstack.org/ |
| 45 | api-ref-identity-v3.html#updateCredential |
| 46 | """ |
| 47 | post_body = json.dumps({'credential': kwargs}) |
Valeriy Ponomaryov | 88686d8 | 2014-02-16 12:24:51 +0200 | [diff] [blame] | 48 | resp, body = self.patch('credentials/%s' % credential_id, post_body) |
David Kranz | 2aaf531 | 2014-08-29 09:22:10 -0400 | [diff] [blame] | 49 | self.expected_success(200, resp.status) |
nayna-patel | 914b471 | 2013-07-16 08:29:05 +0000 | [diff] [blame] | 50 | body = json.loads(body) |
| 51 | body['credential']['blob'] = json.loads(body['credential']['blob']) |
John Warren | f3ac5cc | 2015-08-10 18:06:43 +0000 | [diff] [blame] | 52 | return service_client.ResponseBody(resp, body) |
nayna-patel | 914b471 | 2013-07-16 08:29:05 +0000 | [diff] [blame] | 53 | |
lei zhang | f7169e2 | 2015-11-28 22:51:36 +0800 | [diff] [blame] | 54 | def show_credential(self, credential_id): |
nayna-patel | 914b471 | 2013-07-16 08:29:05 +0000 | [diff] [blame] | 55 | """To GET Details of a credential.""" |
| 56 | resp, body = self.get('credentials/%s' % credential_id) |
David Kranz | 2aaf531 | 2014-08-29 09:22:10 -0400 | [diff] [blame] | 57 | self.expected_success(200, resp.status) |
nayna-patel | 914b471 | 2013-07-16 08:29:05 +0000 | [diff] [blame] | 58 | body = json.loads(body) |
| 59 | body['credential']['blob'] = json.loads(body['credential']['blob']) |
John Warren | f3ac5cc | 2015-08-10 18:06:43 +0000 | [diff] [blame] | 60 | return service_client.ResponseBody(resp, body) |
nayna-patel | 914b471 | 2013-07-16 08:29:05 +0000 | [diff] [blame] | 61 | |
| 62 | def list_credentials(self): |
| 63 | """Lists out all the available credentials.""" |
| 64 | resp, body = self.get('credentials') |
David Kranz | 2aaf531 | 2014-08-29 09:22:10 -0400 | [diff] [blame] | 65 | self.expected_success(200, resp.status) |
nayna-patel | 914b471 | 2013-07-16 08:29:05 +0000 | [diff] [blame] | 66 | body = json.loads(body) |
John Warren | f3ac5cc | 2015-08-10 18:06:43 +0000 | [diff] [blame] | 67 | return service_client.ResponseBody(resp, body) |
nayna-patel | 914b471 | 2013-07-16 08:29:05 +0000 | [diff] [blame] | 68 | |
| 69 | def delete_credential(self, credential_id): |
| 70 | """Deletes a credential.""" |
| 71 | resp, body = self.delete('credentials/%s' % credential_id) |
David Kranz | 2aaf531 | 2014-08-29 09:22:10 -0400 | [diff] [blame] | 72 | self.expected_success(204, resp.status) |
Ken'ichi Ohmichi | a6ac242 | 2015-01-13 01:09:39 +0000 | [diff] [blame] | 73 | return service_client.ResponseBody(resp, body) |