1
# vim: tabstop=4 shiftwidth=4 softtabstop=4
3
# Copyright 2011 OpenStack Foundation.
6
# Licensed under the Apache License, Version 2.0 (the "License"); you may
7
# not use this file except in compliance with the License. You may obtain
8
# a copy of the License at
10
# http://www.apache.org/licenses/LICENSE-2.0
12
# Unless required by applicable law or agreed to in writing, software
13
# distributed under the License is distributed on an "AS IS" BASIS, WITHOUT
14
# WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. See the
15
# License for the specific language governing permissions and limitations
19
Simple class that stores security context information in the web request.
21
Projects should subclass this class if they wish to enhance the request
22
context or provide additional information in their specific WSGI pipeline.
27
from heat.openstack.common import uuidutils
30
def generate_request_id():
31
return 'req-%s' % uuidutils.generate_uuid()
34
class RequestContext(object):
36
"""Helper class to represent useful information about a request context.
38
Stores information about the security context under which the user
39
accesses the system, as well as additional request information.
42
def __init__(self, auth_token=None, user=None, tenant=None, is_admin=False,
43
read_only=False, show_deleted=False, request_id=None):
44
self.auth_token = auth_token
47
self.is_admin = is_admin
48
self.read_only = read_only
49
self.show_deleted = show_deleted
51
request_id = generate_request_id()
52
self.request_id = request_id
55
return {'user': self.user,
56
'tenant': self.tenant,
57
'is_admin': self.is_admin,
58
'read_only': self.read_only,
59
'show_deleted': self.show_deleted,
60
'auth_token': self.auth_token,
61
'request_id': self.request_id}
64
def get_admin_context(show_deleted="no"):
65
context = RequestContext(None,
68
show_deleted=show_deleted)
72
def get_context_from_function_and_args(function, args, kwargs):
73
"""Find an arg of type RequestContext and return it.
75
This is useful in a couple of decorators where we don't
76
know much about the function we're wrapping.
79
for arg in itertools.chain(kwargs.values(), args):
80
if isinstance(arg, RequestContext):