From f80d8b075164e317f9a9c899cc1e2182a9c7abee Mon Sep 17 00:00:00 2001 From: Louis Abel Date: Sat, 21 Dec 2024 20:22:16 -0700 Subject: [PATCH] Add additional topics, set them to default --- buzon/app.py | 59 ++++++++++++++++++++++++++++++++++++++++- buzon/config/carrier.py | 8 +++--- config/buzon.yaml | 4 ++- pyproject.toml | 2 +- rpm/python-buzon.spec | 5 +++- 5 files changed, 71 insertions(+), 7 deletions(-) diff --git a/buzon/app.py b/buzon/app.py index cef5aab..4519cc0 100644 --- a/buzon/app.py +++ b/buzon/app.py @@ -40,6 +40,15 @@ logging.basicConfig(level="INFO") async def startup(): """Starting up buzon""" buzon_logger.info('Starting up') + + # TODO: Some how do this in the models in config/carrier.py + if buzon_config.mqtt_topic_issues is None: + buzon_config.mqtt_topic_issues = buzon_config.mqtt_topic_default + if buzon_config.mqtt_topic_forks is None: + buzon_config.mqtt_topic_forks = buzon_config.mqtt_topic_default + if buzon_config.mqtt_topic_commits is None: + buzon_config.mqtt_topic_commits = buzon_config.mqtt_topic_default + if buzon_mode == "test": buzon_logger.warning('No MQTT messages will be sent in testing mode.') else: @@ -68,7 +77,7 @@ async def root(): """ What's at the root? Nothing. """ - return {"message": "buzon, a carrier for gitea webhooks"} + return {"message": "buzon, a carrier for gitea and forgejo webhooks"} @app.post( '/push-event', @@ -93,3 +102,51 @@ async def push_event(event_data: EventPush): ) return processor_event + +@app.post( + '/fork-event', + response_model=Responder, + responses={201: {'model': Responder}, 400: {'model': Responder}} +) +async def fork_event(event_data: EventPush): + """ + Fork events for repositories + + This comes back as JSONResponse. + """ + processor_event = processor.process_respond( + buzon_config.mqtt_topic_forks, + event_data, + buzon_mqtt, + buzon_config, + buzon_logger, + buzon_mode, + retries=5, + sleep=10 + ) + + return processor_event + +@app.post( + '/issue-event', + response_model=Responder, + responses={201: {'model': Responder}, 400: {'model': Responder}} +) +async def issue_event(event_data: EventPush): + """ + Issues event for repositories that have issue activity + + This comes back as JSONResponse. + """ + processor_event = processor.process_respond( + buzon_config.mqtt_topic_issues, + event_data, + buzon_mqtt, + buzon_config, + buzon_logger, + buzon_mode, + retries=5, + sleep=10 + ) + + return processor_event diff --git a/buzon/config/carrier.py b/buzon/config/carrier.py index b333e9c..5d42bda 100644 --- a/buzon/config/carrier.py +++ b/buzon/config/carrier.py @@ -6,7 +6,7 @@ Carrier module import typing from datetime import datetime -from pydantic import BaseModel +from pydantic import BaseModel, model_validator __all__ = [ 'Responder', @@ -31,7 +31,7 @@ class Responder(BaseModel): """ confirm: bool -class Configuration(BaseModel): +class Configuration(BaseModel, validate_assignment=True): """ Configuration stuff """ @@ -40,8 +40,10 @@ class Configuration(BaseModel): mqtt_port: int mqtt_user: str mqtt_password: str - mqtt_topic_commits: str mqtt_topic_default: str + mqtt_topic_commits: typing.Optional[str] = None + mqtt_topic_forks: typing.Optional[str] = None + mqtt_topic_issues: typing.Optional[str] = None mqtt_qos: int mode: typing.Literal['test', 'prod'] diff --git a/config/buzon.yaml b/config/buzon.yaml index 24b9630..4ec21e5 100644 --- a/config/buzon.yaml +++ b/config/buzon.yaml @@ -4,8 +4,10 @@ mqtt_host: mq.example.com mqtt_port: 1883 mqtt_user: buzon mqtt_password: buzon -mqtt_topic_commits: commits mqtt_topic_default: default +#mqtt_topic_commits: default +#mqtt_topic_forks: default +#mqtt_topic_issues: default mqtt_qos: 2 loglevel: INFO diff --git a/pyproject.toml b/pyproject.toml index 428469a..534a370 100644 --- a/pyproject.toml +++ b/pyproject.toml @@ -1,6 +1,6 @@ [project] name = "buzon" -version = "0.1.0" +version = "0.2.1" description = "MQTT webhook delivery service" readme = "README.md" authors = [ diff --git a/rpm/python-buzon.spec b/rpm/python-buzon.spec index 0acbd5d..ffb1f90 100644 --- a/rpm/python-buzon.spec +++ b/rpm/python-buzon.spec @@ -1,7 +1,7 @@ %global pyname buzon Name: python-%{pyname} -Version: 0.2.0 +Version: 0.2.1 Release: 1%{?dist} Summary: MQTT Webhook Delivery Service @@ -55,6 +55,9 @@ install -pm 0644 rpm/buzon.sysconfig %{buildroot}%{_sysconfdir}/sysconfig/%{pyna %{_sysconfdir}/sysconfig/%{pyname} %changelog +* Sat Dec 21 2024 Louis Abel - 0.2.1-1 +- Add additional fields for topics + * Wed Dec 18 2024 Louis Abel - 0.1.0-1 - Initial buzon spec file