-
Notifications
You must be signed in to change notification settings - Fork 8
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
This change adds a module for listing configuration options and setting their defaults. It also changes the key manager base class to incorporate a configuration during creation. By default, the key manager will continue to use the global CONF object from the oslo.config package. For the most part, this change will be backwards compatible. The one exception is the creation of sample configuration files. Previously, importing castellan was sufficient to add these options to the global configuration object. Now, these options will need to be applied by using the castellan.options.list_opts function, or adding them through other means, to create sample configuration files. Similar applies for setting configuration before instantiating a key manager. changes * adding castellan.options with list_opts and set_defaults functions * changing KeyManager abc to include a configuration option to __init__ * changing barbican and not_implemented key managers to accept configuration parameters * adding tests for set_defaults function * fixing barbican tests to accomodate new configuration parameter * adding documentation about configuration usage * adding castellan configs to oslo entry point in setup.cfg * adding a genconfig target to tox for producing a sample castellan configuration file * adding the sample configuration file to the git ignore * renaming barbican option api_version to barbican_api_version Change-Id: I86d6d7d49a893beaae6f311060ec593e0482d889 Implements: blueprint improved-configuration-options
- Loading branch information
Showing
12 changed files
with
247 additions
and
19 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,70 @@ | ||
# Copyright (c) 2015 Red Hat, Inc. | ||
# All Rights Reserved. | ||
# | ||
# 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 castellan import key_manager as km | ||
try: | ||
from castellan.key_manager import barbican_key_manager as bkm | ||
except ImportError: | ||
bkm = None | ||
|
||
|
||
def set_defaults(conf, api_class=None, barbican_endpoint=None, | ||
barbican_api_version=None): | ||
'''Set defaults for configuration values. | ||
Overrides the default options values. | ||
:param conf: Config instance in which to set default options. | ||
:param api_class: The full class name of the key manager API class. | ||
:param barbican_endpoint: Use this endpoint to connect to Barbican. | ||
:param barbican_api_version: Version of the Barbican API. | ||
''' | ||
conf.register_opts(km.key_manager_opts, group='key_manager') | ||
if bkm: | ||
conf.register_opts(bkm.barbican_opts, group=bkm.BARBICAN_OPT_GROUP) | ||
|
||
if api_class is not None: | ||
conf.set_default('api_class', api_class, group='key_manager') | ||
if bkm is not None and barbican_endpoint is not None: | ||
conf.set_default('barbican_endpoint', barbican_endpoint, | ||
group=bkm.BARBICAN_OPT_GROUP) | ||
if bkm is not None and barbican_api_version is not None: | ||
conf.set_default('barbican_api_version', barbican_api_version, | ||
group=bkm.BARBICAN_OPT_GROUP) | ||
|
||
|
||
def list_opts(): | ||
'''Returns a list of oslo.config options available in the library. | ||
The returned list includes all oslo.config options which may be registered | ||
at runtime by the library. | ||
Each element of the list is a tuple. The first element is the name of the | ||
group under which the list of elements in the second element will be | ||
registered. A group name of None corresponds to the [DEFAULT] group in | ||
config files. | ||
The purpose of this is to allow tools like the Oslo sample config file | ||
generator to discover the options exposed to users by this library. | ||
:returns: a list of (group_name, opts) tuples | ||
''' | ||
opts = [('key_manager', km.key_manager_opts)] | ||
if bkm is not None: | ||
opts.append((bkm.BARBICAN_OPT_GROUP, bkm.barbican_opts)) | ||
return opts |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,40 @@ | ||
# Copyright (c) 2015 Red Hat, Inc. | ||
# All Rights Reserved. | ||
# | ||
# 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 castellan.key_manager import barbican_key_manager as bkm | ||
from castellan import options | ||
from castellan.tests import base | ||
|
||
|
||
class TestOptions(base.TestCase): | ||
|
||
def test_set_defaults(self): | ||
conf = cfg.ConfigOpts() | ||
|
||
api_class = 'test.api.class' | ||
options.set_defaults(conf, api_class=api_class) | ||
self.assertEqual(api_class, conf.key_manager.api_class) | ||
|
||
barbican_endpoint = 'http://test-server.org:9311/' | ||
options.set_defaults(conf, barbican_endpoint=barbican_endpoint) | ||
self.assertEqual(barbican_endpoint, | ||
conf.get(bkm.BARBICAN_OPT_GROUP).barbican_endpoint) | ||
|
||
barbican_api_version = 'vSomething' | ||
options.set_defaults(conf, barbican_api_version=barbican_api_version) | ||
self.assertEqual(barbican_api_version, | ||
conf.get(bkm.BARBICAN_OPT_GROUP).barbican_api_version) |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,4 @@ | ||
[DEFAULT] | ||
output_file = etc/castellan/castellan.conf.sample | ||
wrap_width = 79 | ||
namespace = castellan.config |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters