enable debug-only rabbitmq webhook hander
This commit is contained in:
parent
4c8eae5e7c
commit
937664dfba
@ -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)
|
||||||
|
|
||||||
connectToRabbitMQ()
|
if doPublish {
|
||||||
|
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,17 +411,19 @@ func main() {
|
|||||||
return
|
return
|
||||||
}
|
}
|
||||||
|
|
||||||
err = PublishMessage(org.Username, reqType, extraAction, data)
|
if doPublish {
|
||||||
if err != nil {
|
err = PublishMessage(org.Username, reqType, extraAction, data)
|
||||||
errorStr := fmt.Sprintf("hook (%s) processing error: %v\n", reqType, err)
|
if err != nil {
|
||||||
res.Header().Add("Content-Type", "plain/text")
|
errorStr := fmt.Sprintf("hook (%s) processing error: %v\n", reqType, err)
|
||||||
res.Write([]byte(errorStr))
|
res.Header().Add("Content-Type", "plain/text")
|
||||||
res.WriteHeader(http.StatusBadRequest)
|
res.Write([]byte(errorStr))
|
||||||
|
res.WriteHeader(http.StatusBadRequest)
|
||||||
|
|
||||||
if DebugMode {
|
if DebugMode {
|
||||||
log.Println(errorStr)
|
log.Println(errorStr)
|
||||||
|
}
|
||||||
|
return
|
||||||
}
|
}
|
||||||
return
|
|
||||||
}
|
}
|
||||||
res.WriteHeader(http.StatusOK)
|
res.WriteHeader(http.StatusOK)
|
||||||
})
|
})
|
||||||
|
Loading…
Reference in New Issue
Block a user