blob: a0fbb76c65b3250a9ae5688e1a607915724d4735 [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})
43 resp, body = self.post('credentials', post_body,
44 self.headers)
45 body = json.loads(body)
46 body['credential']['blob'] = json.loads(body['credential']['blob'])
47 return resp, body['credential']
48
49 def update_credential(self, credential_id, **kwargs):
50 """Updates a credential."""
51 resp, body = self.get_credential(credential_id)
52 cred_type = kwargs.get('type', body['type'])
53 access_key = kwargs.get('access_key', body['blob']['access'])
54 secret_key = kwargs.get('secret_key', body['blob']['secret'])
55 project_id = kwargs.get('project_id', body['project_id'])
56 user_id = kwargs.get('user_id', body['user_id'])
57 blob = "{\"access\": \"%s\", \"secret\": \"%s\"}" % (
58 access_key, secret_key)
59 post_body = {
60 "blob": blob,
61 "project_id": project_id,
62 "type": cred_type,
63 "user_id": user_id
64 }
65 post_body = json.dumps({'credential': post_body})
66 resp, body = self.patch('credentials/%s' % credential_id, post_body,
67 self.headers)
68 body = json.loads(body)
69 body['credential']['blob'] = json.loads(body['credential']['blob'])
70 return resp, body['credential']
71
72 def get_credential(self, credential_id):
73 """To GET Details of a credential."""
74 resp, body = self.get('credentials/%s' % credential_id)
75 body = json.loads(body)
76 body['credential']['blob'] = json.loads(body['credential']['blob'])
77 return resp, body['credential']
78
79 def list_credentials(self):
80 """Lists out all the available credentials."""
81 resp, body = self.get('credentials')
82 body = json.loads(body)
83 return resp, body['credentials']
84
85 def delete_credential(self, credential_id):
86 """Deletes a credential."""
87 resp, body = self.delete('credentials/%s' % credential_id)
88 return resp, body