From cbe7232aac2869bc91370288be1f52cfdb2cf104 Mon Sep 17 00:00:00 2001 From: Alex Kavanagh Date: Thu, 23 Jun 2016 13:48:39 +0000 Subject: [PATCH] Initial commit of basic softhsm plugin charm This is a barebones charm (as part of this commit) which only connects to the prinical barbican charm and announces its name (as softhsm). Next steps are to install and configure the software for the softhsm and determine what should go across the charm relation. --- .gitignore | 6 +++ copyright | 13 ++++++ requirements.txt | 2 + src/layer.yaml | 1 + src/lib/charm/openstack/softhsm_plugin.py | 37 +++++++++++++++++ src/metadata.yaml | 18 +++++++++ src/reactive/handlers.py | 19 +++++++++ test-requirements.txt | 6 +++ tox.ini | 49 +++++++++++++++++++++++ 9 files changed, 151 insertions(+) create mode 100644 .gitignore create mode 100644 copyright create mode 100644 requirements.txt create mode 100644 src/layer.yaml create mode 100644 src/lib/charm/openstack/softhsm_plugin.py create mode 100644 src/metadata.yaml create mode 100644 src/reactive/handlers.py create mode 100644 test-requirements.txt create mode 100644 tox.ini diff --git a/.gitignore b/.gitignore new file mode 100644 index 0000000..53bfadc --- /dev/null +++ b/.gitignore @@ -0,0 +1,6 @@ +build +.tox +layers +interfaces +trusty +.testrepository diff --git a/copyright b/copyright new file mode 100644 index 0000000..c9349ff --- /dev/null +++ b/copyright @@ -0,0 +1,13 @@ +Copyright 2016 Canonical Ltd. + +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. diff --git a/requirements.txt b/requirements.txt new file mode 100644 index 0000000..96d5c76 --- /dev/null +++ b/requirements.txt @@ -0,0 +1,2 @@ +charm-tools +simplejson diff --git a/src/layer.yaml b/src/layer.yaml new file mode 100644 index 0000000..14240f8 --- /dev/null +++ b/src/layer.yaml @@ -0,0 +1 @@ +includes: ['layer:openstack', 'interface:barbican-hsm-plugin'] diff --git a/src/lib/charm/openstack/softhsm_plugin.py b/src/lib/charm/openstack/softhsm_plugin.py new file mode 100644 index 0000000..8b035a1 --- /dev/null +++ b/src/lib/charm/openstack/softhsm_plugin.py @@ -0,0 +1,37 @@ +import charms_openstack.charm +import charms_openstack.adapters + + +def install(): + """Use the singleton from the BarbicanSoftHSMCharm to install the packages + on the unit + """ + BarbicanSoftHSMCharm.singleton.install() + + +class BarbicanSoftHSMCharm(charms_openstack.charm.OpenStackCharm): + + service_name = 'barbican-softhsm' + name = 'softhsm' + release = 'mitaka' + + # Packages that the service needs installed + packages = [] + + # Init services the charm manages + services = [] + + # Standard interface adapters class to use. + adapters_class = charms_openstack.adapters.OpenStackRelationAdapters + + # Ports that need exposing + default_service = '' + api_ports = {} + + # Database sync command (if needed) + sync_cmd = [] + + # The restart map defines which services should be restarted when a given + # file changes + restart_map = { + } diff --git a/src/metadata.yaml b/src/metadata.yaml new file mode 100644 index 0000000..f461cef --- /dev/null +++ b/src/metadata.yaml @@ -0,0 +1,18 @@ +name: barbican-softhsm-plugin +summary: The softhsm security module for the barbican charm service +maintainer: OpenStack Charmers +subordinate: true +description: | + Barbican provides a secure storage for keys and other secrets and + additionally has features to provide certificates to OpenStack applications. + The barbican-softhsm-plugin is for testing purposes only, and demonstrates + the barbican-hsm-plugin interface for interfacing real HSM providers with + Barbican. +provides: + hsm: + interface: barbican-hsm-plugin + scope: container +requires: + juju-info: + interface: juju-info + scope: container diff --git a/src/reactive/handlers.py b/src/reactive/handlers.py new file mode 100644 index 0000000..7a69eeb --- /dev/null +++ b/src/reactive/handlers.py @@ -0,0 +1,19 @@ +import charms.reactive as reactive +import charmhelpers.core.hookenv as hookenv + +# This charm's library contains all of the handler code associated with +# congress +import charm.openstack.softhsm_plugin as softhsm_plugin + + +# use a synthetic state to ensure that it get it to be installed independent of +# the install hook. +@reactive.when_not('charm.installed') +def install_packages(): + softhsm_plugin.install() + reactive.set_state('charm.installed') + +@reactive.when('hsm.connected') +def hsm_connected(hsm): + hookenv.log("Setting my name to softhsm") + hsm.set_name('softhsm') diff --git a/test-requirements.txt b/test-requirements.txt new file mode 100644 index 0000000..362199a --- /dev/null +++ b/test-requirements.txt @@ -0,0 +1,6 @@ +flake8>=2.2.4,<=2.4.1 +os-testr>=0.4.1 +charms.reactive +mock>=1.2 +coverage>=3.6 +git+https://github.com/ajkavanagh/charm.openstack#egg=charms-openstack diff --git a/tox.ini b/tox.ini new file mode 100644 index 0000000..b770176 --- /dev/null +++ b/tox.ini @@ -0,0 +1,49 @@ +[tox] +skipsdist = True +envlist = generate +skip_missing_interpreters = True + +[testenv] +setenv = VIRTUAL_ENV={envdir} + PYTHONHASHSEED=0 + TERM=linux + INTERFACE_PATH={toxinidir}/interfaces + LAYER_PATH={toxinidir}/layers + INTERFACE_PATH={toxinidir}/interfaces + JUJU_REPOSITORY={toxinidir}/build +passenv = http_proxy https_proxy +install_command = + pip install {opts} {packages} +deps = + -r{toxinidir}/requirements.txt + +[testenv:build] +basepython = python2.7 +commands = + charm-build --log-level DEBUG -o {toxinidir}/build src {posargs} + +[testenv:py27] +basepython = python2.7 +deps = -r{toxinidir}/test-requirements.txt +commands = ostestr {posargs} + +[testenv:py34] +basepython = python3.4 +deps = -r{toxinidir}/test-requirements.txt +commands = ostestr {posargs} + +[testenv:py35] +basepython = python3.5 +deps = -r{toxinidir}/test-requirements.txt +commands = ostestr {posargs} + +[testenv:lint] +basepython = python2.7 +deps = -r{toxinidir}/test-requirements.txt +commands = flake8 {posargs} src unit_tests + +[testenv:venv] +commands = {posargs} + +[flake8] +ignore = E402,E226