enable debug-only rabbitmq webhook hander

This commit is contained in:
Adam Majer 2024-09-11 18:56:48 +02:00
parent 4c8eae5e7c
commit 937664dfba

View File

@ -325,19 +325,24 @@ func parseRequestJSONOrg(reqType string, data []byte) (org *common.Organization,
func main() { func main() {
var listenAddr string var listenAddr string
var reqBearerToken string var reqBearerToken string
var doPublish bool
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.StringVar(&topicScope, "topic-domain", DefTopicDomain, "Default domain for RabbitMQ topics")
flag.StringVar(&reqBearerToken, "token", "", "HTTP Bearer token to match") flag.StringVar(&reqBearerToken, "token", "", "HTTP Bearer token to match")
flag.BoolVar(&doPublish, "publish", true, "Publish to RabbitMQ. Disable for testing.")
flag.Parse() flag.Parse()
log.Println("Starting....") log.Println("Starting....")
log.Printf(" * Debugging: %t\n", DebugMode) log.Printf(" * Debugging: %t\n", DebugMode)
log.Printf(" * Listening: %s\n", listenAddr) log.Printf(" * Listening: %s\n", listenAddr)
log.Printf(" * Bearer token: %t\n", len(reqBearerToken) > 0) log.Printf(" * Bearer token: %t\n", len(reqBearerToken) > 0)
log.Printf(" * Publish to RabbitMQ: %t\n", doPublish)
if doPublish {
connectToRabbitMQ() connectToRabbitMQ()
}
http.HandleFunc("POST /rabbitmq-forwarder", func(res http.ResponseWriter, req *http.Request) { http.HandleFunc("POST /rabbitmq-forwarder", func(res http.ResponseWriter, req *http.Request) {
if len(req.Header.Get("Content-Type")) == 0 || if len(req.Header.Get("Content-Type")) == 0 ||
@ -406,6 +411,7 @@ func main() {
return return
} }
if doPublish {
err = PublishMessage(org.Username, reqType, extraAction, data) err = PublishMessage(org.Username, reqType, extraAction, data)
if err != nil { if err != nil {
errorStr := fmt.Sprintf("hook (%s) processing error: %v\n", reqType, err) errorStr := fmt.Sprintf("hook (%s) processing error: %v\n", reqType, err)
@ -418,6 +424,7 @@ func main() {
} }
return return
} }
}
res.WriteHeader(http.StatusOK) res.WriteHeader(http.StatusOK)
}) })