Created
September 9, 2017 04:31
-
-
Save jmvrbanac/66ee795d134afadfe1c6d53ba84daf66 to your computer and use it in GitHub Desktop.
Middleware plugins for a service
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
from pike.discovery import py | |
class MiddlewarePlugin(object): | |
def __init__(self, config): | |
self.config = config | |
@classmethod | |
def qualified_name(cls): | |
__, __, module_name = cls.__module__.rpartition('.') | |
return '{}.{}'.format(module_name, cls.__name__) | |
def get_middleware_plugins(mw_names, inst_kwargs): | |
module = py.get_module_by_name('my_service.middleware') | |
classes = py.get_all_inherited_classes(module, MiddlewarePlugin) | |
loaded_middleware = list( | |
mw(**inst_kwargs) | |
for name in mw_names | |
for mw in classes | |
if mw.qualified_name() == name | |
) | |
return loaded_middleware |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment