MCPcopy Create free account
hub / github.com/Keeper-Security/Commander / _get_plugin

Function _get_plugin

keepercommander/config_storage/loader.py:106–131  ·  view source on GitHub ↗
(url)

Source from the content-addressed store, hash-verified

104
105
106def _get_plugin(url): # type: (str) -> SecureStorageBase
107 if not url:
108 raise SecureStorageException(f'Configuration file error: "{CONFIG_STORAGE_URL}" cannot be empty')
109 par = urlparse(url)
110 if not par.scheme:
111 raise SecureStorageException(f'Configuration file error: "{CONFIG_STORAGE_URL}" is not URL')
112
113 plugin_name = par.scheme.replace('-', '_')
114 if not any(x for x in pkgutil.iter_modules(config_storage.__path__) if x.name == plugin_name):
115 raise SecureStorageException(f'Protected storage "{plugin_name}" is not supported')
116
117 module_name = f'keepercommander.config_storage.{plugin_name}'
118 try:
119 logging.debug('Importing config storage module "%s"', module_name)
120 module = importlib.import_module(module_name)
121 except ModuleNotFoundError as me:
122 dependency_not_installed = f'{plugin_name} requires {me.name} package to be installed\n' \
123 f'pip install {me.name}'
124 raise SecureStorageException(dependency_not_installed)
125 if not hasattr(module, 'SecureStorage'):
126 raise SecureStorageException(f'Protected storage "{plugin_name}" is invalid')
127 storage_class = getattr(module, 'SecureStorage')
128 storage = storage_class() # type: SecureStorageBase
129 if not isinstance(storage, SecureStorageBase):
130 raise SecureStorageException(f'Protected storage "{plugin_name}" is invalid')
131 return storage
132
133
134def split_name(name): # type: (Union[str, Tuple[str, str]]) -> Tuple[str, str]

Callers 2

store_config_propertiesFunction · 0.85
load_config_propertiesFunction · 0.85

Calls 2

debugMethod · 0.45

Tested by

no test coverage detected