Allow hooks file to be parsed as a template

Add a -template command line option that instructs webhook to parse the
hooks files as Go text templates.

Includes a `getenv` template func for retrieving environment variables.
This commit is contained in:
Cameron Moore 2017-08-15 18:02:33 -05:00
parent ba0adb117a
commit f5f04ddaa2
5 changed files with 157 additions and 11 deletions

View file

@ -34,6 +34,7 @@ var (
hotReload = flag.Bool("hotreload", false, "watch hooks file for changes and reload them automatically")
hooksURLPrefix = flag.String("urlprefix", "hooks", "url prefix to use for served hooks (protocol://yourserver:port/PREFIX/:hook-id)")
secure = flag.Bool("secure", false, "use HTTPS instead of HTTP")
asTemplate = flag.Bool("template", false, "parse hooks file as a Go template")
cert = flag.String("cert", "cert.pem", "path to the HTTPS certificate pem file")
key = flag.String("key", "key.pem", "path to the HTTPS certificate private key pem file")
justDisplayVersion = flag.Bool("version", false, "display webhook version and quit")
@ -99,7 +100,7 @@ func main() {
newHooks := hook.Hooks{}
err := newHooks.LoadFromFile(hooksFilePath)
err := newHooks.LoadFromFile(hooksFilePath, *asTemplate)
if err != nil {
log.Printf("couldn't load hooks from file! %+v\n", err)
@ -407,7 +408,7 @@ func reloadHooks(hooksFilePath string) {
// parse and swap
log.Printf("attempting to reload hooks from %s\n", hooksFilePath)
err := hooksInFile.LoadFromFile(hooksFilePath)
err := hooksInFile.LoadFromFile(hooksFilePath, *asTemplate)
if err != nil {
log.Printf("couldn't load hooks from file! %+v\n", err)