Moved CORS middleware configuration into oslo-config-generator

The default values needed for sahara'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: Iedcaa002ff3d40cf61168769bc3946f8c6e42b87
Closes-Bug: 1551836
This commit is contained in:
Michael Krotscheck 2016-03-02 10:26:32 -08:00
parent 7af0c16924
commit 8b4b3abdaf
5 changed files with 51 additions and 3 deletions

View File

@ -15,9 +15,6 @@ paste.app_factory = sahara.api.middleware.sahara_middleware:Router.factory
[filter:cors]
paste.filter_factory = oslo_middleware.cors:filter_factory
oslo_config_project = sahara
latent_allow_headers = X-Auth-Token, X-Identity-Status, X-Roles, X-Service-Catalog, X-User-Id, X-Tenant-Id, X-OpenStack-Request-ID
latent_expose_headers = X-Auth-Token, X-Subject-Token, X-Service-Token, X-OpenStack-Request-ID
latent_allow_methods = GET, PUT, POST, DELETE, PATCH
[filter:request_id]
paste.filter_factory = oslo_middleware.request_id:RequestId.factory

View File

46
sahara/common/config.py Normal file
View File

@ -0,0 +1,46 @@
# Copyright (c) 2016 Hewlett Packard Enterprise Development Corporation, LP
#
# 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 oslo_middleware import cors
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-OpenStack-Request-ID'],
expose_headers=['X-Auth-Token',
'X-Subject-Token',
'X-Service-Token',
'X-OpenStack-Request-ID'],
allow_methods=['GET',
'PUT',
'POST',
'DELETE',
'PATCH']
)

View File

@ -23,6 +23,7 @@ from oslo_service import wsgi as oslo_wsgi
import stevedore
from sahara.api import acl
from sahara.common import config as common_config
from sahara import config
from sahara.i18n import _LI
from sahara.i18n import _LW
@ -79,6 +80,7 @@ def setup_common(possible_topdir, service_name):
config_files = [dev_conf]
config.parse_configs(config_files)
common_config.set_config_defaults()
log.setup(CONF, "sahara")
# Validate other configurations (that may produce logs) here

View File

@ -62,6 +62,9 @@ sahara.run.mode =
oslo.config.opts =
sahara.config = sahara.config:list_opts
oslo.config.opts.defaults =
oslo.middleware.cors = sahara.common.config:set_cors_middleware_defaults
tempest.test_plugins =
sahara_clients_scenario_tests = sahara.tests.tempest.scenario.data_processing.plugin:SaharaClientsScenarioPlugin