From 21d8f30858a443bf5c86b4930cde599cbeaa00f8 Mon Sep 17 00:00:00 2001 From: Endre Karlson Date: Thu, 9 Oct 2014 14:58:35 +0200 Subject: [PATCH] Switch to oslo.middleware and remove deprecated incubator Change-Id: I6844cb342f16fa40896fcfcc3411ad2deecce738 --- designate/api/middleware.py | 12 ++-- .../openstack/common/middleware/__init__.py | 0 designate/openstack/common/middleware/base.py | 56 ------------------- .../openstack/common/middleware/request_id.py | 44 --------------- etc/designate/api-paste.ini | 2 +- openstack-common.conf | 2 - requirements.txt | 1 + 7 files changed, 8 insertions(+), 109 deletions(-) delete mode 100644 designate/openstack/common/middleware/__init__.py delete mode 100644 designate/openstack/common/middleware/base.py delete mode 100644 designate/openstack/common/middleware/request_id.py diff --git a/designate/api/middleware.py b/designate/api/middleware.py index 4f29564b3..e3d0e26ff 100644 --- a/designate/api/middleware.py +++ b/designate/api/middleware.py @@ -17,15 +17,15 @@ import flask import webob.dec from oslo.config import cfg from oslo import messaging +from oslo.middleware import base +from oslo.middleware import request_id from oslo.serialization import jsonutils as json from oslo.utils import strutils from designate import exceptions from designate import notifications -from designate import wsgi from designate import context 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 _LW from designate.i18n import _LE @@ -59,7 +59,7 @@ def auth_pipeline_factory(loader, global_conf, **local_conf): return app -class ContextMiddleware(wsgi.Middleware): +class ContextMiddleware(base.Middleware): def make_context(self, request, *args, **kwargs): req_id = request.environ.get(request_id.ENV_REQUEST_ID) kwargs.setdefault('request_id', req_id) @@ -160,7 +160,7 @@ class TestContextMiddleware(ContextMiddleware): all_tenants=all_tenants) -class MaintenanceMiddleware(wsgi.Middleware): +class MaintenanceMiddleware(base.Middleware): def __init__(self, application): super(MaintenanceMiddleware, self).__init__(application) @@ -185,7 +185,7 @@ class MaintenanceMiddleware(wsgi.Middleware): return flask.Response(status=503, headers={'Retry-After': 60}) -class NormalizeURIMiddleware(wsgi.Middleware): +class NormalizeURIMiddleware(base.Middleware): @webob.dec.wsgify def __call__(self, request): # Remove any trailing /'s. @@ -194,7 +194,7 @@ class NormalizeURIMiddleware(wsgi.Middleware): return request.get_response(self.application) -class FaultWrapperMiddleware(wsgi.Middleware): +class FaultWrapperMiddleware(base.Middleware): def __init__(self, application): super(FaultWrapperMiddleware, self).__init__(application) diff --git a/designate/openstack/common/middleware/__init__.py b/designate/openstack/common/middleware/__init__.py deleted file mode 100644 index e69de29bb..000000000 diff --git a/designate/openstack/common/middleware/base.py b/designate/openstack/common/middleware/base.py deleted file mode 100644 index 464a1ccd7..000000000 --- a/designate/openstack/common/middleware/base.py +++ /dev/null @@ -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) diff --git a/designate/openstack/common/middleware/request_id.py b/designate/openstack/common/middleware/request_id.py deleted file mode 100644 index 1f53cec96..000000000 --- a/designate/openstack/common/middleware/request_id.py +++ /dev/null @@ -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 diff --git a/etc/designate/api-paste.ini b/etc/designate/api-paste.ini index 6fd5a7b88..70937b83e 100644 --- a/etc/designate/api-paste.ini +++ b/etc/designate/api-paste.ini @@ -24,7 +24,7 @@ keystone = request_id faultwrapper authtoken keystonecontext maintenance normali paste.app_factory = designate.api.v2:factory [filter:request_id] -paste.filter_factory = designate.openstack.common.middleware.request_id:RequestIdMiddleware.factory +paste.filter_factory = oslo.middleware:RequestId.factory [filter:noauthcontext] paste.filter_factory = designate.api.middleware:NoAuthContextMiddleware.factory diff --git a/openstack-common.conf b/openstack-common.conf index ef885ef55..fedb794e3 100644 --- a/openstack-common.conf +++ b/openstack-common.conf @@ -9,8 +9,6 @@ module=fixture.config module=local module=lockutils module=log -module=middleware.base -module=middleware.request_id module=policy module=processutils module=service diff --git a/requirements.txt b/requirements.txt index d6564b80e..80570fb86 100644 --- a/requirements.txt +++ b/requirements.txt @@ -14,6 +14,7 @@ lockfile>=0.8 netaddr>=0.7.12 oslo.config>=1.4.0 # Apache-2.0 oslo.messaging>=1.4.0 +oslo.middleware>=0.1.0 # Apache-2.0 oslo.rootwrap>=1.3.0 oslo.serialization>=1.0.0 # Apache-2.0 oslo.utils>=1.0.0 # Apache-2.0