Use oslo.config to load crypto plugins
This commit is contained in:
parent
ac5df00809
commit
d60760a03e
@ -23,7 +23,7 @@ from barbican.api.resources import (VersionResource,
|
||||
SecretsResource, SecretResource,
|
||||
OrdersResource, OrderResource)
|
||||
from barbican.common import config
|
||||
from barbican.crypto.extension_manager import CryptoExtensionManager
|
||||
from barbican.crypto import extension_manager as ext
|
||||
from barbican.openstack.common import log
|
||||
|
||||
|
||||
@ -34,10 +34,7 @@ def create_main_app(global_config, **local_conf):
|
||||
log.setup('barbican')
|
||||
|
||||
# Crypto Plugin Manager
|
||||
crypto_mgr = CryptoExtensionManager(
|
||||
'barbican.crypto.extension',
|
||||
['simple_crypto'] # TODO: grab this list from cfg
|
||||
)
|
||||
crypto_mgr = ext.CryptoExtensionManager(config.CONF)
|
||||
|
||||
# Resources
|
||||
versions = VersionResource()
|
||||
|
@ -13,12 +13,33 @@
|
||||
# See the License for the specific language governing permissions and
|
||||
# limitations under the License.
|
||||
|
||||
from oslo.config import cfg
|
||||
from stevedore import named
|
||||
|
||||
from barbican.common.exception import BarbicanException
|
||||
from barbican.openstack.common.gettextutils import _
|
||||
|
||||
|
||||
CONF = cfg.CONF
|
||||
DEFAULT_PLUGIN_NAMESPACE = 'barbican.crypto.plugin'
|
||||
DEFAULT_PLUGINS = ['simple_crypto']
|
||||
|
||||
crypto_opt_group = cfg.OptGroup(name='crypto',
|
||||
title='Crypto Plugin Options')
|
||||
crypto_opts = [
|
||||
cfg.StrOpt('namespace',
|
||||
default=DEFAULT_PLUGIN_NAMESPACE,
|
||||
help=_('Extension namespace to search for plugins.')
|
||||
),
|
||||
cfg.MultiStrOpt('enabled_crypto_plugins',
|
||||
default=DEFAULT_PLUGINS,
|
||||
help=_('List of crypto plugins to load.')
|
||||
)
|
||||
]
|
||||
CONF.register_group(crypto_opt_group)
|
||||
CONF.register_opts(crypto_opts, group=crypto_opt_group)
|
||||
|
||||
|
||||
class CryptoMimeTypeNotSupportedException(BarbicanException):
|
||||
"""Raised when support for requested mime type is
|
||||
not available in any active plugin."""
|
||||
@ -40,11 +61,11 @@ class CryptoAcceptNotSupportedException(BarbicanException):
|
||||
|
||||
|
||||
class CryptoExtensionManager(named.NamedExtensionManager):
|
||||
def __init__(self, namespace, names,
|
||||
invoke_on_load=True, invoke_args=(), invoke_kwargs={}):
|
||||
def __init__(self, conf, invoke_on_load=True,
|
||||
invoke_args=(), invoke_kwargs={}):
|
||||
super(CryptoExtensionManager, self).__init__(
|
||||
namespace,
|
||||
names,
|
||||
conf.crypto.namespace,
|
||||
conf.crypto.enabled_crypto_plugins,
|
||||
invoke_on_load=invoke_on_load,
|
||||
invoke_args=invoke_args,
|
||||
invoke_kwds=invoke_kwargs
|
||||
|
@ -140,11 +140,10 @@ class WhenCreatingSecretsUsingSecretsResource(unittest.TestCase):
|
||||
self.req.stream = self.stream
|
||||
|
||||
self.resp = MagicMock()
|
||||
self.crypto_mgr = CryptoExtensionManager(
|
||||
'barbican.test.crypto.extension',
|
||||
['test_crypto']
|
||||
)
|
||||
self.policy = MagicMock()
|
||||
self.conf = MagicMock()
|
||||
self.conf.crypto.namespace = 'barbican.test.crypto.plugin'
|
||||
self.conf.crypto.enabled_crypto_plugins = ['test_crypto']
|
||||
self.crypto_mgr = CryptoExtensionManager(self.conf)
|
||||
|
||||
self.resource = SecretsResource(self.crypto_mgr,
|
||||
self.tenant_repo,
|
||||
@ -277,10 +276,10 @@ class WhenGettingSecretsListUsingSecretsResource(unittest.TestCase):
|
||||
|
||||
self.policy = MagicMock()
|
||||
|
||||
self.crypto_mgr = CryptoExtensionManager(
|
||||
'barbican.test.crypto.extension',
|
||||
['test_crypto']
|
||||
)
|
||||
self.conf = MagicMock()
|
||||
self.conf.crypto.namespace = 'barbican.test.crypto.plugin'
|
||||
self.conf.crypto.enabled_crypto_plugins = ['test_crypto']
|
||||
self.crypto_mgr = CryptoExtensionManager(self.conf)
|
||||
|
||||
self.req = MagicMock()
|
||||
self.req.accept = 'application/json'
|
||||
@ -388,10 +387,12 @@ class WhenGettingPuttingOrDeletingSecretUsingSecretResource(
|
||||
self.req = MagicMock()
|
||||
self.req.accept = 'application/json'
|
||||
self.resp = MagicMock()
|
||||
self.crypto_mgr = CryptoExtensionManager(
|
||||
'barbican.test.crypto.extension',
|
||||
['test_crypto']
|
||||
)
|
||||
|
||||
self.conf = MagicMock()
|
||||
self.conf.crypto.namespace = 'barbican.test.crypto.plugin'
|
||||
self.conf.crypto.enabled_crypto_plugins = ['test_crypto']
|
||||
self.crypto_mgr = CryptoExtensionManager(self.conf)
|
||||
|
||||
self.policy = MagicMock()
|
||||
self.resource = SecretResource(self.crypto_mgr,
|
||||
self.tenant_repo,
|
||||
|
@ -79,10 +79,10 @@ class WhenBeginningOrder(unittest.TestCase):
|
||||
self.datum_repo = MagicMock()
|
||||
self.datum_repo.create_from.return_value = None
|
||||
|
||||
self.crypto_mgr = CryptoExtensionManager(
|
||||
'barbican.test.crypto.extension',
|
||||
['test_crypto']
|
||||
)
|
||||
self.conf = MagicMock()
|
||||
self.conf.crypto.namespace = 'barbican.test.crypto.plugin'
|
||||
self.conf.crypto.enabled_crypto_plugins = ['test_crypto']
|
||||
self.crypto_mgr = CryptoExtensionManager(self.conf)
|
||||
|
||||
self.resource = BeginOrder(self.crypto_mgr,
|
||||
self.tenant_repo, self.order_repo,
|
||||
|
4
setup.py
4
setup.py
@ -74,10 +74,10 @@ setup(
|
||||
scripts=['bin/barbican-api'],
|
||||
py_modules=[],
|
||||
entry_points="""
|
||||
[barbican.crypto.extension]
|
||||
[barbican.crypto.plugin]
|
||||
simple_crypto = barbican.crypto.plugin:SimpleCryptoPlugin
|
||||
|
||||
[barbican.test.crypto.extension]
|
||||
[barbican.test.crypto.plugin]
|
||||
test_crypto = barbican.tests.crypto.test_plugin:TestCryptoPlugin
|
||||
"""
|
||||
)
|
||||
|
Loading…
x
Reference in New Issue
Block a user