deb-murano/murano/api/middleware/context.py
Doug Hellmann 21a14acba4 Drop use of 'oslo' namespace package
The Oslo libraries have moved all of their code out of the 'oslo'
namespace package into per-library packages. The namespace package was
retained during kilo for backwards compatibility, but will be removed by
the liberty-2 milestone. This change removes the use of the namespace
package, replacing it with the new package names.

The patches in the libraries will be put on hold until application
patches have landed, or L2, whichever comes first. At that point, new
versions of the libraries without namespace packages will be released as
a major version update.

Please merge this patch, or an equivalent, before L2 to avoid problems
with those library releases.

Blueprint: remove-namespace-packages
https://blueprints.launchpad.net/oslo-incubator/+spec/remove-namespace-packages

Change-Id: I975592f3694be42d52685ebf606f6d3012caf1a8
2015-04-28 20:21:22 +00:00

60 lines
2.0 KiB
Python

# Copyright (c) 2013 Mirantis, Inc.
#
# Licensed under the Apache License, Version 2.0 (the "License"); you may
# not use this file except in compliance with the License. You may obtain
# a copy of the License at
#
# http://www.apache.org/licenses/LICENSE-2.0
#
# Unless required by applicable law or agreed to in writing, software
# distributed under the License is distributed on an "AS IS" BASIS, WITHOUT
# WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. See the
# License for the specific language governing permissions and limitations
# under the License.
from oslo_config import cfg
from murano.common.i18n import _
from murano.common import wsgi
import murano.context
import murano.openstack.common.log as logging
context_opts = [
cfg.StrOpt('admin_role', default='admin',
help=_('Role used to identify an authenticated user as '
'administrator.'))]
CONF = cfg.CONF
CONF.register_opts(context_opts)
LOG = logging.getLogger(__name__)
CONF = cfg.CONF
class ContextMiddleware(wsgi.Middleware):
def process_request(self, req):
"""Convert authentication information into a request context
Generate a murano.context.RequestContext object from the available
authentication headers and store on the 'context' attribute
of the req object.
:param req: wsgi request object that will be given the context object
"""
roles = [r.strip() for r in req.headers.get('X-Roles').split(',')]
kwargs = {
'user': req.headers.get('X-User-Id'),
'tenant': req.headers.get('X-Tenant-Id'),
'auth_token': req.headers.get('X-Auth-Token'),
'session': req.headers.get('X-Configuration-Session'),
'is_admin': CONF.admin_role in roles,
'roles': roles
}
req.context = murano.context.RequestContext(**kwargs)
@classmethod
def factory(cls, global_conf, **local_conf):
def filter(app):
return cls(app)
return filter