1 # Copyright 2011-2014 OpenStack Foundation
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
8 # http://www.apache.org/licenses/LICENSE-2.0
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
16 from oslo_context import context
18 from escalator.api import policy
21 class RequestContext(context.RequestContext):
22 """Stores information about the security context.
24 Stores how the user accesses the system, as well as additional request
29 def __init__(self, roles=None,
30 owner_is_tenant=True, service_catalog=None,
31 policy_enforcer=None, **kwargs):
32 super(RequestContext, self).__init__(**kwargs)
33 self.roles = roles or []
34 self.owner_is_tenant = owner_is_tenant
35 self.service_catalog = service_catalog
36 self.policy_enforcer = policy_enforcer or policy.Enforcer()
38 self.is_admin = self.policy_enforcer.check_is_admin(self)
41 d = super(RequestContext, self).to_dict()
44 'service_catalog': self.service_catalog,
49 def from_dict(cls, values):
54 """Return the owner to correlate with an image."""
55 return self.tenant if self.owner_is_tenant else self.user
58 def can_see_deleted(self):
59 """Admins can see deleted by default"""
60 return self.show_deleted or self.is_admin