Read webhook token from viper config.
This commit is contained in:
@@ -171,6 +171,7 @@ type ConfigValues struct {
|
|||||||
General Protocol
|
General Protocol
|
||||||
Gateway []Gateway
|
Gateway []Gateway
|
||||||
SameChannelGateway []SameChannelGateway
|
SameChannelGateway []SameChannelGateway
|
||||||
|
ConfigWebhookToken string
|
||||||
}
|
}
|
||||||
|
|
||||||
type Config struct {
|
type Config struct {
|
||||||
|
|||||||
@@ -4,6 +4,7 @@ import (
|
|||||||
"net/http"
|
"net/http"
|
||||||
"github.com/labstack/echo"
|
"github.com/labstack/echo"
|
||||||
"github.com/labstack/echo/middleware"
|
"github.com/labstack/echo/middleware"
|
||||||
|
"github.com/spf13/viper"
|
||||||
)
|
)
|
||||||
|
|
||||||
func Serve() {
|
func Serve() {
|
||||||
@@ -13,12 +14,9 @@ func Serve() {
|
|||||||
e.Logger.Fatal(e.Start(":1323"))
|
e.Logger.Fatal(e.Start(":1323"))
|
||||||
}
|
}
|
||||||
|
|
||||||
var (
|
|
||||||
secretToken = "1234567890"
|
|
||||||
)
|
|
||||||
|
|
||||||
func reloadConfig(c echo.Context) error {
|
func reloadConfig(c echo.Context) error {
|
||||||
providedToken := c.QueryParam("token")
|
providedToken := c.QueryParam("token")
|
||||||
|
secretToken := viper.GetString("ConfigWebhookToken")
|
||||||
if providedToken != secretToken {
|
if providedToken != secretToken {
|
||||||
return c.String(http.StatusUnauthorized, "Unauthorized")
|
return c.String(http.StatusUnauthorized, "Unauthorized")
|
||||||
}
|
}
|
||||||
|
|||||||
@@ -10,6 +10,7 @@ import (
|
|||||||
"github.com/42wim/matterbridge/gateway"
|
"github.com/42wim/matterbridge/gateway"
|
||||||
"github.com/42wim/matterbridge/gateway/webhook"
|
"github.com/42wim/matterbridge/gateway/webhook"
|
||||||
"github.com/google/gops/agent"
|
"github.com/google/gops/agent"
|
||||||
|
"github.com/spf13/viper"
|
||||||
prefixed "github.com/matterbridge/logrus-prefixed-formatter"
|
prefixed "github.com/matterbridge/logrus-prefixed-formatter"
|
||||||
log "github.com/sirupsen/logrus"
|
log "github.com/sirupsen/logrus"
|
||||||
)
|
)
|
||||||
@@ -41,18 +42,22 @@ func main() {
|
|||||||
flog.Info("Enabling debug")
|
flog.Info("Enabling debug")
|
||||||
log.SetLevel(log.DebugLevel)
|
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)
|
flog.Printf("Running version %s %s", version, githash)
|
||||||
if strings.Contains(version, "-dev") {
|
if strings.Contains(version, "-dev") {
|
||||||
flog.Println("WARNING: THIS IS A DEVELOPMENT VERSION. Things may break.")
|
flog.Println("WARNING: THIS IS A DEVELOPMENT VERSION. Things may break.")
|
||||||
}
|
}
|
||||||
cfg := config.NewConfig(*flagConfig)
|
cfg := config.NewConfig(*flagConfig)
|
||||||
cfg.General.Debug = *flagDebug
|
cfg.General.Debug = *flagDebug
|
||||||
|
if *flagWebhook {
|
||||||
|
// TODO: Find out why this reverts after config load
|
||||||
|
log.SetFormatter(&prefixed.TextFormatter{PrefixPadding: 13, DisableColors: true, FullTimestamp: true})
|
||||||
|
flog.Println("Starting webhook for reloading remote config...")
|
||||||
|
if viper.GetString("ConfigWebhookToken") == "" {
|
||||||
|
flog.Fatalf("Must set config webhook's auth token to use.")
|
||||||
|
}
|
||||||
|
flog.Println("Serving at: POST /webhook")
|
||||||
|
webhook.Serve()
|
||||||
|
}
|
||||||
r, err := gateway.NewRouter(cfg)
|
r, err := gateway.NewRouter(cfg)
|
||||||
if err != nil {
|
if err != nil {
|
||||||
flog.Fatalf("Starting gateway failed: %s", err)
|
flog.Fatalf("Starting gateway failed: %s", err)
|
||||||
|
|||||||
@@ -1,3 +1,8 @@
|
|||||||
|
# If you are serving the config reload webhook, you will need to set this
|
||||||
|
# security token the will be needed to trigger reload.
|
||||||
|
# OPTIONAL (default "")
|
||||||
|
ConfigWebhookToken=1234567890
|
||||||
|
|
||||||
#This is configuration for matterbridge.
|
#This is configuration for matterbridge.
|
||||||
#WARNING: as this file contains credentials, be sure to set correct file permissions
|
#WARNING: as this file contains credentials, be sure to set correct file permissions
|
||||||
###################################################################
|
###################################################################
|
||||||
|
|||||||
Reference in New Issue
Block a user