1
# vim: tabstop=4 shiftwidth=4 softtabstop=4
3
# Copyright 2012 OpenStack LLC
5
# Licensed under the Apache License, Version 2.0 (the "License"); you may
6
# not use this file except in compliance with the License. You may obtain
7
# a copy of the License at
9
# http://www.apache.org/licenses/LICENSE-2.0
11
# Unless required by applicable law or agreed to in writing, software
12
# distributed under the License is distributed on an "AS IS" BASIS, WITHOUT
13
# WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. See the
14
# License for the specific language governing permissions and limitations
17
An in memory implementation of the trusts API.
18
only to be used for testing purposes
24
from keystone.common import kvs
25
from keystone.openstack.common import timeutils
26
from keystone import exception
27
from keystone import trust
30
def _filter_trust(ref):
33
if ref.get('expires_at') and timeutils.utcnow() > ref['expires_at']:
35
ref = copy.deepcopy(ref)
39
class Trust(kvs.Base, trust.Driver):
40
def create_trust(self, trust_id, trust, roles):
42
trust_ref['id'] = trust_id
43
trust_ref['deleted'] = False
44
trust_ref['roles'] = roles
45
if (trust_ref.get('expires_at') and
46
trust_ref['expires_at'].tzinfo is not None):
47
trust_ref['expires_at'] = (timeutils.normalize_time
48
(trust_ref['expires_at']))
50
self.db.set('trust-%s' % trust_id, trust_ref)
51
trustee_user_id = trust_ref['trustee_user_id']
52
trustee_list = self.db.get('trustee-%s' % trustee_user_id, [])
53
trustee_list.append(trust_id)
54
self.db.set('trustee-%s' % trustee_user_id, trustee_list)
55
trustor_user_id = trust_ref['trustor_user_id']
56
trustor_list = self.db.get('trustor-%s' % trustor_user_id, [])
57
trustor_list.append(trust_id)
58
self.db.set('trustor-%s' % trustor_user_id, trustor_list)
59
return copy.deepcopy(trust_ref)
61
def get_trust(self, trust_id):
63
ref = self.db.get('trust-%s' % trust_id)
64
return _filter_trust(ref)
65
except exception.NotFound:
68
def delete_trust(self, trust_id):
70
ref = self.db.get('trust-%s' % trust_id)
71
except exception.NotFound:
72
raise exception.TrustNotFound(token_id=token_id)
74
self.db.set('trust-%s' % trust_id, ref)
76
def list_trusts(self):
78
for key, value in self.db.items():
79
if key.startswith("trust-") and not value['deleted']:
83
def list_trusts_for_trustee(self, trustee_user_id):
85
for trust in self.db.get('trustee-%s' % trustee_user_id, []):
86
trusts.append(self.get_trust(trust))
89
def list_trusts_for_trustor(self, trustor_user_id):
91
for trust in self.db.get('trustor-%s' % trustor_user_id, []):
92
trusts.append(self.get_trust(trust))