From e99662c9eaf7101e84e8add5e28da90b168de279 Mon Sep 17 00:00:00 2001 From: Pierre-Yves Chibon Date: Feb 05 2019 15:17:21 +0000 Subject: [PATCH 1/3] Add support for fedora-messaging in pagure This effectively port pagure to the new messaging app used in Fedora relying on AMQP. As for the other messaging notifications this relies on a dedicated configuration key. However, projects will reuse the "fedmsg" option key. Signed-off-by: Pierre-Yves Chibon --- diff --git a/doc/configuration.rst b/doc/configuration.rst index 494b468..c8009c6 100644 --- a/doc/configuration.rst +++ b/doc/configuration.rst @@ -1069,6 +1069,15 @@ This configuration key allows to turn on or off notifications via `fedmsg Defaults to: ``False``. +FEDORA_MESSAGING_NOTIFICATIONS +~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~ + +This configuration key allows to turn on or off sending notifications via +`fedora-messaging <>`_. + +Defaults to: ``False``. + + ALWAYS_FEDMSG_ON_COMMITS ~~~~~~~~~~~~~~~~~~~~~~~~ diff --git a/pagure/lib/notify.py b/pagure/lib/notify.py index 17c15c0..d64455e 100644 --- a/pagure/lib/notify.py +++ b/pagure/lib/notify.py @@ -64,6 +64,31 @@ def fedmsg_publish(*args, **kwargs): # pragma: no cover _log.exception("Error sending fedmsg") +def fedora_messaging_publish(topic, message): # pragma: no cover + """ Try to publish a message on AMPQ using fedora-messaging. """ + if not pagure_config.get("FEDORA_MESSAGING_NOTIFICATIONS", False): + return + + try: + import fedora_messaging.api + import fedora_messaging.exceptions + + msg = fedora_messaging.api.Message( + topic="pagure.{}".format(topic), + body=message, + ) + fedora_messaging.api.publish(msg) + except Pfedora_messaging.exceptions.ublishReturned as e: + log.warning( + "Fedora Messaging broker rejected message %s: %s", + msg.id, e + ) + except fedora_messaging.exceptions.ConnectionException as e: + log.warning("Error sending message %s: %s", msg.id, e) + except Exception: + _log.exception("Error sending fedora-messaging message") + + stomp_conn = None @@ -165,6 +190,7 @@ def log(project, topic, msg, webhook=True): and not project.private ): fedmsg_publish(topic, msg) + fedora_messaging_publish(topic, msg) # Send stomp notification (if stomp is there and set-up) if not project or ( From 8b01fe00f293c32fd070560da1485430d2774146 Mon Sep 17 00:00:00 2001 From: Pierre-Yves Chibon Date: Feb 05 2019 15:17:21 +0000 Subject: [PATCH 2/3] Fix default configuration key value to fit the actual default value This also fit what is documented as being the default value. Signed-off-by: Pierre-Yves Chibon --- diff --git a/pagure/lib/notify.py b/pagure/lib/notify.py index d64455e..da35cd3 100644 --- a/pagure/lib/notify.py +++ b/pagure/lib/notify.py @@ -65,7 +65,7 @@ def fedmsg_publish(*args, **kwargs): # pragma: no cover def fedora_messaging_publish(topic, message): # pragma: no cover - """ Try to publish a message on AMPQ using fedora-messaging. """ + """ Try to publish a message on AMQP using fedora-messaging. """ if not pagure_config.get("FEDORA_MESSAGING_NOTIFICATIONS", False): return @@ -74,14 +74,12 @@ def fedora_messaging_publish(topic, message): # pragma: no cover import fedora_messaging.exceptions msg = fedora_messaging.api.Message( - topic="pagure.{}".format(topic), - body=message, + topic="pagure.{}".format(topic), body=message ) fedora_messaging.api.publish(msg) - except Pfedora_messaging.exceptions.ublishReturned as e: + except fedora_messaging.exceptions.PublishReturned as e: log.warning( - "Fedora Messaging broker rejected message %s: %s", - msg.id, e + "Fedora Messaging broker rejected message %s: %s", msg.id, e ) except fedora_messaging.exceptions.ConnectionException as e: log.warning("Error sending message %s: %s", msg.id, e) @@ -94,7 +92,7 @@ stomp_conn = None def stomp_publish(topic, message): """ Try to publish a message on a Stomp-compliant message bus. """ - if not pagure_config.get("STOMP_NOTIFICATIONS", True): + if not pagure_config.get("STOMP_NOTIFICATIONS", False): return # We catch Exception if we want :-p # pylint: disable=broad-except From f34287f6716f62122d0b20abb08a1f8c99f92f2c Mon Sep 17 00:00:00 2001 From: Pierre-Yves Chibon Date: Feb 05 2019 15:17:21 +0000 Subject: [PATCH 3/3] Add an example fedora-messaging configuration file Signed-off-by: Pierre-Yves Chibon --- diff --git a/files/fedora-messaging.toml.example b/files/fedora-messaging.toml.example new file mode 100644 index 0000000..fa917cb --- /dev/null +++ b/files/fedora-messaging.toml.example @@ -0,0 +1,15 @@ +# Example configuraton for Fedora Messaging +# More information on how to use it or what to do with it at: +# https://fedora-messaging.readthedocs.io/en/stable/configuration.html + +# Broker address +amqp_url = "amqp://" + +# Authentication is TLS-based +[tls] +ca_cert = "/etc/pki/tls/certs/ca-bundle.crt" +keyfile = "/my/client/key.pem" +certfile = "/my/client/cert.pem" + +[client_properties] +app = "pagure"