Handle unknown ini options

This commit is contained in:
Thom Seddon
2019-05-07 19:17:42 +01:00
parent d1b12e4ffb
commit a4a34dcd76
6 changed files with 24 additions and 2 deletions

View File

@ -14,7 +14,7 @@ import (
"strings"
"time"
"github.com/jessevdk/go-flags"
"github.com/thomseddon/go-flags"
"github.com/thomseddon/traefik-forward-auth/internal/provider"
)
@ -141,7 +141,7 @@ func NewConfig(args []string) (Config, error) {
}
func (c *Config) parseFlags(args []string) error {
p := flags.NewParser(c, flags.Default)
p := flags.NewParser(c, flags.Default | flags.IniUnknownOptionHandler)
p.UnknownOptionHandler = c.parseUnknownFlag
i := flags.NewIniParser(p)
@ -157,6 +157,7 @@ func (c *Config) parseFlags(args []string) error {
return err
}
fmt.Println("config format deprecated, please use ini format")
return i.Parse(converted)
}

View File

@ -165,6 +165,18 @@ func TestConfigParseIni(t *testing.T) {
assert.Equal("inicookiename", c.CookieName, "should be read from ini file")
assert.Equal("csrfcookiename", c.CSRFCookieName, "should be read from ini file")
assert.Equal("/two", c.Path, "variable in second ini file should override first ini file")
assert.Equal(map[string]*Rule{
"1": {
Action: "allow",
Rule: "PathPrefix(`/one`)",
Provider: "google",
},
"two": {
Action: "auth",
Rule: "Host(`two.com`) && Path(`/two`)",
Provider: "google",
},
}, c.Rules)
}
func TestConfigFileBackwardsCompatability(t *testing.T) {