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