Files
deb-python-openstacksdk/openstack/module_loader.py
Terry Howe 17381f0e37 Refactor auth plugin loading
I wanted to move the auth plugin loading code out of connection
for a couple of reasons:
* I wanted to be able to get a list of auth plugins without a
  connection.
* In the future, we'll want to load service extensions which the
  module loader can handle.
* The loading of service extensions needs to happen before we
  have a connection so we can assemble user preferences for those
  services.
At some point I think the user preference class will have the
module loader and handle these things, but I think it would be
a lot to digest all those changes.

Change-Id: I3abc47a6252bfca26cc1ab2e33553fe06b7b14c2
2015-01-23 14:31:14 -07:00

40 lines
1.2 KiB
Python

# 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.
"""
Load various modules for authorization and services.
"""
from stevedore import extension
from openstack import exceptions
class ModuleLoader(object):
def __init__(self):
self.auth_mgr = extension.ExtensionManager(
namespace="openstack.auth.plugin",
invoke_on_load=False,
)
def get_auth_plugin(self, plugin_name):
if not plugin_name:
plugin_name = 'identity'
try:
return self.auth_mgr[plugin_name].plugin
except KeyError:
msg = ('Could not find authorization plugin <%s>' % plugin_name)
raise exceptions.NoMatchingPlugin(msg)
def list_auth_plugins(self):
return self.auth_mgr.names()