From b3b86da7c75c5c3dec250b0bdde6e5d27ab8f526 Mon Sep 17 00:00:00 2001 From: Pierre-Yves Chibon Date: Nov 23 2018 15:34:13 +0000 Subject: [PATCH 1/4] Add support for blueprints defined outside of pagure This is the basis for bringing in support for 3rd party extensions to pagure. Why we used a different configuration file? The content of the configuration file will be something like: ```` from pagure_taiga import taiga PLUGINS = [taiga.TAIGA_NS] ```` It will import the plugin to get its blueprint and store it in PLUGINS. There are high chances that the plugin we import will also import pagure's sources (for example to access the forms or simply the general configuration). So we had this defined in the main configuration file we would very quickly end up with circular imports that would be hard to untangle. Simply using PAGURE_CONFIG and PAGURE_PLUGIN to specify both configuration files solves that issue. Signed-off-by: Pierre-Yves Chibon --- diff --git a/pagure/flask_app.py b/pagure/flask_app.py index c6d4571..3a90c1a 100644 --- a/pagure/flask_app.py +++ b/pagure/flask_app.py @@ -128,6 +128,14 @@ def create_app(config=None): app.register_blueprint(PV) + # Import 3rd party blueprints + plugin_config = flask.config.Config('') + if "PAGURE_PLUGIN" in os.environ: + plugin_config.from_envvar("PAGURE_PLUGIN") + for blueprint in (plugin_config.get('PLUGINS') or []): + logger.info('Loading blueprint: %s', blueprint.name) + app.register_blueprint(blueprint) + themename = pagure_config.get("THEME", "default") here = os.path.abspath( os.path.join(os.path.dirname(os.path.abspath(__file__))) From 0f6d83d937e2027654dfd69cb425d0465f3c1664 Mon Sep 17 00:00:00 2001 From: Pierre-Yves Chibon Date: Nov 23 2018 15:34:13 +0000 Subject: [PATCH 2/4] Add support for 3rd party extensions to runserver.py Signed-off-by: Pierre-Yves Chibon --- diff --git a/runserver.py b/runserver.py index 4080d03..70676bb 100755 --- a/runserver.py +++ b/runserver.py @@ -17,6 +17,9 @@ parser.add_argument( '--config', '-c', dest='config', help='Configuration file to use for pagure.') parser.add_argument( + '--plugins', dest='plugins', + help='Configuration file for pagure plugin.') +parser.add_argument( '--debug', dest='debug', action='store_true', default=False, help='Expand the level of data returned.') @@ -48,6 +51,13 @@ if args.config: config = os.path.join(here, config) os.environ['PAGURE_CONFIG'] = config +if args.plugins: + config = args.plugins + if not config.startswith('/'): + here = os.path.join(os.path.dirname(os.path.abspath(__file__))) + config = os.path.join(here, config) + os.environ['PAGURE_PLUGIN'] = config + if args.perfverbose: os.environ['PAGURE_PERFREPO'] = 'true' os.environ['PAGURE_PERFREPO_VERBOSE'] = 'true' From 4517cde766c746c4897996d5b6ff6ae512c4ded3 Mon Sep 17 00:00:00 2001 From: Pierre-Yves Chibon Date: Nov 23 2018 15:34:13 +0000 Subject: [PATCH 3/4] Add blinker notification for 3rd party to use Signed-off-by: Pierre-Yves Chibon --- diff --git a/pagure/lib/notify.py b/pagure/lib/notify.py index 03ca2cd..bb51610 100644 --- a/pagure/lib/notify.py +++ b/pagure/lib/notify.py @@ -27,6 +27,7 @@ from email.header import Header from email.mime.text import MIMEText from six.moves.urllib_parse import urljoin +import blinker import flask import pagure.lib.query import pagure.lib.tasks_services @@ -98,7 +99,14 @@ def stomp_publish(topic, message): _log.exception("Error sending stomp message") -def log(project, topic, msg, webhook=True): +def blinker_publish(topic, message): + _log.info("Sending blinker signal to: pagure") + ready = blinker.signal("pagure") + _log.info(" Blinker payload: %s" % message) + ready.send("pagure", topic=topic, message=message) + + +def log(project, topic, msg, redis=None): """ This is the place where we send notifications to user about actions occuring in pagure. """ @@ -117,7 +125,10 @@ def log(project, topic, msg, webhook=True): ): stomp_publish(topic, msg) - if webhook and project and not project.private: + # Send blink notification to any 3rd party plugins, if there are any + blinker_publish(topic, msg) + + if redis and project and not project.private: pagure.lib.tasks_services.webhook_notification.delay( topic=topic, msg=msg, From 97dcb02d2d7a9456f2c7edeb0816a8b10d031502 Mon Sep 17 00:00:00 2001 From: Pierre-Yves Chibon Date: Nov 23 2018 15:34:13 +0000 Subject: [PATCH 4/4] Black and flake8 fixes Signed-off-by: Pierre-Yves Chibon --- diff --git a/pagure/flask_app.py b/pagure/flask_app.py index 3a90c1a..fb6c9a3 100644 --- a/pagure/flask_app.py +++ b/pagure/flask_app.py @@ -129,11 +129,11 @@ def create_app(config=None): app.register_blueprint(PV) # Import 3rd party blueprints - plugin_config = flask.config.Config('') + plugin_config = flask.config.Config("") if "PAGURE_PLUGIN" in os.environ: plugin_config.from_envvar("PAGURE_PLUGIN") - for blueprint in (plugin_config.get('PLUGINS') or []): - logger.info('Loading blueprint: %s', blueprint.name) + for blueprint in plugin_config.get("PLUGINS") or []: + logger.info("Loading blueprint: %s", blueprint.name) app.register_blueprint(blueprint) themename = pagure_config.get("THEME", "default")