Skip to content

Commit

Permalink
Moved and renamed all filter name constants
Browse files Browse the repository at this point in the history
Moved all filter name constants to the filters package, added
constants for the filters that used string values.

By having all filters in the same place, with consistent naming, it
makes it easier to use Filters if you use Skipper as a Library and
build routes using code.

Signed-off-by: Peter Klijn <[email protected]>
  • Loading branch information
peterklijn committed Aug 13, 2021
1 parent 27bcb0d commit 9cc68a1
Show file tree
Hide file tree
Showing 89 changed files with 501 additions and 547 deletions.
11 changes: 5 additions & 6 deletions dataclients/kubernetes/kube.go
Original file line number Diff line number Diff line change
Expand Up @@ -13,8 +13,7 @@ import (

log "github.com/sirupsen/logrus"
"github.com/zalando/skipper/eskip"
"github.com/zalando/skipper/filters/accesslog"
"github.com/zalando/skipper/filters/builtin"
"github.com/zalando/skipper/filters"
"github.com/zalando/skipper/predicates"
)

Expand Down Expand Up @@ -359,11 +358,11 @@ func (c *Client) loadAndConvert() ([]*eskip.Route, error) {
func shuntRoute(r *eskip.Route) {
r.Filters = []*eskip.Filter{
{
Name: builtin.StatusName,
Name: filters.StatusName,
Args: []interface{}{502.0},
},
{
Name: builtin.InlineContentName,
Name: filters.InlineContentName,
Args: []interface{}{"no endpoints"},
},
}
Expand All @@ -373,7 +372,7 @@ func shuntRoute(r *eskip.Route) {

func healthcheckRoute(healthy, reverseSourcePredicate bool) *eskip.Route {
logFilters := []*eskip.Filter{{
Name: builtin.StatusName,
Name: filters.StatusName,
Args: []interface{}{http.StatusOK}},
}
if !healthy {
Expand All @@ -382,7 +381,7 @@ func healthcheckRoute(healthy, reverseSourcePredicate bool) *eskip.Route {
// log if unhealthy or a debug loglevel
if healthy && !log.IsLevelEnabled(log.DebugLevel) {
logFilters = append(logFilters, &eskip.Filter{
Name: accesslog.DisableAccessLogName,
Name: filters.DisableAccessLogName,
Args: []interface{}{200},
})
}
Expand Down
4 changes: 2 additions & 2 deletions dataclients/kubernetes/kube_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -33,7 +33,7 @@ import (

"github.com/zalando/skipper/dataclients/kubernetes/definitions"
"github.com/zalando/skipper/eskip"
"github.com/zalando/skipper/filters/builtin"
"github.com/zalando/skipper/filters"
"github.com/zalando/skipper/predicates"
)

Expand Down Expand Up @@ -399,7 +399,7 @@ func checkHealthcheck(t *testing.T, got []*eskip.Route, expected, healthy, rever
}

for _, f := range r.Filters {
if f.Name != builtin.StatusName {
if f.Name != filters.StatusName {
continue
}

Expand Down
9 changes: 2 additions & 7 deletions filters/accesslog/control.go
Original file line number Diff line number Diff line change
Expand Up @@ -3,11 +3,6 @@ package accesslog
import "github.com/zalando/skipper/filters"

const (
// DisableAccessLogName is the filter name seen by the user
DisableAccessLogName = "disableAccessLog"

// EnableAccessLogName is the filter name seen by the user
EnableAccessLogName = "enableAccessLog"

// AccessLogEnabledKey is the key used in the state bag to pass the access log state to the proxy.
AccessLogEnabledKey = "statebag:access_log:proxy:enabled"
Expand Down Expand Up @@ -64,7 +59,7 @@ func NewDisableAccessLog() filters.Spec {
return &disableAccessLog{}
}

func (*disableAccessLog) Name() string { return DisableAccessLogName }
func (*disableAccessLog) Name() string { return filters.DisableAccessLogName }

func (al *disableAccessLog) CreateFilter(args []interface{}) (filters.Filter, error) {
return extractFilterValues(args, false)
Expand All @@ -82,7 +77,7 @@ func NewEnableAccessLog() filters.Spec {
return &enableAccessLog{}
}

func (*enableAccessLog) Name() string { return EnableAccessLogName }
func (*enableAccessLog) Name() string { return filters.EnableAccessLogName }

func (al *enableAccessLog) CreateFilter(args []interface{}) (filters.Filter, error) {
return extractFilterValues(args, true)
Expand Down
7 changes: 1 addition & 6 deletions filters/accesslog/disable.go
Original file line number Diff line number Diff line change
Expand Up @@ -4,11 +4,6 @@ import (
"github.com/zalando/skipper/filters"
)

const (
// AccessLogDisabledName is the filter name seen by the user
AccessLogDisabledName = "accessLogDisabled"
)

type accessLogDisabled struct {
disabled bool
}
Expand All @@ -21,7 +16,7 @@ func NewAccessLogDisabled() filters.Spec {
return &accessLogDisabled{}
}

func (*accessLogDisabled) Name() string { return AccessLogDisabledName }
func (*accessLogDisabled) Name() string { return filters.AccessLogDisabledName }

func (*accessLogDisabled) CreateFilter(args []interface{}) (filters.Filter, error) {
if len(args) != 1 {
Expand Down
2 changes: 1 addition & 1 deletion filters/apiusagemonitoring/filter.go
Original file line number Diff line number Diff line change
Expand Up @@ -24,7 +24,7 @@ const (
)

const (
stateBagKey = "filter." + Name
stateBagKey = "filter." + filters.ApiUsageMonitoringName
)

const (
Expand Down
2 changes: 1 addition & 1 deletion filters/apiusagemonitoring/noop.go
Original file line number Diff line number Diff line change
Expand Up @@ -7,7 +7,7 @@ type noopSpec struct {
}

func (*noopSpec) Name() string {
return Name
return filters.ApiUsageMonitoringName
}

func (s *noopSpec) CreateFilter(config []interface{}) (filters.Filter, error) {
Expand Down
8 changes: 3 additions & 5 deletions filters/apiusagemonitoring/spec.go
Original file line number Diff line number Diff line change
Expand Up @@ -13,15 +13,13 @@ import (
)

const (
Name = "apiUsageMonitoring"

unknownPlaceholder = "{unknown}"
noMatchPlaceholder = "{no-match}"
noTagPlaceholder = "{no-tag}"
)

var (
log = logrus.WithField("filter", Name)
log = logrus.WithField("filter", filters.ApiUsageMonitoringName)
regCache = sync.Map{}
)

Expand All @@ -47,7 +45,7 @@ func NewApiUsageMonitoring(
realmsTrackingPattern string,
) filters.Spec {
if !enabled {
log.Debugf("filter %q is not enabled. spec returns `noop` filters.", Name)
log.Debugf("filter %q is not enabled. spec returns `noop` filters.", filters.ApiUsageMonitoringName)
return &noopSpec{&noopFilter{}}
}

Expand Down Expand Up @@ -122,7 +120,7 @@ type apiUsageMonitoringSpec struct {
}

func (s *apiUsageMonitoringSpec) Name() string {
return Name
return filters.ApiUsageMonitoringName
}

func (s *apiUsageMonitoringSpec) CreateFilter(args []interface{}) (filter filters.Filter, err error) {
Expand Down
3 changes: 1 addition & 2 deletions filters/auth/basic.go
Original file line number Diff line number Diff line change
Expand Up @@ -7,7 +7,6 @@ import (
)

const (
Name = "basicAuth"
ForceBasicAuthHeaderName = "WWW-Authenticate"
ForceBasicAuthHeaderValue = "Basic realm="
DefaultRealmName = "Basic Realm"
Expand Down Expand Up @@ -72,4 +71,4 @@ func (spec *basicSpec) CreateFilter(config []interface{}) (filters.Filter, error
}, nil
}

func (spec *basicSpec) Name() string { return Name }
func (spec *basicSpec) Name() string { return filters.BasicAuthName }
6 changes: 1 addition & 5 deletions filters/auth/bearer.go
Original file line number Diff line number Diff line change
Expand Up @@ -5,10 +5,6 @@ import (
"github.com/zalando/skipper/secrets"
)

const (
BearerInjectorName = "bearerinjector"
)

type (
bearerInjectorSpec struct {
secretsReader secrets.SecretsReader
Expand All @@ -26,7 +22,7 @@ func NewBearerInjector(sr secrets.SecretsReader) filters.Spec {
}

func (*bearerInjectorSpec) Name() string {
return BearerInjectorName
return filters.BearerInjectorName
}

func (b *bearerInjectorSpec) CreateFilter(args []interface{}) (filters.Filter, error) {
Expand Down
4 changes: 2 additions & 2 deletions filters/auth/bearer_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -15,8 +15,8 @@ import (

func Test_bearerInjectorSpec_Name(t *testing.T) {
b := &bearerInjectorSpec{}
if got := b.Name(); got != BearerInjectorName {
t.Errorf("bearerInjectorSpec.Name() = %v, want %v", got, BearerInjectorName)
if got := b.Name(); got != filters.BearerInjectorName {
t.Errorf("bearerInjectorSpec.Name() = %v, want %v", got, filters.BearerInjectorName)
}
}

Expand Down
6 changes: 1 addition & 5 deletions filters/auth/forwardtoken.go
Original file line number Diff line number Diff line change
Expand Up @@ -10,10 +10,6 @@ import (
"golang.org/x/net/http/httpguts"
)

const (
ForwardTokenName = "forwardToken"
)

type (
forwardTokenSpec struct{}
forwardTokenFilter struct {
Expand All @@ -29,7 +25,7 @@ func NewForwardToken() filters.Spec {
}

func (s *forwardTokenSpec) Name() string {
return ForwardTokenName
return filters.ForwardTokenName
}

func (*forwardTokenSpec) CreateFilter(args []interface{}) (filters.Filter, error) {
Expand Down
4 changes: 1 addition & 3 deletions filters/auth/grant.go
Original file line number Diff line number Diff line change
Expand Up @@ -13,8 +13,6 @@ import (
)

const (
OAuthGrantName = "oauthGrant"

secretsRefreshInternal = time.Minute
tokenWasRefreshed = "oauth-did-refresh"
)
Expand All @@ -31,7 +29,7 @@ type grantFilter struct {
config OAuthConfig
}

func (s *grantSpec) Name() string { return OAuthGrantName }
func (s *grantSpec) Name() string { return filters.OAuthGrantName }

func (s *grantSpec) CreateFilter([]interface{}) (filters.Filter, error) {
return &grantFilter{
Expand Down
5 changes: 3 additions & 2 deletions filters/auth/grant_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -11,6 +11,7 @@ import (
"time"

"github.com/zalando/skipper/eskip"
"github.com/zalando/skipper/filters"
"github.com/zalando/skipper/filters/auth"
"github.com/zalando/skipper/filters/builtin"
"github.com/zalando/skipper/proxy/proxytest"
Expand Down Expand Up @@ -178,8 +179,8 @@ func newAuthProxy(config *auth.OAuthConfig, routes ...*eskip.Route) (*proxytest.
func newSimpleGrantAuthProxy(t *testing.T, config *auth.OAuthConfig) *proxytest.TestProxy {
proxy, err := newAuthProxy(config, &eskip.Route{
Filters: []*eskip.Filter{
{Name: auth.OAuthGrantName},
{Name: "status", Args: []interface{}{http.StatusNoContent}},
{Name: filters.OAuthGrantName},
{Name: filters.StatusName, Args: []interface{}{http.StatusNoContent}},
},
BackendType: eskip.ShuntBackend,
})
Expand Down
4 changes: 1 addition & 3 deletions filters/auth/grantcallback.go
Original file line number Diff line number Diff line change
Expand Up @@ -8,8 +8,6 @@ import (
"golang.org/x/oauth2"
)

const GrantCallbackName = "grantCallback"

type grantCallbackSpec struct {
config OAuthConfig
}
Expand All @@ -18,7 +16,7 @@ type grantCallbackFilter struct {
config OAuthConfig
}

func (*grantCallbackSpec) Name() string { return GrantCallbackName }
func (*grantCallbackSpec) Name() string { return filters.GrantCallbackName }

func (s *grantCallbackSpec) CreateFilter([]interface{}) (filters.Filter, error) {
return &grantCallbackFilter{
Expand Down
4 changes: 1 addition & 3 deletions filters/auth/grantclaimsquery.go
Original file line number Diff line number Diff line change
Expand Up @@ -9,14 +9,12 @@ package auth

import "github.com/zalando/skipper/filters"

const GrantClaimsQueryName = "grantClaimsQuery"

type grantClaimsQuerySpec struct {
oidcSpec oidcIntrospectionSpec
}

func (s *grantClaimsQuerySpec) Name() string {
return GrantClaimsQueryName
return filters.GrantClaimsQueryName
}

func (s *grantClaimsQuerySpec) CreateFilter(args []interface{}) (filters.Filter, error) {
Expand Down
7 changes: 4 additions & 3 deletions filters/auth/grantclaimsquery_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -6,6 +6,7 @@ import (
"testing"

"github.com/zalando/skipper/eskip"
"github.com/zalando/skipper/filters"
"github.com/zalando/skipper/filters/auth"
"github.com/zalando/skipper/proxy/proxytest"
)
Expand All @@ -29,9 +30,9 @@ func TestGrantClaimsQuery(t *testing.T) {
createProxyForQuery := func(config *auth.OAuthConfig, query string) *proxytest.TestProxy {
proxy, err := newAuthProxy(config, &eskip.Route{
Filters: []*eskip.Filter{
{Name: auth.OAuthGrantName},
{Name: auth.GrantClaimsQueryName, Args: []interface{}{query}},
{Name: "status", Args: []interface{}{http.StatusNoContent}},
{Name: filters.OAuthGrantName},
{Name: filters.GrantClaimsQueryName, Args: []interface{}{query}},
{Name: filters.StatusName, Args: []interface{}{http.StatusNoContent}},
},
BackendType: eskip.ShuntBackend,
})
Expand Down
3 changes: 1 addition & 2 deletions filters/auth/grantlogout.go
Original file line number Diff line number Diff line change
Expand Up @@ -14,7 +14,6 @@ import (
)

const (
GrantLogoutName = "grantLogout"
revokeTokenKey = "token"
revokeTokenTypeKey = "token_type_hint"
refreshTokenType = "refresh_token"
Expand All @@ -35,7 +34,7 @@ type revokeErrorResponse struct {
ErrorDescription string `json:"error_description"`
}

func (*grantLogoutSpec) Name() string { return GrantLogoutName }
func (*grantLogoutSpec) Name() string { return filters.GrantLogoutName }

func (s *grantLogoutSpec) CreateFilter([]interface{}) (filters.Filter, error) {
return &grantLogoutFilter{
Expand Down
5 changes: 3 additions & 2 deletions filters/auth/grantlogout_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -4,6 +4,7 @@ import (
"encoding/base64"
"encoding/json"
"github.com/zalando/skipper/eskip"
"github.com/zalando/skipper/filters"
"github.com/zalando/skipper/filters/auth"
"net/http"
"net/http/httptest"
Expand Down Expand Up @@ -104,8 +105,8 @@ func TestGrantLogout(t *testing.T) {

proxy, err := newAuthProxy(config, &eskip.Route{
Filters: []*eskip.Filter{
{Name: auth.GrantLogoutName},
{Name: "status", Args: []interface{}{http.StatusNoContent}},
{Name: filters.GrantLogoutName},
{Name: filters.StatusName, Args: []interface{}{http.StatusNoContent}},
},
BackendType: eskip.ShuntBackend,
})
Expand Down
7 changes: 5 additions & 2 deletions filters/auth/grantprep.go
Original file line number Diff line number Diff line change
@@ -1,6 +1,9 @@
package auth

import "github.com/zalando/skipper/eskip"
import (
"github.com/zalando/skipper/eskip"
"github.com/zalando/skipper/filters"
)

const (
defaultCallbackRouteID = "__oauth2_grant_callback"
Expand All @@ -26,7 +29,7 @@ func (p *grantPrep) Do(r []*eskip.Route) []*eskip.Route {
},
}},
Filters: []*eskip.Filter{{
Name: GrantCallbackName,
Name: filters.GrantCallbackName,
}},
BackendType: eskip.ShuntBackend,
})
Expand Down
Loading

0 comments on commit 9cc68a1

Please sign in to comment.