From b0c0bf145acf55b4ccf6134555eeafa7183a6aac Mon Sep 17 00:00:00 2001 From: Ade Lee Date: Wed, 4 Jan 2017 12:12:57 -0500 Subject: [PATCH] Added ability to generate config file To generate use tox -e genconfig Change-Id: Ie2065f822991bf308805de7788712cdc7b31d1dc --- files/novajoin-config-generator.conf | 8 +++++ novajoin/config.py | 10 ++++++ novajoin/keystone_client.py | 6 ++++ novajoin/middleware/config.py | 48 ++++++++++++++++++++++++++++ setup.cfg | 9 ++++++ tox.ini | 6 ++++ 6 files changed, 87 insertions(+) create mode 100644 files/novajoin-config-generator.conf create mode 100644 novajoin/middleware/config.py diff --git a/files/novajoin-config-generator.conf b/files/novajoin-config-generator.conf new file mode 100644 index 0000000..aeb711e --- /dev/null +++ b/files/novajoin-config-generator.conf @@ -0,0 +1,8 @@ +[DEFAULT] +output_file = files/join.conf.sample +wrap_width = 79 +namespace = novajoin +namespace = novajoin-auth +namespace = oslo.log + + diff --git a/novajoin/config.py b/novajoin/config.py index 87647f0..e3f335c 100644 --- a/novajoin/config.py +++ b/novajoin/config.py @@ -12,6 +12,7 @@ # License for the specific language governing permissions and limitations # under the License. +import itertools import os from oslo_config import cfg @@ -105,3 +106,12 @@ def find_config_files(): CONF = cfg.CONF CONF.register_opts(service_opts) log.register_options(CONF) + + +def list_opts(): + return [ + ('DEFAULT', + itertools.chain( + service_opts, + )), + ] diff --git a/novajoin/keystone_client.py b/novajoin/keystone_client.py index 0d3e407..b6d01ab 100644 --- a/novajoin/keystone_client.py +++ b/novajoin/keystone_client.py @@ -63,6 +63,12 @@ def register_keystoneauth_opts(conf): }) +def list_keystoneauth_opts(): + return [('service_credentials', ( + ks_loading.get_auth_common_conf_options() + + ks_loading.get_auth_plugin_conf_options('password')))] + + def get_project_name(project_id): """Given a keystone project-id return the name of the project.""" # Handle case where no credentials are configured diff --git a/novajoin/middleware/config.py b/novajoin/middleware/config.py new file mode 100644 index 0000000..bbc5b40 --- /dev/null +++ b/novajoin/middleware/config.py @@ -0,0 +1,48 @@ +# Copyright 2016 Red Hat, Inc. +# +# 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_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.set_defaults( + allow_headers=['Content-MD5', + 'X-Image-Meta-Checksum', + 'X-Storage-Token', + 'Accept-Encoding', + 'X-Auth-Token', + 'X-Identity-Status', + 'X-Roles', + 'X-Service-Catalog', + 'X-User-Id', + 'X-Tenant-Id', + 'X-OpenStack-Request-ID'], + expose_headers=['X-Image-Meta-Checksum', + 'X-Auth-Token', + 'X-Subject-Token', + 'X-Service-Token', + 'X-OpenStack-Request-ID'], + allow_methods=['GET', + 'PUT', + 'POST', + 'DELETE', + 'PATCH'] + ) diff --git a/setup.cfg b/setup.cfg index a46769d..797c437 100644 --- a/setup.cfg +++ b/setup.cfg @@ -57,3 +57,12 @@ universal = 1 [pbr] skip_authors = True skip_changelog = True + +[entry_points] +oslo.config.opts = + novajoin = novajoin.config:list_opts + novajoin-auth = novajoin.keystone_client:list_keystoneauth_opts + +oslo.config.opts.defaults = + novajoin = novajoin.middleware.config:set_config_defaults + diff --git a/tox.ini b/tox.ini index 1790db6..12cc190 100644 --- a/tox.ini +++ b/tox.ini @@ -60,3 +60,9 @@ commands = {posargs} [testenv:docs] commands = sphinx-build -W -b html doc/source doc/build/html + +[testenv:genconfig] +sitepackages = False +envdir = {toxworkdir}/pep8 +commands = oslo-config-generator --config-file=files/novajoin-config-generator.conf +