blob: 5d6632af67874f5c1545c7ed57d35b383aaf63bc [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
18from tempest.common.rest_client import RestClient
Matthew Treinish684d8992014-01-30 16:27:40 +000019from tempest import config
20
21CONF = config.CONF
nayna-patel914b4712013-07-16 08:29:05 +000022
23
24class CredentialsClientJSON(RestClient):
25
Andrea Frittoli8bbdb162014-01-06 11:06:13 +000026 def __init__(self, auth_provider):
27 super(CredentialsClientJSON, self).__init__(auth_provider)
Matthew Treinish684d8992014-01-30 16:27:40 +000028 self.service = CONF.identity.catalog_type
nayna-patel914b4712013-07-16 08:29:05 +000029 self.endpoint_url = 'adminURL'
Andrea Frittoli8bbdb162014-01-06 11:06:13 +000030 self.api_version = "v3"
nayna-patel914b4712013-07-16 08:29:05 +000031
32 def create_credential(self, access_key, secret_key, user_id, project_id):
33 """Creates a credential."""
34 blob = "{\"access\": \"%s\", \"secret\": \"%s\"}" % (
35 access_key, secret_key)
36 post_body = {
37 "blob": blob,
38 "project_id": project_id,
39 "type": "ec2",
40 "user_id": user_id
41 }
42 post_body = json.dumps({'credential': post_body})
Valeriy Ponomaryov88686d82014-02-16 12:24:51 +020043 resp, body = self.post('credentials', post_body)
nayna-patel914b4712013-07-16 08:29:05 +000044 body = json.loads(body)
45 body['credential']['blob'] = json.loads(body['credential']['blob'])
46 return resp, body['credential']
47
48 def update_credential(self, credential_id, **kwargs):
49 """Updates a credential."""
50 resp, body = self.get_credential(credential_id)
51 cred_type = kwargs.get('type', body['type'])
52 access_key = kwargs.get('access_key', body['blob']['access'])
53 secret_key = kwargs.get('secret_key', body['blob']['secret'])
54 project_id = kwargs.get('project_id', body['project_id'])
55 user_id = kwargs.get('user_id', body['user_id'])
56 blob = "{\"access\": \"%s\", \"secret\": \"%s\"}" % (
57 access_key, secret_key)
58 post_body = {
59 "blob": blob,
60 "project_id": project_id,
61 "type": cred_type,
62 "user_id": user_id
63 }
64 post_body = json.dumps({'credential': post_body})
Valeriy Ponomaryov88686d82014-02-16 12:24:51 +020065 resp, body = self.patch('credentials/%s' % credential_id, post_body)
nayna-patel914b4712013-07-16 08:29:05 +000066 body = json.loads(body)
67 body['credential']['blob'] = json.loads(body['credential']['blob'])
68 return resp, body['credential']
69
70 def get_credential(self, credential_id):
71 """To GET Details of a credential."""
72 resp, body = self.get('credentials/%s' % credential_id)
73 body = json.loads(body)
74 body['credential']['blob'] = json.loads(body['credential']['blob'])
75 return resp, body['credential']
76
77 def list_credentials(self):
78 """Lists out all the available credentials."""
79 resp, body = self.get('credentials')
80 body = json.loads(body)
81 return resp, body['credentials']
82
83 def delete_credential(self, credential_id):
84 """Deletes a credential."""
85 resp, body = self.delete('credentials/%s' % credential_id)
86 return resp, body