From 5e5271f93adeeee9a47ce153653f83ae8d8bc6ee Mon Sep 17 00:00:00 2001
From: Randy Barlow <randy@electronsweatshop.com>
Date: May 28 2019 18:30:43 +0000
Subject: Convert to fedora-messaging.


Signed-off-by: Randy Barlow <randy@electronsweatshop.com>

---

diff --git a/fedmsg.d/example-config.py b/fedmsg.d/example-config.py
deleted file mode 100644
index a570f72..0000000
--- a/fedmsg.d/example-config.py
+++ /dev/null
@@ -1,20 +0,0 @@
-import socket
-hostname = socket.gethostname()
-
-config = {
-    'tag2distrepo.enabled': True,
-
-    'tag2distrepo.tags': {
-        'primary': {
-            'url': 'http://koji.fedoraproject.org/kojihub',
-            'authmethod': 'ssl',
-            'cert': 'tag2distrepo.cert',
-            'serverca': 'server-ca.cert',
-            'options': {},
-
-            'tags': {
-                'sometag': ['xxxxxxx']
-            }
-        }
-    }
-}
diff --git a/fedmsg.d/tag2distrepo-logging.py b/fedmsg.d/tag2distrepo-logging.py
deleted file mode 100644
index 499be85..0000000
--- a/fedmsg.d/tag2distrepo-logging.py
+++ /dev/null
@@ -1,16 +0,0 @@
-config = dict(
-    logging=dict(
-        loggers=dict(
-            tag2distrepo={
-                "level": "DEBUG",
-                "propagate": False,
-                "handlers": ["console"],
-            },
-            root={
-                "level": "INFO",
-                "propagate": False,
-                "handlers": ["console"],
-            },
-        ),
-    ),
-)
diff --git a/fedora-messaging/example-config.toml b/fedora-messaging/example-config.toml
new file mode 100644
index 0000000..1d1d23f
--- /dev/null
+++ b/fedora-messaging/example-config.toml
@@ -0,0 +1,81 @@
+amqp_url = "amqps://tag2distrepo:@rabbitmq.fedoraproject.org/%2Fpubsub"
+
+topic_prefix = "org.fedoraproject.prod"
+
+publish_exchange = "amq.topic"
+passive_declares = true
+
+callback = "tag2distrepo:Tag2DistRepoConsumer"
+
+
+[tls]
+ca_cert = "/etc/pki/fedora-messaging/cacert.pem"
+keyfile = "/etc/pki/fedora-messaging/tag2distrepo-key.pem"
+certfile = "/etc/pki/fedora-messaging/tag2distrepo-cert.pem"
+
+
+[client_properties]
+app = "tag2distrepo"
+
+
+[queues.tag2distrepo]
+durable = true
+auto_delete = false
+exclusive = false
+arguments = {}
+
+
+[[bindings]]
+queue = "tag2distrepo"
+exchange = "amq.topic"
+routing_keys = [
+    "org.fedoraproject.prod.buildsys.tag",
+]
+
+
+[log_config]
+version = 1
+disable_existing_loggers = true
+
+
+[log_config.formatters.simple]
+format = "%(asctime)s %(levelname)-5.5s [%(name)s][%(threadName)s] %(message)s"
+
+
+[log_config.handlers.console]
+class = "logging.StreamHandler"
+formatter = "simple"
+stream = "ext://sys.stdout"
+
+
+[log_config.loggers.tag2distrepo]
+level = "INFO"
+propagate = false
+handlers = ["console"]
+
+
+[log_config.loggers.fedora_messaging]
+level = "INFO"
+propagate = false
+handlers = ["console"]
+
+
+# Twisted is the asynchronous framework that manages the TCP/TLS connection, as well
+# as the consumer event loop. When debugging you may want to lower this log level.
+[log_config.loggers.twisted]
+level = "INFO"
+propagate = false
+handlers = ["console"]
+
+
+# Pika is the underlying AMQP client library. When debugging you may want to
+# lower this log level.
+[log_config.loggers.pika]
+level = "WARNING"
+propagate = false
+handlers = ["console"]
+
+
+[log_config.root]
+level = "ERROR"
+handlers = ["console"]
diff --git a/tag2distrepo.yaml.example b/tag2distrepo.yaml.example
new file mode 100644
index 0000000..f298cc4
--- /dev/null
+++ b/tag2distrepo.yaml.example
@@ -0,0 +1,10 @@
+tag2distrepo.tags:
+    primary:
+        url: http://koji.fedoraproject.org/kojihub
+        authmethod: ssl
+        cert: tag2distrepo.cert
+        serverca: server-ca.cert
+        options: {}
+        tags:
+           sometag:
+             - xxxxxxx
diff --git a/tag2distrepo/__init__.py b/tag2distrepo/__init__.py
index c6d4014..c633173 100644
--- a/tag2distrepo/__init__.py
+++ b/tag2distrepo/__init__.py
@@ -1,33 +1,19 @@
 import koji
-
-import fedmsg
-import fedmsg.consumers
+import yaml
 
 import logging
 log = logging.getLogger('tag2distrepo')
 
 
-class Tag2DistRepoConsumer(fedmsg.consumers.FedmsgConsumer):
+class Tag2DistRepoConsumer:
     config_key = 'tag2distrepo.enabled'
 
-    def __init__(self, hub):
-        super(Tag2DistRepoConsumer, self).__init__(hub)
-
-        config = hub.config
-        prefix = config['topic_prefix']
-        env = config.get('environment')
-        self.topic = [
-            '%s.%s.buildsys.tag' % (prefix, env)
-        ]
-
+    def __init__(self):
+        self.config = yaml.safe_load('/etc/tag2distrepo.yaml')
         log.info('Tag2DistRepo consumer ready for service')
 
-    def consume(self, msg):
-        topic = msg['topic']
-        if topic not in self.topic:
-            return
-
-        msg = msg['body']['msg']
+    def __call__(self, msg):
+        msg = msg.body
 
         #  {u'build_id': 799208,
         #   u'name': u'python-fmn-rules',
@@ -47,12 +33,10 @@ class Tag2DistRepoConsumer(fedmsg.consumers.FedmsgConsumer):
         log.info('Build %s (%s) tagged into %s on %s',
                  build_nvr, build_id, tag, koji_instance)
 
-        config = fedmsg.config.load_config()
-
-        if koji_instance not in config['tag2distrepo.tags']:
+        if koji_instance not in self.config['tag2distrepo.tags']:
             log.info('Koji instance %s not enabled', koji_instance)
             return
-        kconfig = config['tag2distrepo.tags'][koji_instance]
+        kconfig = self.config['tag2distrepo.tags'][koji_instance]
 
         if tag not in kconfig['tags']:
             log.info('Tag %s not enabled for koji instance %s',

