From eab524abd873f1454e1d9620a709b93cf5c6a69c Mon Sep 17 00:00:00 2001 From: Felipe Monteiro Date: Mon, 26 Jun 2017 19:57:50 -0400 Subject: [PATCH] Oslo config integration (#1) * DECKHAND-11: Add oslo.config integration to Deckhand This commit adds oslo.config integration to Deckhand. It also creates a lot of preliminary files/configuration settings needed to run tox as well as lint and oslo-config-generator jobs. * Remove sample config file. --- .gitignore | 1 + AUTHORS | 2 + ChangeLog | 2 + README.md | 2 - README.rst | 4 ++ deckhand/__init__.py | 0 deckhand/conf/__init__.py | 0 deckhand/conf/config.py | 33 +++++++++++++ deckhand/conf/opts.py | 78 ++++++++++++++++++++++++++++++ etc/deckhand/config-generator.conf | 4 ++ requirements.txt | 5 ++ setup.cfg | 28 +++++++++++ setup.py | 27 +++++++++++ test-requirements.txt | 0 tox.ini | 24 +++++++++ 15 files changed, 208 insertions(+), 2 deletions(-) create mode 100644 AUTHORS delete mode 100644 README.md create mode 100644 README.rst create mode 100644 deckhand/__init__.py create mode 100644 deckhand/conf/__init__.py create mode 100644 deckhand/conf/config.py create mode 100644 deckhand/conf/opts.py create mode 100644 etc/deckhand/config-generator.conf create mode 100644 requirements.txt create mode 100644 setup.cfg create mode 100644 setup.py create mode 100644 test-requirements.txt create mode 100644 tox.ini diff --git a/.gitignore b/.gitignore index 7bbc71c0..849c5852 100644 --- a/.gitignore +++ b/.gitignore @@ -24,6 +24,7 @@ wheels/ *.egg-info/ .installed.cfg *.egg +etc/*.sample # PyInstaller # Usually these files are written by a python script from a template diff --git a/AUTHORS b/AUTHORS new file mode 100644 index 00000000..72dbc755 --- /dev/null +++ b/AUTHORS @@ -0,0 +1,2 @@ +Alan Meadows +Felipe Monteiro diff --git a/ChangeLog b/ChangeLog index 1da8d65a..efc5c23e 100644 --- a/ChangeLog +++ b/ChangeLog @@ -1,4 +1,6 @@ CHANGES ======= +* DECKHAND-11: Add oslo.config integration to Deckhand +* Add ChangeLog * Initial commit diff --git a/README.md b/README.md deleted file mode 100644 index 5b8433dd..00000000 --- a/README.md +++ /dev/null @@ -1,2 +0,0 @@ -# deckhand -A foundational python REST YAML processing engine providing data and secrets management to other platform services. diff --git a/README.rst b/README.rst new file mode 100644 index 00000000..089d8a0e --- /dev/null +++ b/README.rst @@ -0,0 +1,4 @@ +Deckhand +======== +A foundational python REST YAML processing engine providing data and secrets +management to other platform services. diff --git a/deckhand/__init__.py b/deckhand/__init__.py new file mode 100644 index 00000000..e69de29b diff --git a/deckhand/conf/__init__.py b/deckhand/conf/__init__.py new file mode 100644 index 00000000..e69de29b diff --git a/deckhand/conf/config.py b/deckhand/conf/config.py new file mode 100644 index 00000000..55adbed5 --- /dev/null +++ b/deckhand/conf/config.py @@ -0,0 +1,33 @@ +# Copyright 2017 AT&T Intellectual Property. All other 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 + +barbican_group = cfg.OptGroup( + name='barbican', + title='Barbican Options', + help=""" +Barbican options for allowing Deckhand to communicate with Barbican. +""") + +barbican_opts = [] + + +def register_opts(conf): + conf.register_group(barbican_group) + conf.register_opts(barbican_opts, group=barbican_group) + + +def list_opts(): + return {barbican_group: barbican_opts} diff --git a/deckhand/conf/opts.py b/deckhand/conf/opts.py new file mode 100644 index 00000000..ca0a49c3 --- /dev/null +++ b/deckhand/conf/opts.py @@ -0,0 +1,78 @@ +# Copyright 2017 AT&T Intellectual Property. All other 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. + +import collections +import importlib +import os +import pkgutil + +LIST_OPTS_FUNC_NAME = "list_opts" + + +def _tupleize(dct): + """Take the dict of options and convert to the 2-tuple format.""" + return [(key, val) for key, val in dct.items()] + + +def list_opts(): + """Entry point used only in the context of sample file generation. + + This is the single point of entry to generate the sample configuration + file for Deckhand. It collects all the necessary info from the other + modules in this package. It is assumed that: + + * every other module in this package has a 'list_opts' function which + return a dict where + * the keys are strings which are the group names + * the value of each key is a list of config options for that group + * the deckhand.conf package doesn't have further packages with config + options + """ + opts = collections.defaultdict(list) + module_names = _list_module_names() + imported_modules = _import_modules(module_names) + _append_config_options(imported_modules, opts) + return _tupleize(opts) + + +def _list_module_names(): + module_names = [] + package_path = os.path.dirname(os.path.abspath(__file__)) + for _, modname, ispkg in pkgutil.iter_modules(path=[package_path]): + if modname == "opts" or ispkg: + continue + else: + module_names.append(modname) + return module_names + + +def _import_modules(module_names): + imported_modules = [] + for modname in module_names: + mod = importlib.import_module("deckhand.conf." + modname) + if not hasattr(mod, LIST_OPTS_FUNC_NAME): + msg = "The module 'deckhand.conf.%s' should have a '%s' "\ + "function which returns the config options." % \ + (modname, LIST_OPTS_FUNC_NAME) + raise Exception(msg) + else: + imported_modules.append(mod) + return imported_modules + + +def _append_config_options(imported_modules, config_options): + for mod in imported_modules: + configs = mod.list_opts() + for key, val in configs.items(): + config_options[key].extend(val) diff --git a/etc/deckhand/config-generator.conf b/etc/deckhand/config-generator.conf new file mode 100644 index 00000000..eadbdcea --- /dev/null +++ b/etc/deckhand/config-generator.conf @@ -0,0 +1,4 @@ +[DEFAULT] +output_file = etc/deckhand/deckhand.conf.sample +wrap_width = 80 +namespace = deckhand.conf diff --git a/requirements.txt b/requirements.txt new file mode 100644 index 00000000..ec98e895 --- /dev/null +++ b/requirements.txt @@ -0,0 +1,5 @@ +# API +falcon==1.1.0 + +# Oslo +oslo.config>=3.22.0 # Apache-2.0 diff --git a/setup.cfg b/setup.cfg new file mode 100644 index 00000000..c26996ed --- /dev/null +++ b/setup.cfg @@ -0,0 +1,28 @@ +[metadata] +name = deckhand +summary = Secrets management persistence tool. +description-file = README.rst + +author = deckhand team +home-page = http://deckhand-helm.readthedocs.io/en/latest/ +classifier = + Intended Audience :: Information Technology + Intended Audience :: System Administrators + License :: OSI Approved :: Apache Software License + Operating System :: POSIX :: Linux + Programming Language :: Python + Programming Language :: Python :: 2 + Programming Language :: Python :: 2.7 + Programming Language :: Python :: 3 + Programming Language :: Python :: 3.5 + +[files] +packages = + deckhand + +[entry_points] +oslo.config.opts = + deckhand.conf = deckhand.conf.opts:list_opts + +[pbr] +warnerrors = True diff --git a/setup.py b/setup.py new file mode 100644 index 00000000..0b220f45 --- /dev/null +++ b/setup.py @@ -0,0 +1,27 @@ +# Copyright 2017 AT&T Intellectual Property. All other 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. + +import setuptools + +# In python < 2.7.4, a lazy loading of package `pbr` will break +# setuptools if some other modules registered functions in `atexit`. +# solution from: http://bugs.python.org/issue15881#msg170215 +try: + import multiprocessing # noqa +except ImportError: + pass + +setuptools.setup( + setup_requires=['pbr>=2.0.0'], + pbr=True) diff --git a/test-requirements.txt b/test-requirements.txt new file mode 100644 index 00000000..e69de29b diff --git a/tox.ini b/tox.ini new file mode 100644 index 00000000..9e2846e3 --- /dev/null +++ b/tox.ini @@ -0,0 +1,24 @@ +[tox] +envlist = py35,py27,pep8 + +[testenv] +usedevelop = True +setenv = VIRTUAL_ENV={envdir} + LANGUAGE=en_US + LC_ALL=en_US.utf-8 +deps= + -r{toxinidir}/requirements.txt + -r{toxinidir}/test-requirements.txt +whitelist_externals = flake8 + +[testenv:genconfig] +commands = oslo-config-generator --config-file=etc/deckhand/config-generator.conf + +[testenv:pep8] +commands = flake8 {posargs} + +[flake8] +# D100, D103, D104 deal with docstrings in public functions +# D205, D400, D401 deal with docstring formatting +ignore=E121,E122,E123,E124,E125,E126,E127,E128,E129,E131,E251,H405,D100,D103,D104,D205,D400,D401 +exclude=.venv,.git,.tox,dist,doc,*lib/python*,*egg,build,tools/xenserver*,releasenotes