parametrize rabbit topic
This commit is contained in:
parent
60705dc939
commit
f38b63b297
@ -9,4 +9,6 @@ const (
|
||||
GiteaRequestHeader = "X-Gitea-Event-Type"
|
||||
|
||||
Bot_BuildReview = "autogits_obs_staging_bot"
|
||||
|
||||
TopicApp = "src"
|
||||
)
|
||||
|
@ -15,9 +15,11 @@ import (
|
||||
const (
|
||||
ListenAddrDef = "[::1]:8002"
|
||||
AppName = "rabbitmq-forwarder"
|
||||
DefTopicDomain = "opensuse"
|
||||
)
|
||||
|
||||
var DebugMode bool
|
||||
var topicScope string
|
||||
|
||||
func connectToRabbitMQ() {
|
||||
host := os.Getenv("RABBITMQ_HOST")
|
||||
@ -36,7 +38,7 @@ var id int
|
||||
|
||||
func dumpUnhandledData(reqType string, data []byte) {
|
||||
id++
|
||||
if err := os.WriteFile(fmt.Sprintf("/tmp/unhandled-json-%s-%d.json", reqType,id), data, 0600); err != nil {
|
||||
if err := os.WriteFile(fmt.Sprintf("/tmp/unhandled-json-%s-%d.json", reqType, id), data, 0600); err != nil {
|
||||
log.Printf("Cannot dump json. err: %v\n", err)
|
||||
log.Println(string(data))
|
||||
}
|
||||
@ -307,6 +309,7 @@ func main() {
|
||||
|
||||
flag.BoolVar(&DebugMode, "debug", false, "enables debugging messages")
|
||||
flag.StringVar(&listenAddr, "listen", ListenAddrDef, "HTTP listen socket address for webhook events")
|
||||
flag.StringVar(&topicScope, "topic-domain", DefTopicDomain, "Default domain for RabbitMQ topics")
|
||||
flag.Parse()
|
||||
|
||||
log.Println("Starting....")
|
||||
|
@ -10,6 +10,7 @@ import (
|
||||
"time"
|
||||
|
||||
rabbitmq "github.com/rabbitmq/amqp091-go"
|
||||
"src.opensuse.org/autogits/common"
|
||||
)
|
||||
|
||||
func failOnError(err error, msg string) {
|
||||
@ -37,12 +38,12 @@ func PublishMessage(giteaOrg, giteaWebhookType, action string, data []byte) erro
|
||||
var msg Message
|
||||
if len(action) > 0 {
|
||||
msg = Message{
|
||||
Topic: fmt.Sprintf("opensuse.gitea.%s.%s.%s", giteaOrg, giteaWebhookType, action),
|
||||
Topic: fmt.Sprintf("%s.%s.%s.%s.%s", topicScope, common.TopicApp, giteaOrg, giteaWebhookType, action),
|
||||
Body: data,
|
||||
}
|
||||
} else {
|
||||
msg = Message{
|
||||
Topic: fmt.Sprintf("opensuse.gitea.%s.%s", giteaOrg, giteaWebhookType),
|
||||
Topic: fmt.Sprintf("%s.%s.%s.%s", topicScope, common.TopicApp, giteaOrg, giteaWebhookType),
|
||||
Body: data,
|
||||
}
|
||||
}
|
||||
|
Loading…
Reference in New Issue
Block a user