Exemplo n.º 1
0
async def main():
    # create a manager and add the spec
    pm = aiopluggy.PluginManager("myproject")
    pm.register_specs(MySpec)

    # register plugins
    await pm.register(Plugin_1())
    await pm.register(Plugin_2())

    # call our `myhook` hook
    results = await pm.hooks.myhook(arg1=1, arg2=2)
    values = [ result.value for result in results ]
    print(values)
Exemplo n.º 2
0
    def __init__(self, *args, middlewares=None, **kwargs):
        middlewares = [] if middlewares is None else list(middlewares)
        # add required middlewares
        middlewares.extend([
            web.normalize_path_middleware(),  # todo: needed?
            # Make comment from the following line to disable authentication for local testing
            authorization.middleware
        ])
        super().__init__(*args, middlewares=middlewares, **kwargs)

        # Initialize config:
        self._config = config.load()

        self._pool = None

        # set app properties
        path = urllib.parse.urlparse(self._config['web']['baseurl']).path
        if len(path) == 0 or path[-1] != '/':
            path += '/'
        self['path'] = path
        self['openapi'] = openapi.openapi

        # set routes
        self.router.add_get(path + 'datasets',
                            handlers.datasets.get_collection)
        self.router.add_post(path + 'datasets',
                             handlers.datasets.post_collection)

        self.router.add_get(path + 'datasets/{dataset}', handlers.datasets.get)
        self.router.add_put(path + 'datasets/{dataset}', handlers.datasets.put)
        self.router.add_delete(path + 'datasets/{dataset}',
                               handlers.datasets.delete)
        self.router.add_get(path + 'datasets/{dataset}/purls/{distribution}',
                            handlers.datasets.link_redirect)

        self.router.add_get(path + 'harvest', handlers.harvest.get_collection)

        self.router.add_get(path + 'openapi', handlers.openapi.get)

        self.router.add_get(path + 'system/health', handlers.systemhealth.get)

        # Load and initialize plugins:
        self._pm = aiopluggy.PluginManager('datacatalog')
        self._pm.register_specs(plugin_interfaces)

        self.on_startup.append(_on_startup)
        self.on_cleanup.append(_on_cleanup)

        self._load_plugins()
        self._initialize_sync()

        # CORS
        # this must be done after initialize_sync: plugins may register new
        # routes during setup and our allow_cors applies to all routes.
        if 'allow_cors' in self._config['web'] and self._config['web'][
                'allow_cors']:
            cors = aiohttp_cors.setup(self,
                                      defaults={
                                          '*':
                                          aiohttp_cors.ResourceOptions(
                                              expose_headers="*",
                                              allow_headers="*"),
                                      })
            for route in list(self.router.routes()):
                cors.add(route)
Exemplo n.º 3
0
def test_signatures():
    pm = aiopluggy.PluginManager('datacatalog')
    pm.register_specs(plugin_interfaces)
    pm.register(postgres_plugin)