Skip to content

Instantly share code, notes, and snippets.

@jmvrbanac
Created September 9, 2017 04:31
Show Gist options
  • Save jmvrbanac/66ee795d134afadfe1c6d53ba84daf66 to your computer and use it in GitHub Desktop.
Save jmvrbanac/66ee795d134afadfe1c6d53ba84daf66 to your computer and use it in GitHub Desktop.
Middleware plugins for a service
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