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 | |
Matthew Treinish | 2190551 | 2015-07-13 10:33:35 -0400 | [diff] [blame] | 16 | from oslo_serialization import jsonutils as json |
nayna-patel | 914b471 | 2013-07-16 08:29:05 +0000 | [diff] [blame] | 17 | |
Ken'ichi Ohmichi | a6ac242 | 2015-01-13 01:09:39 +0000 | [diff] [blame] | 18 | from tempest.common import service_client |
nayna-patel | 914b471 | 2013-07-16 08:29:05 +0000 | [diff] [blame] | 19 | |
| 20 | |
Ken'ichi Ohmichi | a628707 | 2015-07-02 02:43:15 +0000 | [diff] [blame] | 21 | class CredentialsClient(service_client.ServiceClient): |
ghanshyam | d26b5cd | 2015-02-09 14:48:58 +0900 | [diff] [blame] | 22 | api_version = "v3" |
nayna-patel | 914b471 | 2013-07-16 08:29:05 +0000 | [diff] [blame] | 23 | |
| 24 | def create_credential(self, access_key, secret_key, user_id, project_id): |
| 25 | """Creates a credential.""" |
| 26 | blob = "{\"access\": \"%s\", \"secret\": \"%s\"}" % ( |
| 27 | access_key, secret_key) |
| 28 | post_body = { |
| 29 | "blob": blob, |
| 30 | "project_id": project_id, |
| 31 | "type": "ec2", |
| 32 | "user_id": user_id |
| 33 | } |
| 34 | post_body = json.dumps({'credential': post_body}) |
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): |
| 42 | """Updates a credential.""" |
John Warren | f3ac5cc | 2015-08-10 18:06:43 +0000 | [diff] [blame] | 43 | body = self.get_credential(credential_id)['credential'] |
nayna-patel | 914b471 | 2013-07-16 08:29:05 +0000 | [diff] [blame] | 44 | cred_type = kwargs.get('type', body['type']) |
| 45 | access_key = kwargs.get('access_key', body['blob']['access']) |
| 46 | secret_key = kwargs.get('secret_key', body['blob']['secret']) |
| 47 | project_id = kwargs.get('project_id', body['project_id']) |
| 48 | user_id = kwargs.get('user_id', body['user_id']) |
| 49 | blob = "{\"access\": \"%s\", \"secret\": \"%s\"}" % ( |
| 50 | access_key, secret_key) |
| 51 | post_body = { |
| 52 | "blob": blob, |
| 53 | "project_id": project_id, |
| 54 | "type": cred_type, |
| 55 | "user_id": user_id |
| 56 | } |
| 57 | post_body = json.dumps({'credential': post_body}) |
Valeriy Ponomaryov | 88686d8 | 2014-02-16 12:24:51 +0200 | [diff] [blame] | 58 | resp, body = self.patch('credentials/%s' % credential_id, post_body) |
David Kranz | 2aaf531 | 2014-08-29 09:22:10 -0400 | [diff] [blame] | 59 | self.expected_success(200, resp.status) |
nayna-patel | 914b471 | 2013-07-16 08:29:05 +0000 | [diff] [blame] | 60 | body = json.loads(body) |
| 61 | body['credential']['blob'] = json.loads(body['credential']['blob']) |
John Warren | f3ac5cc | 2015-08-10 18:06:43 +0000 | [diff] [blame] | 62 | return service_client.ResponseBody(resp, body) |
nayna-patel | 914b471 | 2013-07-16 08:29:05 +0000 | [diff] [blame] | 63 | |
| 64 | def get_credential(self, credential_id): |
| 65 | """To GET Details of a credential.""" |
| 66 | resp, body = self.get('credentials/%s' % credential_id) |
David Kranz | 2aaf531 | 2014-08-29 09:22:10 -0400 | [diff] [blame] | 67 | self.expected_success(200, resp.status) |
nayna-patel | 914b471 | 2013-07-16 08:29:05 +0000 | [diff] [blame] | 68 | body = json.loads(body) |
| 69 | body['credential']['blob'] = json.loads(body['credential']['blob']) |
John Warren | f3ac5cc | 2015-08-10 18:06:43 +0000 | [diff] [blame] | 70 | return service_client.ResponseBody(resp, body) |
nayna-patel | 914b471 | 2013-07-16 08:29:05 +0000 | [diff] [blame] | 71 | |
| 72 | def list_credentials(self): |
| 73 | """Lists out all the available credentials.""" |
| 74 | resp, body = self.get('credentials') |
David Kranz | 2aaf531 | 2014-08-29 09:22:10 -0400 | [diff] [blame] | 75 | self.expected_success(200, resp.status) |
nayna-patel | 914b471 | 2013-07-16 08:29:05 +0000 | [diff] [blame] | 76 | body = json.loads(body) |
John Warren | f3ac5cc | 2015-08-10 18:06:43 +0000 | [diff] [blame] | 77 | return service_client.ResponseBody(resp, body) |
nayna-patel | 914b471 | 2013-07-16 08:29:05 +0000 | [diff] [blame] | 78 | |
| 79 | def delete_credential(self, credential_id): |
| 80 | """Deletes a credential.""" |
| 81 | resp, body = self.delete('credentials/%s' % credential_id) |
David Kranz | 2aaf531 | 2014-08-29 09:22:10 -0400 | [diff] [blame] | 82 | self.expected_success(204, resp.status) |
Ken'ichi Ohmichi | a6ac242 | 2015-01-13 01:09:39 +0000 | [diff] [blame] | 83 | return service_client.ResponseBody(resp, body) |