Created CLI flag and stubbed out simple webhook endpoint.
This commit is contained in:
28
gateway/webhook/webhook.go
Normal file
28
gateway/webhook/webhook.go
Normal file
@@ -0,0 +1,28 @@
|
||||
package webhook
|
||||
|
||||
import (
|
||||
"net/http"
|
||||
"github.com/labstack/echo"
|
||||
"github.com/labstack/echo/middleware"
|
||||
)
|
||||
|
||||
func Serve() {
|
||||
e := echo.New()
|
||||
e.Use(middleware.Logger())
|
||||
e.POST("/reload", reloadConfig)
|
||||
e.Logger.Fatal(e.Start(":1323"))
|
||||
}
|
||||
|
||||
var (
|
||||
secretToken = "1234567890"
|
||||
)
|
||||
|
||||
func reloadConfig(c echo.Context) error {
|
||||
providedToken := c.QueryParam("token")
|
||||
if providedToken != secretToken {
|
||||
return c.String(http.StatusUnauthorized, "Unauthorized")
|
||||
}
|
||||
|
||||
return c.String(http.StatusAccepted, "Accepted")
|
||||
|
||||
}
|
||||
@@ -8,6 +8,7 @@ import (
|
||||
|
||||
"github.com/42wim/matterbridge/bridge/config"
|
||||
"github.com/42wim/matterbridge/gateway"
|
||||
"github.com/42wim/matterbridge/gateway/webhook"
|
||||
"github.com/google/gops/agent"
|
||||
prefixed "github.com/matterbridge/logrus-prefixed-formatter"
|
||||
log "github.com/sirupsen/logrus"
|
||||
@@ -25,6 +26,7 @@ func main() {
|
||||
flagDebug := flag.Bool("debug", false, "enable debug")
|
||||
flagVersion := flag.Bool("version", false, "show version")
|
||||
flagGops := flag.Bool("gops", false, "enable gops agent")
|
||||
flagWebhook := flag.Bool("webhook", false, "run webhook serve mode")
|
||||
flag.Parse()
|
||||
if *flagGops {
|
||||
agent.Listen(&agent.Options{})
|
||||
@@ -39,6 +41,12 @@ func main() {
|
||||
flog.Info("Enabling debug")
|
||||
log.SetLevel(log.DebugLevel)
|
||||
}
|
||||
if *flagWebhook {
|
||||
fmt.Printf("Starting webhook for reloading remote config...")
|
||||
fmt.Printf("Serving at: POST /webhook")
|
||||
webhook.Serve()
|
||||
return
|
||||
}
|
||||
flog.Printf("Running version %s %s", version, githash)
|
||||
if strings.Contains(version, "-dev") {
|
||||
flog.Println("WARNING: THIS IS A DEVELOPMENT VERSION. Things may break.")
|
||||
|
||||
Reference in New Issue
Block a user