diff --git a/gitea-events-rabbitmq-publisher/main.go b/gitea-events-rabbitmq-publisher/main.go index b12d6fe..f433125 100644 --- a/gitea-events-rabbitmq-publisher/main.go +++ b/gitea-events-rabbitmq-publisher/main.go @@ -325,19 +325,24 @@ func parseRequestJSONOrg(reqType string, data []byte) (org *common.Organization, func main() { var listenAddr string var reqBearerToken string + var doPublish bool 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.StringVar(&reqBearerToken, "token", "", "HTTP Bearer token to match") + flag.BoolVar(&doPublish, "publish", true, "Publish to RabbitMQ. Disable for testing.") flag.Parse() log.Println("Starting....") log.Printf(" * Debugging: %t\n", DebugMode) log.Printf(" * Listening: %s\n", listenAddr) 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) { if len(req.Header.Get("Content-Type")) == 0 || @@ -406,17 +411,19 @@ func main() { return } - err = PublishMessage(org.Username, reqType, extraAction, data) - if err != nil { - errorStr := fmt.Sprintf("hook (%s) processing error: %v\n", reqType, err) - res.Header().Add("Content-Type", "plain/text") - res.Write([]byte(errorStr)) - res.WriteHeader(http.StatusBadRequest) + if doPublish { + err = PublishMessage(org.Username, reqType, extraAction, data) + if err != nil { + errorStr := fmt.Sprintf("hook (%s) processing error: %v\n", reqType, err) + res.Header().Add("Content-Type", "plain/text") + res.Write([]byte(errorStr)) + res.WriteHeader(http.StatusBadRequest) - if DebugMode { - log.Println(errorStr) + if DebugMode { + log.Println(errorStr) + } + return } - return } res.WriteHeader(http.StatusOK) })