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

1
go.mod
View File

@ -25,6 +25,7 @@ require (
github.com/sirupsen/logrus v1.4.1 github.com/sirupsen/logrus v1.4.1
github.com/stretchr/objx v0.2.0 // indirect github.com/stretchr/objx v0.2.0 // indirect
github.com/stretchr/testify v1.3.0 github.com/stretchr/testify v1.3.0
github.com/thomseddon/go-flags v1.4.1-0.20190507181358-ce437f05b7fb
github.com/vulcand/predicate v1.1.0 // indirect github.com/vulcand/predicate v1.1.0 // indirect
golang.org/x/crypto v0.0.0-20190422183909-d864b10871cd // indirect golang.org/x/crypto v0.0.0-20190422183909-d864b10871cd // indirect
golang.org/x/net v0.0.0-20190420063019-afa5a82059c6 // indirect golang.org/x/net v0.0.0-20190420063019-afa5a82059c6 // indirect

4
go.sum
View File

@ -55,6 +55,10 @@ github.com/stretchr/objx v0.2.0/go.mod h1:qt09Ya8vawLte6SNmTgCsAVtYtaKzEcn8ATUoH
github.com/stretchr/testify v1.2.2/go.mod h1:a8OnRcib4nhh0OaRAV+Yts87kKdq0PP7pXfy6kDkUVs= github.com/stretchr/testify v1.2.2/go.mod h1:a8OnRcib4nhh0OaRAV+Yts87kKdq0PP7pXfy6kDkUVs=
github.com/stretchr/testify v1.3.0 h1:TivCn/peBQ7UY8ooIcPgZFpTNSz0Q2U6UrFlUfqbe0Q= github.com/stretchr/testify v1.3.0 h1:TivCn/peBQ7UY8ooIcPgZFpTNSz0Q2U6UrFlUfqbe0Q=
github.com/stretchr/testify v1.3.0/go.mod h1:M5WIy9Dh21IEIfnGCwXGc5bZfKNJtfHm1UVUgZn+9EI= github.com/stretchr/testify v1.3.0/go.mod h1:M5WIy9Dh21IEIfnGCwXGc5bZfKNJtfHm1UVUgZn+9EI=
github.com/thomseddon/go-flags v1.4.0 h1:cHj56pbnQxlGo2lx2P8f0Dph4TRYKBJzoPuF2lqNvW4=
github.com/thomseddon/go-flags v1.4.0/go.mod h1:NK9eZpNBmSKVxvyB/MExg6jW0Bo9hQyAuCP+b8MJFow=
github.com/thomseddon/go-flags v1.4.1-0.20190507181358-ce437f05b7fb h1:L311/fJ7WXmFDDtuhf22PkVJqZpqLbEsmGSTEGv7ZQY=
github.com/thomseddon/go-flags v1.4.1-0.20190507181358-ce437f05b7fb/go.mod h1:NK9eZpNBmSKVxvyB/MExg6jW0Bo9hQyAuCP+b8MJFow=
github.com/vulcand/predicate v1.1.0 h1:Gq/uWopa4rx/tnZu2opOSBqHK63Yqlou/SzrbwdJiNg= github.com/vulcand/predicate v1.1.0 h1:Gq/uWopa4rx/tnZu2opOSBqHK63Yqlou/SzrbwdJiNg=
github.com/vulcand/predicate v1.1.0/go.mod h1:mlccC5IRBoc2cIFmCB8ZM62I3VDb6p2GXESMHa3CnZg= github.com/vulcand/predicate v1.1.0/go.mod h1:mlccC5IRBoc2cIFmCB8ZM62I3VDb6p2GXESMHa3CnZg=
golang.org/x/crypto v0.0.0-20190308221718-c2843e01d9a2/go.mod h1:djNgcEr1/C05ACkg1iLfiJU5Ep61QUkGW8qpdssI0+w= golang.org/x/crypto v0.0.0-20190308221718-c2843e01d9a2/go.mod h1:djNgcEr1/C05ACkg1iLfiJU5Ep61QUkGW8qpdssI0+w=

View File

@ -14,7 +14,7 @@ import (
"strings" "strings"
"time" "time"
"github.com/jessevdk/go-flags" "github.com/thomseddon/go-flags"
"github.com/thomseddon/traefik-forward-auth/internal/provider" "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 { 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 p.UnknownOptionHandler = c.parseUnknownFlag
i := flags.NewIniParser(p) i := flags.NewIniParser(p)
@ -157,6 +157,7 @@ func (c *Config) parseFlags(args []string) error {
return err return err
} }
fmt.Println("config format deprecated, please use ini format")
return i.Parse(converted) 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("inicookiename", c.CookieName, "should be read from ini file")
assert.Equal("csrfcookiename", c.CSRFCookieName, "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("/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) { func TestConfigFileBackwardsCompatability(t *testing.T) {

View File

@ -1,3 +1,5 @@
cookie-name=inicookiename cookie-name=inicookiename
csrf-cookie-name=inicsrfcookiename csrf-cookie-name=inicsrfcookiename
url-path=one url-path=one
rule.1.action=allow
rule.1.rule=PathPrefix(`/one`)

View File

@ -1 +1,3 @@
url-path=two url-path=two
rule.two.action=auth
rule.two.rule=Host(`two.com`) && Path(`/two`)