Moving common objects under KeyManager.

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 <moguimar@redhat.com>
This commit is contained in:
Moisés Guimarães de Medeiros 2020-02-28 12:20:49 +01:00
parent 3ccf918c98
commit fd01ccc0f5
3 changed files with 15 additions and 24 deletions

View File

@ -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

View File

@ -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.

View File

@ -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)