From fd01ccc0f51fe37d36702923e0ddb30591dc64ef Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Mois=C3=A9s=20Guimar=C3=A3es=20de=20Medeiros?= Date: Fri, 28 Feb 2020 12:20:49 +0100 Subject: [PATCH] Moving common objects under KeyManager. MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit Both Barbican and Vault backends have this replicated code. Let's centralize it to reduce code duplication. Change-Id: I365a6d3031695ee369664c00a61816c77792f2e2 Signed-off-by: Moisés Guimarães de Medeiros --- castellan/key_manager/barbican_key_manager.py | 13 ------------- castellan/key_manager/key_manager.py | 15 +++++++++++++++ castellan/key_manager/vault_key_manager.py | 11 ----------- 3 files changed, 15 insertions(+), 24 deletions(-) diff --git a/castellan/key_manager/barbican_key_manager.py b/castellan/key_manager/barbican_key_manager.py index 9545c1a1..892da26a 100644 --- a/castellan/key_manager/barbican_key_manager.py +++ b/castellan/key_manager/barbican_key_manager.py @@ -33,11 +33,6 @@ from oslo_utils import excutils from castellan.common import exception from castellan.common.objects import key as key_base_class from castellan.common.objects import opaque_data as op_data -from castellan.common.objects import passphrase -from castellan.common.objects import private_key as pri_key -from castellan.common.objects import public_key as pub_key -from castellan.common.objects import symmetric_key as sym_key -from castellan.common.objects import x_509 from castellan.i18n import _ from castellan.key_manager import key_manager @@ -86,14 +81,6 @@ LOG = logging.getLogger(__name__) class BarbicanKeyManager(key_manager.KeyManager): """Key Manager Interface that wraps the Barbican client API.""" - _secret_type_dict = { - op_data.OpaqueData: 'opaque', - passphrase.Passphrase: 'passphrase', - pri_key.PrivateKey: 'private', - pub_key.PublicKey: 'public', - sym_key.SymmetricKey: 'symmetric', - x_509.X509: 'certificate'} - def __init__(self, configuration): self._barbican_client = None self._base_url = None diff --git a/castellan/key_manager/key_manager.py b/castellan/key_manager/key_manager.py index 7a29b096..028f58b0 100644 --- a/castellan/key_manager/key_manager.py +++ b/castellan/key_manager/key_manager.py @@ -19,6 +19,13 @@ Key manager API import abc +from castellan.common.objects import opaque_data as op_data +from castellan.common.objects import passphrase +from castellan.common.objects import private_key as pri_key +from castellan.common.objects import public_key as pub_key +from castellan.common.objects import symmetric_key as sym_key +from castellan.common.objects import x_509 + class KeyManager(object, metaclass=abc.ABCMeta): """Base Key Manager Interface @@ -27,6 +34,14 @@ class KeyManager(object, metaclass=abc.ABCMeta): Key Manager is responsible for creating, reading, and deleting keys. """ + _secret_type_dict = { + op_data.OpaqueData: "opaque", + passphrase.Passphrase: "passphrase", + pri_key.PrivateKey: "private", + pub_key.PublicKey: "public", + sym_key.SymmetricKey: "symmetric", + x_509.X509: "certificate"} + @abc.abstractmethod def __init__(self, configuration): """Instantiate a KeyManager object. diff --git a/castellan/key_manager/vault_key_manager.py b/castellan/key_manager/vault_key_manager.py index f198ffe8..2510f2db 100644 --- a/castellan/key_manager/vault_key_manager.py +++ b/castellan/key_manager/vault_key_manager.py @@ -33,12 +33,9 @@ from oslo_utils import timeutils import requests from castellan.common import exception -from castellan.common.objects import opaque_data as op_data -from castellan.common.objects import passphrase from castellan.common.objects import private_key as pri_key from castellan.common.objects import public_key as pub_key from castellan.common.objects import symmetric_key as sym_key -from castellan.common.objects import x_509 from castellan.i18n import _ from castellan.key_manager import key_manager @@ -83,14 +80,6 @@ LOG = logging.getLogger(__name__) class VaultKeyManager(key_manager.KeyManager): """Key Manager Interface that wraps the Vault REST API.""" - _secret_type_dict = { - op_data.OpaqueData: 'opaque', - passphrase.Passphrase: 'passphrase', - pri_key.PrivateKey: 'private', - pub_key.PublicKey: 'public', - sym_key.SymmetricKey: 'symmetric', - x_509.X509: 'certificate'} - def __init__(self, configuration): self._conf = configuration self._conf.register_opts(_vault_opts, group=_VAULT_OPT_GROUP)