From 61e581c7d852a4227df32349f922ba8873784b21 Mon Sep 17 00:00:00 2001 From: Michael Krotscheck Date: Tue, 1 Mar 2016 10:49:32 -0800 Subject: [PATCH] Added Keystone and RequestID headers to CORS middleware This patch makes use of oslo.config's genconfig hooks to add nova-specific default config values to the generated configuration. It also adds this same method to nova's configuration parsing logic, to ensure that these default values are also the ones used at runtime. Closes-bug: 1551836 Change-Id: Ic799aea89f681ef8626e996f0357ade388f76ca9 --- nova/common/__init__.py | 0 nova/common/config.py | 40 ++++++++++++++++++++++++++++++++++++++++ nova/config.py | 4 +++- setup.cfg | 3 +++ 4 files changed, 46 insertions(+), 1 deletion(-) create mode 100644 nova/common/__init__.py create mode 100644 nova/common/config.py diff --git a/nova/common/__init__.py b/nova/common/__init__.py new file mode 100644 index 000000000000..e69de29bb2d1 diff --git a/nova/common/config.py b/nova/common/config.py new file mode 100644 index 000000000000..4f4557d0299e --- /dev/null +++ b/nova/common/config.py @@ -0,0 +1,40 @@ +# Copyright 2016 Hewlett Packard Enterprise Development Company, L.P. +# +# 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_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-Identity-Status', + 'X-Roles', + 'X-Service-Catalog', + 'X-User-Id', + 'X-Tenant-Id'], + expose_headers=['X-Auth-Token', + 'X-Openstack-Request-Id', + 'X-Subject-Token', + 'X-Service-Token'], + allow_methods=['GET', + 'PUT', + 'POST', + 'DELETE', + 'PATCH'] + ) diff --git a/nova/config.py b/nova/config.py index b9c025915a2f..7c3606475996 100644 --- a/nova/config.py +++ b/nova/config.py @@ -20,13 +20,13 @@ from oslo_config import cfg from oslo_db import options from oslo_log import log +from nova.common import config from nova.db.sqlalchemy import api as sqlalchemy_api from nova import debugger from nova import paths from nova import rpc from nova import version - CONF = cfg.CONF _DEFAULT_SQL_CONNECTION = 'sqlite:///' + paths.state_path_def('nova.sqlite') @@ -57,6 +57,8 @@ def parse_args(argv, default_config_files=None, configure_db=True, rpc.set_defaults(control_exchange='nova') cache.configure(CONF) debugger.register_cli_opts() + config.set_middleware_defaults() + CONF(argv[1:], project='nova', version=version.version_string(), diff --git a/setup.cfg b/setup.cfg index 9a3133e1f2c2..f27bb97bb6a6 100644 --- a/setup.cfg +++ b/setup.cfg @@ -36,6 +36,9 @@ oslo.config.opts = nova.virt = nova.virt.opts:list_opts nova.cache_utils = nova.cache_utils:list_opts +oslo.config.opts.defaults = + oslo.middleware = nova.common.config:set_middleware_defaults + nova.compute.monitors.cpu = virt_driver = nova.compute.monitors.cpu.virt_driver:Monitor nova.compute.resources =