blob: 281f3cd15a61dfa884b89e076d914b95c506f5de [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
16import json
nayna-patel914b4712013-07-16 08:29:05 +000017
Ken'ichi Ohmichia6ac2422015-01-13 01:09:39 +000018from tempest.common import service_client
nayna-patel914b4712013-07-16 08:29:05 +000019
20
Ken'ichi Ohmichia6287072015-07-02 02:43:15 +000021class CredentialsClient(service_client.ServiceClient):
ghanshyamd26b5cd2015-02-09 14:48:58 +090022 api_version = "v3"
nayna-patel914b4712013-07-16 08:29:05 +000023
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 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'])
Ken'ichi Ohmichia6ac2422015-01-13 01:09:39 +000039 return service_client.ResponseBody(resp, body['credential'])
nayna-patel914b4712013-07-16 08:29:05 +000040
41 def update_credential(self, credential_id, **kwargs):
42 """Updates a credential."""
David Kranzd8ccb792014-12-29 11:32:05 -050043 body = self.get_credential(credential_id)
nayna-patel914b4712013-07-16 08:29:05 +000044 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 Ponomaryov88686d82014-02-16 12:24:51 +020058 resp, body = self.patch('credentials/%s' % credential_id, post_body)
David Kranz2aaf5312014-08-29 09:22:10 -040059 self.expected_success(200, resp.status)
nayna-patel914b4712013-07-16 08:29:05 +000060 body = json.loads(body)
61 body['credential']['blob'] = json.loads(body['credential']['blob'])
Ken'ichi Ohmichia6ac2422015-01-13 01:09:39 +000062 return service_client.ResponseBody(resp, body['credential'])
nayna-patel914b4712013-07-16 08:29:05 +000063
64 def get_credential(self, credential_id):
65 """To GET Details of a credential."""
66 resp, body = self.get('credentials/%s' % credential_id)
David Kranz2aaf5312014-08-29 09:22:10 -040067 self.expected_success(200, resp.status)
nayna-patel914b4712013-07-16 08:29:05 +000068 body = json.loads(body)
69 body['credential']['blob'] = json.loads(body['credential']['blob'])
Ken'ichi Ohmichia6ac2422015-01-13 01:09:39 +000070 return service_client.ResponseBody(resp, body['credential'])
nayna-patel914b4712013-07-16 08:29:05 +000071
72 def list_credentials(self):
73 """Lists out all the available credentials."""
74 resp, body = self.get('credentials')
David Kranz2aaf5312014-08-29 09:22:10 -040075 self.expected_success(200, resp.status)
nayna-patel914b4712013-07-16 08:29:05 +000076 body = json.loads(body)
Ken'ichi Ohmichia6ac2422015-01-13 01:09:39 +000077 return service_client.ResponseBodyList(resp, body['credentials'])
nayna-patel914b4712013-07-16 08:29:05 +000078
79 def delete_credential(self, credential_id):
80 """Deletes a credential."""
81 resp, body = self.delete('credentials/%s' % credential_id)
David Kranz2aaf5312014-08-29 09:22:10 -040082 self.expected_success(204, resp.status)
Ken'ichi Ohmichia6ac2422015-01-13 01:09:39 +000083 return service_client.ResponseBody(resp, body)