blob: c376979578ad5257db54664c93573996866ea993 [file] [log] [blame]
harika-vakadi40e10112013-02-08 14:38:09 +05301# 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
harika-vakadi40e10112013-02-08 14:38:09 +053017
18from tempest.common.rest_client import RestClient
Matthew Treinish684d8992014-01-30 16:27:40 +000019from tempest import config
20
21CONF = config.CONF
harika-vakadi40e10112013-02-08 14:38:09 +053022
23
24class PolicyClientJSON(RestClient):
25
Andrea Frittoli8bbdb162014-01-06 11:06:13 +000026 def __init__(self, auth_provider):
27 super(PolicyClientJSON, self).__init__(auth_provider)
Matthew Treinish684d8992014-01-30 16:27:40 +000028 self.service = CONF.identity.catalog_type
harika-vakadi40e10112013-02-08 14:38:09 +053029 self.endpoint_url = 'adminURL'
Andrea Frittoli8bbdb162014-01-06 11:06:13 +000030 self.api_version = "v3"
harika-vakadi40e10112013-02-08 14:38:09 +053031
32 def create_policy(self, blob, type):
33 """Creates a Policy."""
34 post_body = {
35 "blob": blob,
36 "type": type
37 }
38 post_body = json.dumps({'policy': post_body})
39 resp, body = self.post('policies', post_body, self.headers)
40 body = json.loads(body)
41 return resp, body['policy']
42
43 def list_policies(self):
44 """Lists the policies."""
45 resp, body = self.get('policies')
46 body = json.loads(body)
47 return resp, body['policies']
48
49 def get_policy(self, policy_id):
50 """Lists out the given policy."""
51 url = 'policies/%s' % policy_id
52 resp, body = self.get(url)
53 body = json.loads(body)
54 return resp, body['policy']
55
56 def update_policy(self, policy_id, **kwargs):
57 """Updates a policy."""
58 resp, body = self.get_policy(policy_id)
59 type = kwargs.get('type')
60 post_body = {
61 'type': type
62 }
63 post_body = json.dumps({'policy': post_body})
64 url = 'policies/%s' % policy_id
65 resp, body = self.patch(url, post_body,
66 self.headers)
67 body = json.loads(body)
68 return resp, body['policy']
69
70 def delete_policy(self, policy_id):
71 """Deletes the policy."""
72 url = "policies/%s" % policy_id
73 return self.delete(url)