Switch to oslo.middleware and remove deprecated incubator
Change-Id: I6844cb342f16fa40896fcfcc3411ad2deecce738
This commit is contained in:
parent
126d30c1d5
commit
21d8f30858
@ -17,15 +17,15 @@ import flask
|
|||||||
import webob.dec
|
import webob.dec
|
||||||
from oslo.config import cfg
|
from oslo.config import cfg
|
||||||
from oslo import messaging
|
from oslo import messaging
|
||||||
|
from oslo.middleware import base
|
||||||
|
from oslo.middleware import request_id
|
||||||
from oslo.serialization import jsonutils as json
|
from oslo.serialization import jsonutils as json
|
||||||
from oslo.utils import strutils
|
from oslo.utils import strutils
|
||||||
|
|
||||||
from designate import exceptions
|
from designate import exceptions
|
||||||
from designate import notifications
|
from designate import notifications
|
||||||
from designate import wsgi
|
|
||||||
from designate import context
|
from designate import context
|
||||||
from designate.openstack.common import log as logging
|
from designate.openstack.common import log as logging
|
||||||
from designate.openstack.common.middleware import request_id
|
|
||||||
from designate.i18n import _LI
|
from designate.i18n import _LI
|
||||||
from designate.i18n import _LW
|
from designate.i18n import _LW
|
||||||
from designate.i18n import _LE
|
from designate.i18n import _LE
|
||||||
@ -59,7 +59,7 @@ def auth_pipeline_factory(loader, global_conf, **local_conf):
|
|||||||
return app
|
return app
|
||||||
|
|
||||||
|
|
||||||
class ContextMiddleware(wsgi.Middleware):
|
class ContextMiddleware(base.Middleware):
|
||||||
def make_context(self, request, *args, **kwargs):
|
def make_context(self, request, *args, **kwargs):
|
||||||
req_id = request.environ.get(request_id.ENV_REQUEST_ID)
|
req_id = request.environ.get(request_id.ENV_REQUEST_ID)
|
||||||
kwargs.setdefault('request_id', req_id)
|
kwargs.setdefault('request_id', req_id)
|
||||||
@ -160,7 +160,7 @@ class TestContextMiddleware(ContextMiddleware):
|
|||||||
all_tenants=all_tenants)
|
all_tenants=all_tenants)
|
||||||
|
|
||||||
|
|
||||||
class MaintenanceMiddleware(wsgi.Middleware):
|
class MaintenanceMiddleware(base.Middleware):
|
||||||
def __init__(self, application):
|
def __init__(self, application):
|
||||||
super(MaintenanceMiddleware, self).__init__(application)
|
super(MaintenanceMiddleware, self).__init__(application)
|
||||||
|
|
||||||
@ -185,7 +185,7 @@ class MaintenanceMiddleware(wsgi.Middleware):
|
|||||||
return flask.Response(status=503, headers={'Retry-After': 60})
|
return flask.Response(status=503, headers={'Retry-After': 60})
|
||||||
|
|
||||||
|
|
||||||
class NormalizeURIMiddleware(wsgi.Middleware):
|
class NormalizeURIMiddleware(base.Middleware):
|
||||||
@webob.dec.wsgify
|
@webob.dec.wsgify
|
||||||
def __call__(self, request):
|
def __call__(self, request):
|
||||||
# Remove any trailing /'s.
|
# Remove any trailing /'s.
|
||||||
@ -194,7 +194,7 @@ class NormalizeURIMiddleware(wsgi.Middleware):
|
|||||||
return request.get_response(self.application)
|
return request.get_response(self.application)
|
||||||
|
|
||||||
|
|
||||||
class FaultWrapperMiddleware(wsgi.Middleware):
|
class FaultWrapperMiddleware(base.Middleware):
|
||||||
def __init__(self, application):
|
def __init__(self, application):
|
||||||
super(FaultWrapperMiddleware, self).__init__(application)
|
super(FaultWrapperMiddleware, self).__init__(application)
|
||||||
|
|
||||||
|
@ -1,56 +0,0 @@
|
|||||||
# Copyright 2011 OpenStack Foundation.
|
|
||||||
# All Rights Reserved.
|
|
||||||
#
|
|
||||||
# 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.
|
|
||||||
|
|
||||||
"""Base class(es) for WSGI Middleware."""
|
|
||||||
|
|
||||||
import webob.dec
|
|
||||||
|
|
||||||
|
|
||||||
class Middleware(object):
|
|
||||||
"""Base WSGI middleware wrapper.
|
|
||||||
|
|
||||||
These classes require an application to be initialized that will be called
|
|
||||||
next. By default the middleware will simply call its wrapped app, or you
|
|
||||||
can override __call__ to customize its behavior.
|
|
||||||
"""
|
|
||||||
|
|
||||||
@classmethod
|
|
||||||
def factory(cls, global_conf, **local_conf):
|
|
||||||
"""Factory method for paste.deploy."""
|
|
||||||
return cls
|
|
||||||
|
|
||||||
def __init__(self, application):
|
|
||||||
self.application = application
|
|
||||||
|
|
||||||
def process_request(self, req):
|
|
||||||
"""Called on each request.
|
|
||||||
|
|
||||||
If this returns None, the next application down the stack will be
|
|
||||||
executed. If it returns a response then that response will be returned
|
|
||||||
and execution will stop here.
|
|
||||||
"""
|
|
||||||
return None
|
|
||||||
|
|
||||||
def process_response(self, response):
|
|
||||||
"""Do whatever you'd like to the response."""
|
|
||||||
return response
|
|
||||||
|
|
||||||
@webob.dec.wsgify
|
|
||||||
def __call__(self, req):
|
|
||||||
response = self.process_request(req)
|
|
||||||
if response:
|
|
||||||
return response
|
|
||||||
response = req.get_response(self.application)
|
|
||||||
return self.process_response(response)
|
|
@ -1,44 +0,0 @@
|
|||||||
# Copyright (c) 2013 NEC Corporation
|
|
||||||
# All Rights Reserved.
|
|
||||||
#
|
|
||||||
# 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.
|
|
||||||
|
|
||||||
"""Middleware that ensures request ID.
|
|
||||||
|
|
||||||
It ensures to assign request ID for each API request and set it to
|
|
||||||
request environment. The request ID is also added to API response.
|
|
||||||
"""
|
|
||||||
|
|
||||||
import webob.dec
|
|
||||||
|
|
||||||
from designate.openstack.common import context
|
|
||||||
from designate.openstack.common.middleware import base
|
|
||||||
from designate.openstack.common import versionutils
|
|
||||||
|
|
||||||
|
|
||||||
ENV_REQUEST_ID = 'openstack.request_id'
|
|
||||||
HTTP_RESP_HEADER_REQUEST_ID = 'x-openstack-request-id'
|
|
||||||
|
|
||||||
|
|
||||||
@versionutils.deprecated(as_of=versionutils.deprecated.JUNO,
|
|
||||||
in_favor_of='oslo.middleware.RequestId')
|
|
||||||
class RequestIdMiddleware(base.Middleware):
|
|
||||||
|
|
||||||
@webob.dec.wsgify
|
|
||||||
def __call__(self, req):
|
|
||||||
req_id = context.generate_request_id()
|
|
||||||
req.environ[ENV_REQUEST_ID] = req_id
|
|
||||||
response = req.get_response(self.application)
|
|
||||||
if HTTP_RESP_HEADER_REQUEST_ID not in response.headers:
|
|
||||||
response.headers.add(HTTP_RESP_HEADER_REQUEST_ID, req_id)
|
|
||||||
return response
|
|
@ -24,7 +24,7 @@ keystone = request_id faultwrapper authtoken keystonecontext maintenance normali
|
|||||||
paste.app_factory = designate.api.v2:factory
|
paste.app_factory = designate.api.v2:factory
|
||||||
|
|
||||||
[filter:request_id]
|
[filter:request_id]
|
||||||
paste.filter_factory = designate.openstack.common.middleware.request_id:RequestIdMiddleware.factory
|
paste.filter_factory = oslo.middleware:RequestId.factory
|
||||||
|
|
||||||
[filter:noauthcontext]
|
[filter:noauthcontext]
|
||||||
paste.filter_factory = designate.api.middleware:NoAuthContextMiddleware.factory
|
paste.filter_factory = designate.api.middleware:NoAuthContextMiddleware.factory
|
||||||
|
@ -9,8 +9,6 @@ module=fixture.config
|
|||||||
module=local
|
module=local
|
||||||
module=lockutils
|
module=lockutils
|
||||||
module=log
|
module=log
|
||||||
module=middleware.base
|
|
||||||
module=middleware.request_id
|
|
||||||
module=policy
|
module=policy
|
||||||
module=processutils
|
module=processutils
|
||||||
module=service
|
module=service
|
||||||
|
@ -14,6 +14,7 @@ lockfile>=0.8
|
|||||||
netaddr>=0.7.12
|
netaddr>=0.7.12
|
||||||
oslo.config>=1.4.0 # Apache-2.0
|
oslo.config>=1.4.0 # Apache-2.0
|
||||||
oslo.messaging>=1.4.0
|
oslo.messaging>=1.4.0
|
||||||
|
oslo.middleware>=0.1.0 # Apache-2.0
|
||||||
oslo.rootwrap>=1.3.0
|
oslo.rootwrap>=1.3.0
|
||||||
oslo.serialization>=1.0.0 # Apache-2.0
|
oslo.serialization>=1.0.0 # Apache-2.0
|
||||||
oslo.utils>=1.0.0 # Apache-2.0
|
oslo.utils>=1.0.0 # Apache-2.0
|
||||||
|
Loading…
Reference in New Issue
Block a user