blob: 42acd2a6ec85d5f624cea6d16ad3bc9571649dde [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 Ohmichi5e397992014-12-17 09:03:19 +000018from tempest.services.identity.v3.json import base
nayna-patel914b4712013-07-16 08:29:05 +000019
20
Ken'ichi Ohmichi5e397992014-12-17 09:03:19 +000021class CredentialsClientJSON(base.IdentityV3Client):
nayna-patel914b4712013-07-16 08:29:05 +000022
23 def create_credential(self, access_key, secret_key, user_id, project_id):
24 """Creates a credential."""
25 blob = "{\"access\": \"%s\", \"secret\": \"%s\"}" % (
26 access_key, secret_key)
27 post_body = {
28 "blob": blob,
29 "project_id": project_id,
30 "type": "ec2",
31 "user_id": user_id
32 }
33 post_body = json.dumps({'credential': post_body})
Valeriy Ponomaryov88686d82014-02-16 12:24:51 +020034 resp, body = self.post('credentials', post_body)
David Kranz2aaf5312014-08-29 09:22:10 -040035 self.expected_success(201, resp.status)
nayna-patel914b4712013-07-16 08:29:05 +000036 body = json.loads(body)
37 body['credential']['blob'] = json.loads(body['credential']['blob'])
38 return resp, body['credential']
39
40 def update_credential(self, credential_id, **kwargs):
41 """Updates a credential."""
David Kranz2aaf5312014-08-29 09:22:10 -040042 _, body = self.get_credential(credential_id)
nayna-patel914b4712013-07-16 08:29:05 +000043 cred_type = kwargs.get('type', body['type'])
44 access_key = kwargs.get('access_key', body['blob']['access'])
45 secret_key = kwargs.get('secret_key', body['blob']['secret'])
46 project_id = kwargs.get('project_id', body['project_id'])
47 user_id = kwargs.get('user_id', body['user_id'])
48 blob = "{\"access\": \"%s\", \"secret\": \"%s\"}" % (
49 access_key, secret_key)
50 post_body = {
51 "blob": blob,
52 "project_id": project_id,
53 "type": cred_type,
54 "user_id": user_id
55 }
56 post_body = json.dumps({'credential': post_body})
Valeriy Ponomaryov88686d82014-02-16 12:24:51 +020057 resp, body = self.patch('credentials/%s' % credential_id, post_body)
David Kranz2aaf5312014-08-29 09:22:10 -040058 self.expected_success(200, resp.status)
nayna-patel914b4712013-07-16 08:29:05 +000059 body = json.loads(body)
60 body['credential']['blob'] = json.loads(body['credential']['blob'])
61 return resp, body['credential']
62
63 def get_credential(self, credential_id):
64 """To GET Details of a credential."""
65 resp, body = self.get('credentials/%s' % credential_id)
David Kranz2aaf5312014-08-29 09:22:10 -040066 self.expected_success(200, resp.status)
nayna-patel914b4712013-07-16 08:29:05 +000067 body = json.loads(body)
68 body['credential']['blob'] = json.loads(body['credential']['blob'])
69 return resp, body['credential']
70
71 def list_credentials(self):
72 """Lists out all the available credentials."""
73 resp, body = self.get('credentials')
David Kranz2aaf5312014-08-29 09:22:10 -040074 self.expected_success(200, resp.status)
nayna-patel914b4712013-07-16 08:29:05 +000075 body = json.loads(body)
76 return resp, body['credentials']
77
78 def delete_credential(self, credential_id):
79 """Deletes a credential."""
80 resp, body = self.delete('credentials/%s' % credential_id)
David Kranz2aaf5312014-08-29 09:22:10 -040081 self.expected_success(204, resp.status)
nayna-patel914b4712013-07-16 08:29:05 +000082 return resp, body