Add additional topics, set them to default

This commit is contained in:
Louis Abel 2024-12-21 20:22:16 -07:00
parent 009fafb7a5
commit f80d8b0751
Signed by: label
GPG Key ID: 2A6975660E424560
5 changed files with 71 additions and 7 deletions

View File

@ -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

View File

@ -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']

View File

@ -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

View File

@ -1,6 +1,6 @@
[project]
name = "buzon"
version = "0.1.0"
version = "0.2.1"
description = "MQTT webhook delivery service"
readme = "README.md"
authors = [

View File

@ -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 <label@resf.org> - 0.2.1-1
- Add additional fields for topics
* Wed Dec 18 2024 Louis Abel <label@resf.org> - 0.1.0-1
- Initial buzon spec file