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 | """ |
zhufl | ba3edec | 2016-09-07 17:07:32 +0800 | [diff] [blame] | 17 | http://developer.openstack.org/api-ref/identity/v3/index.html#credentials |
Yaroslav Lobankov | 17e8c85 | 2015-11-09 14:03:50 +0300 | [diff] [blame] | 18 | """ |
| 19 | |
Matthew Treinish | 2190551 | 2015-07-13 10:33:35 -0400 | [diff] [blame] | 20 | from oslo_serialization import jsonutils as json |
ghanshyam | 135a50a | 2016-08-01 16:03:48 +0900 | [diff] [blame] | 21 | from six.moves.urllib import parse as urllib |
nayna-patel | 914b471 | 2013-07-16 08:29:05 +0000 | [diff] [blame] | 22 | |
Ken'ichi Ohmichi | d35a133 | 2016-03-02 10:38:07 -0800 | [diff] [blame] | 23 | from tempest.lib.common import rest_client |
nayna-patel | 914b471 | 2013-07-16 08:29:05 +0000 | [diff] [blame] | 24 | |
| 25 | |
Ken'ichi Ohmichi | d35a133 | 2016-03-02 10:38:07 -0800 | [diff] [blame] | 26 | class CredentialsClient(rest_client.RestClient): |
ghanshyam | d26b5cd | 2015-02-09 14:48:58 +0900 | [diff] [blame] | 27 | api_version = "v3" |
nayna-patel | 914b471 | 2013-07-16 08:29:05 +0000 | [diff] [blame] | 28 | |
Yaroslav Lobankov | 17e8c85 | 2015-11-09 14:03:50 +0300 | [diff] [blame] | 29 | def create_credential(self, **kwargs): |
| 30 | """Creates a credential. |
| 31 | |
OTSUKA, Yuanying | faac571 | 2016-09-15 13:53:55 +0900 | [diff] [blame] | 32 | For a full list of available parameters, please refer to the official |
| 33 | API reference: |
| 34 | http://developer.openstack.org/api-ref/identity/v3/index.html#create-credential |
Yaroslav Lobankov | 17e8c85 | 2015-11-09 14:03:50 +0300 | [diff] [blame] | 35 | """ |
| 36 | post_body = json.dumps({'credential': kwargs}) |
Valeriy Ponomaryov | 88686d8 | 2014-02-16 12:24:51 +0200 | [diff] [blame] | 37 | resp, body = self.post('credentials', post_body) |
David Kranz | 2aaf531 | 2014-08-29 09:22:10 -0400 | [diff] [blame] | 38 | self.expected_success(201, resp.status) |
nayna-patel | 914b471 | 2013-07-16 08:29:05 +0000 | [diff] [blame] | 39 | body = json.loads(body) |
Ken'ichi Ohmichi | d35a133 | 2016-03-02 10:38:07 -0800 | [diff] [blame] | 40 | return rest_client.ResponseBody(resp, body) |
nayna-patel | 914b471 | 2013-07-16 08:29:05 +0000 | [diff] [blame] | 41 | |
| 42 | def update_credential(self, credential_id, **kwargs): |
Yaroslav Lobankov | 17e8c85 | 2015-11-09 14:03:50 +0300 | [diff] [blame] | 43 | """Updates a credential. |
| 44 | |
OTSUKA, Yuanying | faac571 | 2016-09-15 13:53:55 +0900 | [diff] [blame] | 45 | For a full list of available parameters, please refer to the official |
| 46 | API reference: |
| 47 | http://developer.openstack.org/api-ref/identity/v3/index.html#update-credential |
Yaroslav Lobankov | 17e8c85 | 2015-11-09 14:03:50 +0300 | [diff] [blame] | 48 | """ |
| 49 | post_body = json.dumps({'credential': kwargs}) |
Valeriy Ponomaryov | 88686d8 | 2014-02-16 12:24:51 +0200 | [diff] [blame] | 50 | resp, body = self.patch('credentials/%s' % credential_id, post_body) |
David Kranz | 2aaf531 | 2014-08-29 09:22:10 -0400 | [diff] [blame] | 51 | self.expected_success(200, resp.status) |
nayna-patel | 914b471 | 2013-07-16 08:29:05 +0000 | [diff] [blame] | 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) |
nayna-patel | 914b471 | 2013-07-16 08:29:05 +0000 | [diff] [blame] | 54 | |
lei zhang | f7169e2 | 2015-11-28 22:51:36 +0800 | [diff] [blame] | 55 | def show_credential(self, credential_id): |
ghanshyam | 135a50a | 2016-08-01 16:03:48 +0900 | [diff] [blame] | 56 | """To GET Details of a credential. |
| 57 | |
OTSUKA, Yuanying | faac571 | 2016-09-15 13:53:55 +0900 | [diff] [blame] | 58 | 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#show-credential-details |
ghanshyam | 135a50a | 2016-08-01 16:03:48 +0900 | [diff] [blame] | 61 | """ |
nayna-patel | 914b471 | 2013-07-16 08:29:05 +0000 | [diff] [blame] | 62 | resp, body = self.get('credentials/%s' % credential_id) |
David Kranz | 2aaf531 | 2014-08-29 09:22:10 -0400 | [diff] [blame] | 63 | self.expected_success(200, resp.status) |
nayna-patel | 914b471 | 2013-07-16 08:29:05 +0000 | [diff] [blame] | 64 | body = json.loads(body) |
Ken'ichi Ohmichi | d35a133 | 2016-03-02 10:38:07 -0800 | [diff] [blame] | 65 | return rest_client.ResponseBody(resp, body) |
nayna-patel | 914b471 | 2013-07-16 08:29:05 +0000 | [diff] [blame] | 66 | |
ghanshyam | 135a50a | 2016-08-01 16:03:48 +0900 | [diff] [blame] | 67 | def list_credentials(self, **params): |
| 68 | """Lists out all the available credentials. |
| 69 | |
OTSUKA, Yuanying | faac571 | 2016-09-15 13:53:55 +0900 | [diff] [blame] | 70 | For a full list of available parameters, please refer to the official |
| 71 | API reference: |
| 72 | http://developer.openstack.org/api-ref/identity/v3/#list-credentials |
ghanshyam | 135a50a | 2016-08-01 16:03:48 +0900 | [diff] [blame] | 73 | """ |
| 74 | url = 'credentials' |
| 75 | if params: |
| 76 | url += '?%s' % urllib.urlencode(params) |
| 77 | resp, body = self.get(url) |
David Kranz | 2aaf531 | 2014-08-29 09:22:10 -0400 | [diff] [blame] | 78 | self.expected_success(200, resp.status) |
nayna-patel | 914b471 | 2013-07-16 08:29:05 +0000 | [diff] [blame] | 79 | body = json.loads(body) |
Ken'ichi Ohmichi | d35a133 | 2016-03-02 10:38:07 -0800 | [diff] [blame] | 80 | return rest_client.ResponseBody(resp, body) |
nayna-patel | 914b471 | 2013-07-16 08:29:05 +0000 | [diff] [blame] | 81 | |
| 82 | def delete_credential(self, credential_id): |
ghanshyam | 135a50a | 2016-08-01 16:03:48 +0900 | [diff] [blame] | 83 | """Deletes a credential. |
| 84 | |
OTSUKA, Yuanying | faac571 | 2016-09-15 13:53:55 +0900 | [diff] [blame] | 85 | For a full list of available parameters, please refer to the official |
| 86 | API reference: |
| 87 | http://developer.openstack.org/api-ref/identity/v3/#delete-credential |
ghanshyam | 135a50a | 2016-08-01 16:03:48 +0900 | [diff] [blame] | 88 | """ |
nayna-patel | 914b471 | 2013-07-16 08:29:05 +0000 | [diff] [blame] | 89 | resp, body = self.delete('credentials/%s' % credential_id) |
David Kranz | 2aaf531 | 2014-08-29 09:22:10 -0400 | [diff] [blame] | 90 | self.expected_success(204, resp.status) |
Ken'ichi Ohmichi | d35a133 | 2016-03-02 10:38:07 -0800 | [diff] [blame] | 91 | return rest_client.ResponseBody(resp, body) |