diff --git a/pkg/autologin/autologin.go b/pkg/handler/autologin/autologin.go similarity index 73% rename from pkg/autologin/autologin.go rename to pkg/handler/autologin/autologin.go index c84c269..9113d40 100644 --- a/pkg/autologin/autologin.go +++ b/pkg/handler/autologin/autologin.go @@ -8,17 +8,17 @@ import ( "github.com/nais/wonderwall/pkg/config" ) -type Options struct { +type AutoLogin struct { Enabled bool IgnorePatterns []string } -func (o *Options) NeedsLogin(r *http.Request, isAuthenticated bool) bool { - if isAuthenticated || !o.Enabled { +func (a *AutoLogin) NeedsLogin(r *http.Request, isAuthenticated bool) bool { + if isAuthenticated || !a.Enabled { return false } - for _, pattern := range o.IgnorePatterns { + for _, pattern := range a.IgnorePatterns { path := r.URL.Path if !strings.HasPrefix(path, "/") { path = "/" + path @@ -33,7 +33,7 @@ func (o *Options) NeedsLogin(r *http.Request, isAuthenticated bool) bool { return true } -func NewOptions(cfg *config.Config) (*Options, error) { +func New(cfg *config.Config) (*AutoLogin, error) { seen := make(map[string]bool) patterns := make([]string, 0) @@ -48,7 +48,7 @@ func NewOptions(cfg *config.Config) (*Options, error) { } } - return &Options{ + return &AutoLogin{ Enabled: cfg.AutoLogin, IgnorePatterns: patterns, }, nil diff --git a/pkg/handler/handler.go b/pkg/handler/handler.go index c19e0d3..eb00b34 100644 --- a/pkg/handler/handler.go +++ b/pkg/handler/handler.go @@ -6,10 +6,10 @@ import ( "net/http/httputil" "time" - "github.com/nais/wonderwall/pkg/autologin" "github.com/nais/wonderwall/pkg/config" "github.com/nais/wonderwall/pkg/cookie" "github.com/nais/wonderwall/pkg/crypto" + "github.com/nais/wonderwall/pkg/handler/autologin" "github.com/nais/wonderwall/pkg/loginstatus" "github.com/nais/wonderwall/pkg/middleware" "github.com/nais/wonderwall/pkg/openid/client" @@ -19,7 +19,7 @@ import ( ) type Handler struct { - AutoLogin *autologin.Options + AutoLogin *autologin.AutoLogin Client client.Client Config *config.Config CookieOptions cookie.Options @@ -42,7 +42,7 @@ func NewHandler( return nil, err } - autoLogin, err := autologin.NewOptions(cfg) + autoLogin, err := autologin.New(cfg) if err != nil { return nil, err }