From 151d8cfe3091943bf981dc401312054a459b97d2 Mon Sep 17 00:00:00 2001 From: Tin Lam Date: Wed, 2 Mar 2016 19:30:10 -0600 Subject: [PATCH] Moved CORS middleware configuration into oslo-config-generator The default values needed for murano's implementation of cors middleware have been moved from paste.ini into the configuration hooks provided by oslo.config. Furthermore, these values have been added to the default initialization procedure. This ensures that if a value remains unset in the configuration file, it will fallback to using sane defaults. It also ensures that an operator modifying the configuration will be presented with that same set of defaults. Change-Id: I50a204e27a43991d94cfb5f39c1dd3e904eb5696 Closes-Bug: #1551836 --- etc/murano/murano-paste.ini | 3 --- murano/cmd/api.py | 1 + murano/common/config.py | 26 ++++++++++++++++++++++++++ murano/common/wsgi.py | 2 ++ setup.cfg | 2 ++ 5 files changed, 31 insertions(+), 3 deletions(-) mode change 100644 => 100755 murano/cmd/api.py diff --git a/etc/murano/murano-paste.ini b/etc/murano/murano-paste.ini index e51bcaee..c93359b5 100644 --- a/etc/murano/murano-paste.ini +++ b/etc/murano/murano-paste.ini @@ -45,6 +45,3 @@ paste.filter_factory = murano.api.middleware.ext_context:ExternalContextMiddlewa [filter:cors] paste.filter_factory = oslo_middleware.cors:filter_factory oslo_config_project = murano -latent_allow_headers = X-Auth-Token, X-Openstack-Request-Id, X-Configuration-Session, X-Roles, X-User-Id, X-Tenant-Id -latent_expose_headers = X-Auth-Token, X-Openstack-Request-Id, X-Configuration-Session, X-Roles, X-User-Id, X-Tenant-Id -latent_allow_methods = GET, PUT, POST, DELETE, PATCH diff --git a/murano/cmd/api.py b/murano/cmd/api.py old mode 100644 new mode 100755 index 473979e1..8db31efc --- a/murano/cmd/api.py +++ b/murano/cmd/api.py @@ -54,6 +54,7 @@ if os.path.exists(os.path.join(root, 'murano', '__init__.py')): def main(): try: config.parse_args() + config.set_middleware_defaults() request_statistics.init_stats() policy.init() diff --git a/murano/common/config.py b/murano/common/config.py index e82d515a..d3fee5ac 100644 --- a/murano/common/config.py +++ b/murano/common/config.py @@ -15,6 +15,7 @@ from oslo_config import cfg from oslo_log import log as logging +from oslo_middleware import cors from murano.common.i18n import _ from murano import version @@ -303,3 +304,28 @@ def parse_args(args=None, usage=None, default_config_files=None): version=version.version_string, usage=usage, default_config_files=default_config_files) + + +def set_middleware_defaults(): + """Update default configuration options for oslo.middleware.""" + # CORS Defaults + # TODO(krotscheck): Update with https://review.openstack.org/#/c/285368/ + cfg.set_defaults(cors.CORS_OPTS, + allow_headers=['X-Auth-Token', + 'X-Openstack-Request-Id', + 'X-Configuration-Session', + 'X-Roles', + 'X-User-Id', + 'X-Tenant-Id'], + expose_headers=['X-Auth-Token', + 'X-Openstack-Request-Id', + 'X-Configuration-Session', + 'X-Roles', + 'X-User-Id', + 'X-Tenant-Id'], + allow_methods=['GET', + 'PUT', + 'POST', + 'DELETE', + 'PATCH'] + ) diff --git a/murano/common/wsgi.py b/murano/common/wsgi.py index 21383705..009d7e15 100644 --- a/murano/common/wsgi.py +++ b/murano/common/wsgi.py @@ -39,6 +39,7 @@ import webob.dec import webob.exc from murano.api.v1 import schemas +from murano.common import config from murano.common import exceptions from murano.common.i18n import _, _LE, _LW from murano.common import xmlutils @@ -82,6 +83,7 @@ class Service(service.Service): self._backlog = backlog if backlog else CONF.backlog self._logger = logging.getLogger('eventlet.wsgi') self.greenthread = None + config.set_middleware_defaults() super(Service, self).__init__(threads) def _get_socket(self, host, port, backlog): diff --git a/setup.cfg b/setup.cfg index 4a2f8dc8..739de517 100644 --- a/setup.cfg +++ b/setup.cfg @@ -50,6 +50,8 @@ console_scripts = oslo.config.opts = murano = murano.opts:list_opts keystone_authtoken = keystonemiddleware.opts:list_auth_token_opts +oslo.config.opts.defaults = + oslo.middleware = murano.common.config:set_middleware_defaults tempest.test_plugins = murano_tests = murano_tempest_tests.plugin:MuranoTempestPlugin