From a4a34dcd76bc4cca74a034e902b40218429054a6 Mon Sep 17 00:00:00 2001 From: Thom Seddon Date: Tue, 7 May 2019 19:17:42 +0100 Subject: [PATCH] Handle unknown ini options --- go.mod | 1 + go.sum | 4 ++++ internal/config.go | 5 +++-- internal/config_test.go | 12 ++++++++++++ test/config0 | 2 ++ test/config1 | 2 ++ 6 files changed, 24 insertions(+), 2 deletions(-) diff --git a/go.mod b/go.mod index a828e970..b8ef7ce4 100644 --- a/go.mod +++ b/go.mod @@ -25,6 +25,7 @@ require ( github.com/sirupsen/logrus v1.4.1 github.com/stretchr/objx v0.2.0 // indirect 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 golang.org/x/crypto v0.0.0-20190422183909-d864b10871cd // indirect golang.org/x/net v0.0.0-20190420063019-afa5a82059c6 // indirect diff --git a/go.sum b/go.sum index 7ed66c64..a32bac2b 100644 --- a/go.sum +++ b/go.sum @@ -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.3.0 h1:TivCn/peBQ7UY8ooIcPgZFpTNSz0Q2U6UrFlUfqbe0Q= 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/go.mod h1:mlccC5IRBoc2cIFmCB8ZM62I3VDb6p2GXESMHa3CnZg= golang.org/x/crypto v0.0.0-20190308221718-c2843e01d9a2/go.mod h1:djNgcEr1/C05ACkg1iLfiJU5Ep61QUkGW8qpdssI0+w= diff --git a/internal/config.go b/internal/config.go index 123271fc..a5a78e0b 100644 --- a/internal/config.go +++ b/internal/config.go @@ -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) } diff --git a/internal/config_test.go b/internal/config_test.go index 3bba18c6..c43c5dfe 100644 --- a/internal/config_test.go +++ b/internal/config_test.go @@ -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) { diff --git a/test/config0 b/test/config0 index 8a5e1112..4edf522d 100644 --- a/test/config0 +++ b/test/config0 @@ -1,3 +1,5 @@ cookie-name=inicookiename csrf-cookie-name=inicsrfcookiename url-path=one +rule.1.action=allow +rule.1.rule=PathPrefix(`/one`) diff --git a/test/config1 b/test/config1 index 49f265ea..a4013fe6 100644 --- a/test/config1 +++ b/test/config1 @@ -1 +1,3 @@ url-path=two +rule.two.action=auth +rule.two.rule=Host(`two.com`) && Path(`/two`)