mirror of
https://github.com/ncarlier/webhookd.git
synced 2025-04-09 10:12:47 +00:00
parent
67107de377
commit
9fa96acfb2
4
main.go
4
main.go
|
@ -40,6 +40,10 @@ func main() {
|
||||||
conf.HookLogDir = os.TempDir()
|
conf.HookLogDir = os.TempDir()
|
||||||
}
|
}
|
||||||
|
|
||||||
|
if err := conf.Validate(); err != nil {
|
||||||
|
logger.Error.Fatal("invalid configuration:", err)
|
||||||
|
}
|
||||||
|
|
||||||
logger.Debug.Println("starting webhookd server...")
|
logger.Debug.Println("starting webhookd server...")
|
||||||
|
|
||||||
srv := server.NewServer(conf)
|
srv := server.NewServer(conf)
|
||||||
|
|
|
@ -42,6 +42,7 @@ func buildMiddlewares(conf *config.Config) middleware.Middlewares {
|
||||||
|
|
||||||
func routes(conf *config.Config) Routes {
|
func routes(conf *config.Config) Routes {
|
||||||
middlewares := buildMiddlewares(conf)
|
middlewares := buildMiddlewares(conf)
|
||||||
|
staticPath := conf.StaticPath + "/"
|
||||||
return Routes{
|
return Routes{
|
||||||
route(
|
route(
|
||||||
"/",
|
"/",
|
||||||
|
@ -49,8 +50,8 @@ func routes(conf *config.Config) Routes {
|
||||||
middlewares.UseBefore(middleware.Methods("GET", "POST"))...,
|
middlewares.UseBefore(middleware.Methods("GET", "POST"))...,
|
||||||
),
|
),
|
||||||
route(
|
route(
|
||||||
"/static/",
|
staticPath,
|
||||||
static("/static/"),
|
static(staticPath),
|
||||||
middlewares.UseBefore(middleware.Methods("GET"))...,
|
middlewares.UseBefore(middleware.Methods("GET"))...,
|
||||||
),
|
),
|
||||||
route(
|
route(
|
||||||
|
|
|
@ -1,5 +1,10 @@
|
||||||
package config
|
package config
|
||||||
|
|
||||||
|
import (
|
||||||
|
"fmt"
|
||||||
|
"regexp"
|
||||||
|
)
|
||||||
|
|
||||||
// Config contain global configuration
|
// Config contain global configuration
|
||||||
type Config struct {
|
type Config struct {
|
||||||
ListenAddr string `flag:"listen-addr" desc:"HTTP listen address" default:":8080"`
|
ListenAddr string `flag:"listen-addr" desc:"HTTP listen address" default:":8080"`
|
||||||
|
@ -15,6 +20,14 @@ type Config struct {
|
||||||
PasswdFile string `flag:"passwd-file" desc:"Password file for basic HTTP authentication" default:".htpasswd"`
|
PasswdFile string `flag:"passwd-file" desc:"Password file for basic HTTP authentication" default:".htpasswd"`
|
||||||
LogLevel string `flag:"log-level" desc:"Log level (debug, info, warn, error)" default:"info"`
|
LogLevel string `flag:"log-level" desc:"Log level (debug, info, warn, error)" default:"info"`
|
||||||
StaticDir string `flag:"static-dir" desc:"Static file directory to serve on /static path" default:""`
|
StaticDir string `flag:"static-dir" desc:"Static file directory to serve on /static path" default:""`
|
||||||
|
StaticPath string `flag:"static-path" desc:"Path to serve static file directory" default:"/static"`
|
||||||
NotificationURI string `flag:"notification-uri" desc:"Notification URI"`
|
NotificationURI string `flag:"notification-uri" desc:"Notification URI"`
|
||||||
TrustStoreFile string `flag:"trust-store-file" desc:"Trust store used by HTTP signature verifier (.pem or .p12)"`
|
TrustStoreFile string `flag:"trust-store-file" desc:"Trust store used by HTTP signature verifier (.pem or .p12)"`
|
||||||
}
|
}
|
||||||
|
|
||||||
|
func (c *Config) Validate() error {
|
||||||
|
if matched, _ := regexp.MatchString(`^/\w+$`, c.StaticPath); !matched {
|
||||||
|
return fmt.Errorf("invalid static path: %s", c.StaticPath)
|
||||||
|
}
|
||||||
|
return nil
|
||||||
|
}
|
||||||
|
|
Loading…
Reference in New Issue
Block a user