Moved CORS middleware configuration into oslo-config-generator

The default values needed for mistral'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 configuration parsing. This ensures
that if a value remains unset in mistral.conf, it will be set
to use sane defaults, and that an operator modifying the
configuration file will be presented with a default set of
necessary sane headers.

Change-Id: I1174fa44f316be60fdc86a4d1032ca71c9827a25
Closes-Bug: 1551836
This commit is contained in:
Michael Krotscheck 2016-03-04 06:49:21 -08:00
parent 8ad4d236ef
commit 54296b1519
3 changed files with 27 additions and 9 deletions

View File

@ -19,6 +19,7 @@ import oslo_middleware.cors as cors_middleware
import pecan
from mistral.api import access_control
from mistral import config as m_config
from mistral import context as ctx
from mistral import coordination
from mistral.db.v2 import api as db_api_v2
@ -44,6 +45,7 @@ def get_pecan_config():
def setup_app(config=None):
if not config:
config = get_pecan_config()
m_config.set_config_defaults()
app_conf = dict(config.app)
@ -66,14 +68,5 @@ def setup_app(config=None):
# Create a CORS wrapper, and attach mistral-specific defaults that must be
# included in all CORS responses.
app = cors_middleware.CORS(app, cfg.CONF)
app.set_latent(
allow_headers=['X-Auth-Token', 'X-Identity-Status', 'X-Roles',
'X-Service-Catalog', 'X-User-Id', 'X-Tenant-Id'
'X-Project-Id', 'X-User-Name', 'X-Project-Name'],
allow_methods=['GET', 'PUT', 'POST', 'DELETE', 'PATCH'],
expose_headers=['X-Auth-Token', 'X-Subject-Token',
'X-Service-Token', 'X-Project-Id', 'X-User-Name',
'X-Project-Name']
)
return app

View File

@ -22,6 +22,7 @@ import itertools
from oslo_config import cfg
from oslo_log import log
from oslo_middleware import cors
from mistral import version
@ -186,3 +187,24 @@ def parse_args(args=None, usage=None, default_config_files=None):
usage=usage,
default_config_files=default_config_files
)
def set_config_defaults():
"""This method updates all configuration default values."""
set_cors_middleware_defaults()
def set_cors_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-Identity-Status', 'X-Roles',
'X-Service-Catalog', 'X-User-Id', 'X-Tenant-Id',
'X-Project-Id', 'X-User-Name', 'X-Project-Name'],
allow_methods=['GET', 'PUT', 'POST', 'DELETE', 'PATCH'],
expose_headers=['X-Auth-Token', 'X-Subject-Token',
'X-Service-Token', 'X-Project-Id', 'X-User-Name',
'X-Project-Name']
)

View File

@ -37,6 +37,9 @@ console_scripts =
oslo.config.opts =
mistral.config = mistral.config:list_opts
oslo.config.opts.defaults =
oslo.middleware.cors = mistral.config:set_cors_middleware_defaults
tempest.test_plugins =
mistral_test = mistral_tempest_tests.plugin:MistralTempestPlugin