blob: 6e5fd31502f3bbe8e1b18c6eb32988fe7f0d72e6 [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"""
zhuflba3edec2016-09-07 17:07:32 +080017http://developer.openstack.org/api-ref/identity/v3/index.html#credentials
Yaroslav Lobankov17e8c852015-11-09 14:03:50 +030018"""
19
Matthew Treinish21905512015-07-13 10:33:35 -040020from oslo_serialization import jsonutils as json
ghanshyam135a50a2016-08-01 16:03:48 +090021from six.moves.urllib import parse as urllib
nayna-patel914b4712013-07-16 08:29:05 +000022
Ken'ichi Ohmichid35a1332016-03-02 10:38:07 -080023from tempest.lib.common import rest_client
nayna-patel914b4712013-07-16 08:29:05 +000024
25
Ken'ichi Ohmichid35a1332016-03-02 10:38:07 -080026class CredentialsClient(rest_client.RestClient):
ghanshyamd26b5cd2015-02-09 14:48:58 +090027 api_version = "v3"
nayna-patel914b4712013-07-16 08:29:05 +000028
Yaroslav Lobankov17e8c852015-11-09 14:03:50 +030029 def create_credential(self, **kwargs):
30 """Creates a credential.
31
OTSUKA, Yuanyingfaac5712016-09-15 13:53:55 +090032 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 Lobankov17e8c852015-11-09 14:03:50 +030035 """
36 post_body = json.dumps({'credential': kwargs})
Valeriy Ponomaryov88686d82014-02-16 12:24:51 +020037 resp, body = self.post('credentials', post_body)
David Kranz2aaf5312014-08-29 09:22:10 -040038 self.expected_success(201, resp.status)
nayna-patel914b4712013-07-16 08:29:05 +000039 body = json.loads(body)
Ken'ichi Ohmichid35a1332016-03-02 10:38:07 -080040 return rest_client.ResponseBody(resp, body)
nayna-patel914b4712013-07-16 08:29:05 +000041
42 def update_credential(self, credential_id, **kwargs):
Yaroslav Lobankov17e8c852015-11-09 14:03:50 +030043 """Updates a credential.
44
OTSUKA, Yuanyingfaac5712016-09-15 13:53:55 +090045 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 Lobankov17e8c852015-11-09 14:03:50 +030048 """
49 post_body = json.dumps({'credential': kwargs})
Valeriy Ponomaryov88686d82014-02-16 12:24:51 +020050 resp, body = self.patch('credentials/%s' % credential_id, post_body)
David Kranz2aaf5312014-08-29 09:22:10 -040051 self.expected_success(200, resp.status)
nayna-patel914b4712013-07-16 08:29:05 +000052 body = json.loads(body)
Ken'ichi Ohmichid35a1332016-03-02 10:38:07 -080053 return rest_client.ResponseBody(resp, body)
nayna-patel914b4712013-07-16 08:29:05 +000054
lei zhangf7169e22015-11-28 22:51:36 +080055 def show_credential(self, credential_id):
ghanshyam135a50a2016-08-01 16:03:48 +090056 """To GET Details of a credential.
57
OTSUKA, Yuanyingfaac5712016-09-15 13:53:55 +090058 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
ghanshyam135a50a2016-08-01 16:03:48 +090061 """
nayna-patel914b4712013-07-16 08:29:05 +000062 resp, body = self.get('credentials/%s' % credential_id)
David Kranz2aaf5312014-08-29 09:22:10 -040063 self.expected_success(200, resp.status)
nayna-patel914b4712013-07-16 08:29:05 +000064 body = json.loads(body)
Ken'ichi Ohmichid35a1332016-03-02 10:38:07 -080065 return rest_client.ResponseBody(resp, body)
nayna-patel914b4712013-07-16 08:29:05 +000066
ghanshyam135a50a2016-08-01 16:03:48 +090067 def list_credentials(self, **params):
68 """Lists out all the available credentials.
69
OTSUKA, Yuanyingfaac5712016-09-15 13:53:55 +090070 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
ghanshyam135a50a2016-08-01 16:03:48 +090073 """
74 url = 'credentials'
75 if params:
76 url += '?%s' % urllib.urlencode(params)
77 resp, body = self.get(url)
David Kranz2aaf5312014-08-29 09:22:10 -040078 self.expected_success(200, resp.status)
nayna-patel914b4712013-07-16 08:29:05 +000079 body = json.loads(body)
Ken'ichi Ohmichid35a1332016-03-02 10:38:07 -080080 return rest_client.ResponseBody(resp, body)
nayna-patel914b4712013-07-16 08:29:05 +000081
82 def delete_credential(self, credential_id):
ghanshyam135a50a2016-08-01 16:03:48 +090083 """Deletes a credential.
84
OTSUKA, Yuanyingfaac5712016-09-15 13:53:55 +090085 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
ghanshyam135a50a2016-08-01 16:03:48 +090088 """
nayna-patel914b4712013-07-16 08:29:05 +000089 resp, body = self.delete('credentials/%s' % credential_id)
David Kranz2aaf5312014-08-29 09:22:10 -040090 self.expected_success(204, resp.status)
Ken'ichi Ohmichid35a1332016-03-02 10:38:07 -080091 return rest_client.ResponseBody(resp, body)