blob: 753e96007f0f2fbfa3cee7e86179599f742015a6 [file] [log] [blame]
nayna-patel914b4712013-07-16 08:29:05 +00001# 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 Lobankov17e8c852015-11-09 14:03:50 +030016"""
17http://developer.openstack.org/api-ref-identity-v3.html#credentials-v3
18"""
19
Matthew Treinish21905512015-07-13 10:33:35 -040020from oslo_serialization import jsonutils as json
nayna-patel914b4712013-07-16 08:29:05 +000021
Ken'ichi Ohmichia6ac2422015-01-13 01:09:39 +000022from tempest.common import service_client
nayna-patel914b4712013-07-16 08:29:05 +000023
24
Ken'ichi Ohmichia6287072015-07-02 02:43:15 +000025class CredentialsClient(service_client.ServiceClient):
ghanshyamd26b5cd2015-02-09 14:48:58 +090026 api_version = "v3"
nayna-patel914b4712013-07-16 08:29:05 +000027
Yaroslav Lobankov17e8c852015-11-09 14:03:50 +030028 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 Ponomaryov88686d82014-02-16 12:24:51 +020035 resp, body = self.post('credentials', post_body)
David Kranz2aaf5312014-08-29 09:22:10 -040036 self.expected_success(201, resp.status)
nayna-patel914b4712013-07-16 08:29:05 +000037 body = json.loads(body)
38 body['credential']['blob'] = json.loads(body['credential']['blob'])
John Warrenf3ac5cc2015-08-10 18:06:43 +000039 return service_client.ResponseBody(resp, body)
nayna-patel914b4712013-07-16 08:29:05 +000040
41 def update_credential(self, credential_id, **kwargs):
Yaroslav Lobankov17e8c852015-11-09 14:03:50 +030042 """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 Ponomaryov88686d82014-02-16 12:24:51 +020048 resp, body = self.patch('credentials/%s' % credential_id, post_body)
David Kranz2aaf5312014-08-29 09:22:10 -040049 self.expected_success(200, resp.status)
nayna-patel914b4712013-07-16 08:29:05 +000050 body = json.loads(body)
51 body['credential']['blob'] = json.loads(body['credential']['blob'])
John Warrenf3ac5cc2015-08-10 18:06:43 +000052 return service_client.ResponseBody(resp, body)
nayna-patel914b4712013-07-16 08:29:05 +000053
lei zhangf7169e22015-11-28 22:51:36 +080054 def show_credential(self, credential_id):
nayna-patel914b4712013-07-16 08:29:05 +000055 """To GET Details of a credential."""
56 resp, body = self.get('credentials/%s' % credential_id)
David Kranz2aaf5312014-08-29 09:22:10 -040057 self.expected_success(200, resp.status)
nayna-patel914b4712013-07-16 08:29:05 +000058 body = json.loads(body)
59 body['credential']['blob'] = json.loads(body['credential']['blob'])
John Warrenf3ac5cc2015-08-10 18:06:43 +000060 return service_client.ResponseBody(resp, body)
nayna-patel914b4712013-07-16 08:29:05 +000061
62 def list_credentials(self):
63 """Lists out all the available credentials."""
64 resp, body = self.get('credentials')
David Kranz2aaf5312014-08-29 09:22:10 -040065 self.expected_success(200, resp.status)
nayna-patel914b4712013-07-16 08:29:05 +000066 body = json.loads(body)
John Warrenf3ac5cc2015-08-10 18:06:43 +000067 return service_client.ResponseBody(resp, body)
nayna-patel914b4712013-07-16 08:29:05 +000068
69 def delete_credential(self, credential_id):
70 """Deletes a credential."""
71 resp, body = self.delete('credentials/%s' % credential_id)
David Kranz2aaf5312014-08-29 09:22:10 -040072 self.expected_success(204, resp.status)
Ken'ichi Ohmichia6ac2422015-01-13 01:09:39 +000073 return service_client.ResponseBody(resp, body)