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>
Moisés Guimarães de Medeiros
3 years ago
32 | 32 |
from castellan.common import exception
|
33 | 33 |
from castellan.common.objects import key as key_base_class
|
34 | 34 |
from castellan.common.objects import opaque_data as op_data
|
35 | |
from castellan.common.objects import passphrase
|
36 | |
from castellan.common.objects import private_key as pri_key
|
37 | |
from castellan.common.objects import public_key as pub_key
|
38 | |
from castellan.common.objects import symmetric_key as sym_key
|
39 | |
from castellan.common.objects import x_509
|
40 | 35 |
from castellan.i18n import _
|
41 | 36 |
from castellan.key_manager import key_manager
|
42 | 37 |
|
|
84 | 79 |
|
85 | 80 |
class BarbicanKeyManager(key_manager.KeyManager):
|
86 | 81 |
"""Key Manager Interface that wraps the Barbican client API."""
|
87 | |
|
88 | |
_secret_type_dict = {
|
89 | |
op_data.OpaqueData: 'opaque',
|
90 | |
passphrase.Passphrase: 'passphrase',
|
91 | |
pri_key.PrivateKey: 'private',
|
92 | |
pub_key.PublicKey: 'public',
|
93 | |
sym_key.SymmetricKey: 'symmetric',
|
94 | |
x_509.X509: 'certificate'}
|
95 | 82 |
|
96 | 83 |
def __init__(self, configuration):
|
97 | 84 |
self._barbican_client = None
|
18 | 18 |
|
19 | 19 |
import abc
|
20 | 20 |
|
|
21 |
from castellan.common.objects import opaque_data as op_data
|
|
22 |
from castellan.common.objects import passphrase
|
|
23 |
from castellan.common.objects import private_key as pri_key
|
|
24 |
from castellan.common.objects import public_key as pub_key
|
|
25 |
from castellan.common.objects import symmetric_key as sym_key
|
|
26 |
from castellan.common.objects import x_509
|
|
27 |
|
21 | 28 |
|
22 | 29 |
class KeyManager(object, metaclass=abc.ABCMeta):
|
23 | 30 |
"""Base Key Manager Interface
|
|
25 | 32 |
A Key Manager is responsible for managing encryption keys for volumes. A
|
26 | 33 |
Key Manager is responsible for creating, reading, and deleting keys.
|
27 | 34 |
"""
|
|
35 |
|
|
36 |
_secret_type_dict = {
|
|
37 |
op_data.OpaqueData: "opaque",
|
|
38 |
passphrase.Passphrase: "passphrase",
|
|
39 |
pri_key.PrivateKey: "private",
|
|
40 |
pub_key.PublicKey: "public",
|
|
41 |
sym_key.SymmetricKey: "symmetric",
|
|
42 |
x_509.X509: "certificate"}
|
28 | 43 |
|
29 | 44 |
@abc.abstractmethod
|
30 | 45 |
def __init__(self, configuration):
|
32 | 32 |
import requests
|
33 | 33 |
|
34 | 34 |
from castellan.common import exception
|
35 | |
from castellan.common.objects import opaque_data as op_data
|
36 | |
from castellan.common.objects import passphrase
|
37 | 35 |
from castellan.common.objects import private_key as pri_key
|
38 | 36 |
from castellan.common.objects import public_key as pub_key
|
39 | 37 |
from castellan.common.objects import symmetric_key as sym_key
|
40 | |
from castellan.common.objects import x_509
|
41 | 38 |
from castellan.i18n import _
|
42 | 39 |
from castellan.key_manager import key_manager
|
43 | 40 |
|
|
82 | 79 |
class VaultKeyManager(key_manager.KeyManager):
|
83 | 80 |
"""Key Manager Interface that wraps the Vault REST API."""
|
84 | 81 |
|
85 | |
_secret_type_dict = {
|
86 | |
op_data.OpaqueData: 'opaque',
|
87 | |
passphrase.Passphrase: 'passphrase',
|
88 | |
pri_key.PrivateKey: 'private',
|
89 | |
pub_key.PublicKey: 'public',
|
90 | |
sym_key.SymmetricKey: 'symmetric',
|
91 | |
x_509.X509: 'certificate'}
|
92 | |
|
93 | 82 |
def __init__(self, configuration):
|
94 | 83 |
self._conf = configuration
|
95 | 84 |
self._conf.register_opts(_vault_opts, group=_VAULT_OPT_GROUP)
|