diff --git a/dataclients/kubernetes/ingress.go b/dataclients/kubernetes/ingress.go index 6f79934548..2e46f3d172 100644 --- a/dataclients/kubernetes/ingress.go +++ b/dataclients/kubernetes/ingress.go @@ -11,8 +11,7 @@ import ( log "github.com/sirupsen/logrus" "github.com/zalando/skipper/dataclients/kubernetes/definitions" "github.com/zalando/skipper/eskip" - "github.com/zalando/skipper/predicates/primitive" - "github.com/zalando/skipper/predicates/traffic" + "github.com/zalando/skipper/predicates" ) const ( @@ -249,14 +248,14 @@ func setTraffic(r *eskip.Route, svcName string, weight float64, noopCount int) { // add traffic predicate if traffic weight is between 0.0 and 1.0 if 0.0 < weight && weight < 1.0 { r.Predicates = append([]*eskip.Predicate{{ - Name: traffic.PredicateName, + Name: predicates.TrafficName, Args: []interface{}{weight}, }}, r.Predicates...) log.Debugf("Traffic weight %.2f for backend '%s'", weight, svcName) } for i := 0; i < noopCount; i++ { r.Predicates = append([]*eskip.Predicate{{ - Name: primitive.NameTrue, + Name: predicates.TrueName, Args: []interface{}{}, }}, r.Predicates...) } diff --git a/dataclients/kubernetes/kube.go b/dataclients/kubernetes/kube.go index 5d2e20cb5b..56d984252f 100644 --- a/dataclients/kubernetes/kube.go +++ b/dataclients/kubernetes/kube.go @@ -13,9 +13,8 @@ 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/predicates/source" + "github.com/zalando/skipper/filters" + "github.com/zalando/skipper/predicates" ) const ( @@ -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"}, }, } @@ -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 { @@ -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}, }) } @@ -390,12 +389,12 @@ func healthcheckRoute(healthy, reverseSourcePredicate bool) *eskip.Route { var p []*eskip.Predicate if reverseSourcePredicate { p = []*eskip.Predicate{{ - Name: source.NameLast, + Name: predicates.SourceFromLastName, Args: internalIPs, }} } else { p = []*eskip.Predicate{{ - Name: source.Name, + Name: predicates.SourceName, Args: internalIPs, }} } diff --git a/dataclients/kubernetes/kube_test.go b/dataclients/kubernetes/kube_test.go index e5cbab3cd2..f484977cef 100644 --- a/dataclients/kubernetes/kube_test.go +++ b/dataclients/kubernetes/kube_test.go @@ -32,8 +32,8 @@ import ( "github.com/zalando/skipper/dataclients/kubernetes/definitions" "github.com/zalando/skipper/eskip" - "github.com/zalando/skipper/filters/builtin" - "github.com/zalando/skipper/predicates/source" + "github.com/zalando/skipper/filters" + "github.com/zalando/skipper/predicates" ) type testAPI struct { @@ -364,10 +364,10 @@ func checkHealthcheck(t *testing.T, got []*eskip.Route, expected, healthy, rever var found bool for _, p := range r.Predicates { - if reversed && p.Name != source.NameLast { + if reversed && p.Name != predicates.SourceFromLastName { continue } - if !reversed && p.Name != source.Name { + if !reversed && p.Name != predicates.SourceName { continue } @@ -398,7 +398,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 } diff --git a/dataclients/kubernetes/redirect.go b/dataclients/kubernetes/redirect.go index 9ea3711bc7..e85787233f 100644 --- a/dataclients/kubernetes/redirect.go +++ b/dataclients/kubernetes/redirect.go @@ -8,7 +8,7 @@ import ( log "github.com/sirupsen/logrus" "github.com/zalando/skipper/dataclients/kubernetes/definitions" "github.com/zalando/skipper/eskip" - "github.com/zalando/skipper/routing" + "github.com/zalando/skipper/predicates" ) const ( @@ -91,7 +91,7 @@ func initRedirectRoute(r *eskip.Route, code int) { // Give this route a higher weight so that it will get precedence over existing routes r.Predicates = append([]*eskip.Predicate{{ - Name: routing.WeightPredicateName, + Name: predicates.WeightName, Args: []interface{}{float64(1000)}, }}, r.Predicates...) @@ -112,7 +112,7 @@ func initDisableRedirectRoute(r *eskip.Route) { // Give this route a higher weight so that it will get precedence over existing routes r.Predicates = append([]*eskip.Predicate{{ - Name: routing.WeightPredicateName, + Name: predicates.WeightName, Args: []interface{}{float64(1000)}, }}, r.Predicates...) } diff --git a/filters/accesslog/control.go b/filters/accesslog/control.go index 7e7c6915f4..ce4e3860bf 100644 --- a/filters/accesslog/control.go +++ b/filters/accesslog/control.go @@ -3,11 +3,11 @@ package accesslog import "github.com/zalando/skipper/filters" const ( - // DisableAccessLogName is the filter name seen by the user - DisableAccessLogName = "disableAccessLog" + // Deprecated, use filters.DisableAccessLogName instead + DisableAccessLogName = filters.DisableAccessLogName - // EnableAccessLogName is the filter name seen by the user - EnableAccessLogName = "enableAccessLog" + // Deprecated, use filters.EnableAccessLogName instead + EnableAccessLogName = filters.EnableAccessLogName // AccessLogEnabledKey is the key used in the state bag to pass the access log state to the proxy. AccessLogEnabledKey = "statebag:access_log:proxy:enabled" @@ -64,7 +64,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) @@ -82,7 +82,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) diff --git a/filters/accesslog/disable.go b/filters/accesslog/disable.go index 9570de744f..a1bf32543c 100644 --- a/filters/accesslog/disable.go +++ b/filters/accesslog/disable.go @@ -5,7 +5,7 @@ import ( ) const ( - // AccessLogDisabledName is the filter name seen by the user + // Deprecated: use DisableAccessLogName or EnableAccessLogName AccessLogDisabledName = "accessLogDisabled" ) diff --git a/filters/apiusagemonitoring/filter.go b/filters/apiusagemonitoring/filter.go index 7b3dd6f2a2..ab409c6f89 100644 --- a/filters/apiusagemonitoring/filter.go +++ b/filters/apiusagemonitoring/filter.go @@ -24,7 +24,7 @@ const ( ) const ( - stateBagKey = "filter." + Name + stateBagKey = "filter." + filters.ApiUsageMonitoringName ) const ( diff --git a/filters/apiusagemonitoring/noop.go b/filters/apiusagemonitoring/noop.go index 51ccfd5e99..8a4754b138 100644 --- a/filters/apiusagemonitoring/noop.go +++ b/filters/apiusagemonitoring/noop.go @@ -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) { diff --git a/filters/apiusagemonitoring/spec.go b/filters/apiusagemonitoring/spec.go index 5576e106d7..e2f1c7d6b7 100644 --- a/filters/apiusagemonitoring/spec.go +++ b/filters/apiusagemonitoring/spec.go @@ -13,7 +13,8 @@ import ( ) const ( - Name = "apiUsageMonitoring" + // Deprecated, use filters.ApiUsageMonitoringName instead + Name = filters.ApiUsageMonitoringName unknownPlaceholder = "{unknown}" noMatchPlaceholder = "{no-match}" @@ -21,7 +22,7 @@ const ( ) var ( - log = logrus.WithField("filter", Name) + log = logrus.WithField("filter", filters.ApiUsageMonitoringName) regCache = sync.Map{} ) @@ -47,7 +48,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{}} } @@ -122,7 +123,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) { diff --git a/filters/auth/basic.go b/filters/auth/basic.go index d248cfa1d3..515a6e09a1 100644 --- a/filters/auth/basic.go +++ b/filters/auth/basic.go @@ -7,7 +7,9 @@ import ( ) const ( - Name = "basicAuth" + // Deprecated, use filters.BasicAuthName instead + Name = filters.BasicAuthName + ForceBasicAuthHeaderName = "WWW-Authenticate" ForceBasicAuthHeaderValue = "Basic realm=" DefaultRealmName = "Basic Realm" @@ -72,4 +74,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 } diff --git a/filters/auth/bearer.go b/filters/auth/bearer.go index bd78f6cda2..0c8d865834 100644 --- a/filters/auth/bearer.go +++ b/filters/auth/bearer.go @@ -6,7 +6,8 @@ import ( ) const ( - BearerInjectorName = "bearerinjector" + // Deprecated, use filters.BearerInjectorName instead + BearerInjectorName = filters.BearerInjectorName ) type ( @@ -26,7 +27,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) { diff --git a/filters/auth/bearer_test.go b/filters/auth/bearer_test.go index 3e0f9df916..04846a50e7 100644 --- a/filters/auth/bearer_test.go +++ b/filters/auth/bearer_test.go @@ -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) } } diff --git a/filters/auth/forwardtoken.go b/filters/auth/forwardtoken.go index 3550e4c77f..b28f9c6616 100644 --- a/filters/auth/forwardtoken.go +++ b/filters/auth/forwardtoken.go @@ -10,7 +10,8 @@ import ( ) const ( - ForwardTokenName = "forwardToken" + // Deprecated, use filters.ForwardTokenName instead + ForwardTokenName = filters.ForwardTokenName ) type ( @@ -28,7 +29,7 @@ func NewForwardToken() filters.Spec { } func (s *forwardTokenSpec) Name() string { - return ForwardTokenName + return filters.ForwardTokenName } func (*forwardTokenSpec) CreateFilter(args []interface{}) (filters.Filter, error) { diff --git a/filters/auth/grant.go b/filters/auth/grant.go index 5da6cd2e76..84e7cdb882 100644 --- a/filters/auth/grant.go +++ b/filters/auth/grant.go @@ -13,7 +13,8 @@ import ( ) const ( - OAuthGrantName = "oauthGrant" + // Deprecated, use filters.OAuthGrantName instead + OAuthGrantName = filters.OAuthGrantName secretsRefreshInternal = time.Minute tokenWasRefreshed = "oauth-did-refresh" @@ -31,7 +32,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{ diff --git a/filters/auth/grant_test.go b/filters/auth/grant_test.go index a7a5923504..842886a099 100644 --- a/filters/auth/grant_test.go +++ b/filters/auth/grant_test.go @@ -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" @@ -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, }) diff --git a/filters/auth/grantcallback.go b/filters/auth/grantcallback.go index df934e41d6..8044a948df 100644 --- a/filters/auth/grantcallback.go +++ b/filters/auth/grantcallback.go @@ -8,7 +8,9 @@ import ( "golang.org/x/oauth2" ) -const GrantCallbackName = "grantCallback" +// GrantCallbackName is the filter name +// Deprecated, use filters.GrantCallbackName instead +const GrantCallbackName = filters.GrantCallbackName type grantCallbackSpec struct { config OAuthConfig @@ -18,7 +20,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{ diff --git a/filters/auth/grantclaimsquery.go b/filters/auth/grantclaimsquery.go index dc8069fd30..72ab6dc196 100644 --- a/filters/auth/grantclaimsquery.go +++ b/filters/auth/grantclaimsquery.go @@ -9,14 +9,16 @@ package auth import "github.com/zalando/skipper/filters" -const GrantClaimsQueryName = "grantClaimsQuery" +// GrantClaimsQueryName is the filter name +// Deprecated, use filters.GrantClaimsQueryName instead +const GrantClaimsQueryName = filters.GrantClaimsQueryName type grantClaimsQuerySpec struct { oidcSpec oidcIntrospectionSpec } func (s *grantClaimsQuerySpec) Name() string { - return GrantClaimsQueryName + return filters.GrantClaimsQueryName } func (s *grantClaimsQuerySpec) CreateFilter(args []interface{}) (filters.Filter, error) { diff --git a/filters/auth/grantclaimsquery_test.go b/filters/auth/grantclaimsquery_test.go index 2965df728b..f4cd193e8d 100644 --- a/filters/auth/grantclaimsquery_test.go +++ b/filters/auth/grantclaimsquery_test.go @@ -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" ) @@ -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, }) diff --git a/filters/auth/grantlogout.go b/filters/auth/grantlogout.go index 5dfea7b429..297817289e 100644 --- a/filters/auth/grantlogout.go +++ b/filters/auth/grantlogout.go @@ -14,7 +14,9 @@ import ( ) const ( - GrantLogoutName = "grantLogout" + // Deprecated, use filters.GrantLogoutName instead + GrantLogoutName = filters.GrantLogoutName + revokeTokenKey = "token" revokeTokenTypeKey = "token_type_hint" refreshTokenType = "refresh_token" @@ -35,7 +37,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{ diff --git a/filters/auth/grantlogout_test.go b/filters/auth/grantlogout_test.go index 3fac470915..87fc1f45b2 100644 --- a/filters/auth/grantlogout_test.go +++ b/filters/auth/grantlogout_test.go @@ -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" @@ -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, }) diff --git a/filters/auth/grantprep.go b/filters/auth/grantprep.go index 5c7b339a05..76ee71caf7 100644 --- a/filters/auth/grantprep.go +++ b/filters/auth/grantprep.go @@ -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" @@ -26,7 +29,7 @@ func (p *grantPrep) Do(r []*eskip.Route) []*eskip.Route { }, }}, Filters: []*eskip.Filter{{ - Name: GrantCallbackName, + Name: filters.GrantCallbackName, }}, BackendType: eskip.ShuntBackend, }) diff --git a/filters/auth/oidc.go b/filters/auth/oidc.go index 71a52e4ddc..51c3028374 100644 --- a/filters/auth/oidc.go +++ b/filters/auth/oidc.go @@ -26,9 +26,12 @@ import ( ) const ( - OidcUserInfoName = "oauthOidcUserInfo" - OidcAnyClaimsName = "oauthOidcAnyClaims" - OidcAllClaimsName = "oauthOidcAllClaims" + // Deprecated, use filters.OAuthOidcUserInfoName instead + OidcUserInfoName = filters.OAuthOidcUserInfoName + // Deprecated, use filters.OAuthOidcAnyClaimsName instead + OidcAnyClaimsName = filters.OAuthOidcAnyClaimsName + // Deprecated, use filters.OAuthOidcAllClaimsName instead + OidcAllClaimsName = filters.OAuthOidcAllClaimsName oauthOidcCookieName = "skipperOauthOidc" stateValidity = 1 * time.Minute @@ -234,11 +237,11 @@ func (s *tokenOidcSpec) CreateFilter(args []interface{}) (filters.Filter, error) func (s *tokenOidcSpec) Name() string { switch s.typ { case checkOIDCUserInfo: - return OidcUserInfoName + return filters.OAuthOidcUserInfoName case checkOIDCAnyClaims: - return OidcAnyClaimsName + return filters.OAuthOidcAnyClaimsName case checkOIDCAllClaims: - return OidcAllClaimsName + return filters.OAuthOidcAllClaimsName } return AuthUnknown } diff --git a/filters/auth/oidc_introspection.go b/filters/auth/oidc_introspection.go index b017fca8ef..cb919a8754 100644 --- a/filters/auth/oidc_introspection.go +++ b/filters/auth/oidc_introspection.go @@ -13,8 +13,10 @@ import ( ) const ( - OidcClaimsQueryName = "oidcClaimsQuery" - oidcClaimsCacheKey = "oidcclaimscachekey" + // Deprecated, use filters.OidcClaimsQueryName instead + OidcClaimsQueryName = filters.OidcClaimsQueryName + + oidcClaimsCacheKey = "oidcclaimscachekey" ) var gjsonModifierMutex = sync.RWMutex{} @@ -43,7 +45,7 @@ func NewOIDCQueryClaimsFilter() filters.Spec { func (spec *oidcIntrospectionSpec) Name() string { switch spec.typ { case checkOIDCQueryClaims: - return OidcClaimsQueryName + return filters.OidcClaimsQueryName } return AuthUnknown } @@ -105,7 +107,7 @@ func (filter *oidcIntrospectionFilter) String() string { for _, query := range filter.paths { str = append(str, query.String()) } - return fmt.Sprintf("%s(%s)", OidcClaimsQueryName, strings.Join(str, "; ")) + return fmt.Sprintf("%s(%s)", filters.OidcClaimsQueryName, strings.Join(str, "; ")) } func (filter *oidcIntrospectionFilter) Request(ctx filters.FilterContext) { diff --git a/filters/auth/tokeninfo.go b/filters/auth/tokeninfo.go index a9c3f6c536..2a4d3b10ac 100644 --- a/filters/auth/tokeninfo.go +++ b/filters/auth/tokeninfo.go @@ -11,11 +11,16 @@ import ( ) const ( - OAuthTokeninfoAnyScopeName = "oauthTokeninfoAnyScope" - OAuthTokeninfoAllScopeName = "oauthTokeninfoAllScope" - OAuthTokeninfoAnyKVName = "oauthTokeninfoAnyKV" - OAuthTokeninfoAllKVName = "oauthTokeninfoAllKV" - tokeninfoCacheKey = "tokeninfo" + // Deprecated, use filters.OAuthTokeninfoAnyScopeName instead + OAuthTokeninfoAnyScopeName = filters.OAuthTokeninfoAnyScopeName + // Deprecated, use filters.OAuthTokeninfoAllScopeName instead + OAuthTokeninfoAllScopeName = filters.OAuthTokeninfoAllScopeName + // Deprecated, use filters.OAuthTokeninfoAnyKVName instead + OAuthTokeninfoAnyKVName = filters.OAuthTokeninfoAnyKVName + // Deprecated, use filters.OAuthTokeninfoAllKVName instead + OAuthTokeninfoAllKVName = filters.OAuthTokeninfoAllKVName + + tokeninfoCacheKey = "tokeninfo" ) type TokeninfoOptions struct { @@ -144,13 +149,13 @@ func TokeninfoWithOptions(create func(string, time.Duration) filters.Spec, o Tok func (s *tokeninfoSpec) Name() string { switch s.typ { case checkOAuthTokeninfoAnyScopes: - return OAuthTokeninfoAnyScopeName + return filters.OAuthTokeninfoAnyScopeName case checkOAuthTokeninfoAllScopes: - return OAuthTokeninfoAllScopeName + return filters.OAuthTokeninfoAllScopeName case checkOAuthTokeninfoAnyKV: - return OAuthTokeninfoAnyKVName + return filters.OAuthTokeninfoAnyKVName case checkOAuthTokeninfoAllKV: - return OAuthTokeninfoAllKVName + return filters.OAuthTokeninfoAllKVName } return AuthUnknown } @@ -212,13 +217,13 @@ func (s *tokeninfoSpec) CreateFilter(args []interface{}) (filters.Filter, error) func (f *tokeninfoFilter) String() string { switch f.typ { case checkOAuthTokeninfoAnyScopes: - return fmt.Sprintf("%s(%s)", OAuthTokeninfoAnyScopeName, strings.Join(f.scopes, ",")) + return fmt.Sprintf("%s(%s)", filters.OAuthTokeninfoAnyScopeName, strings.Join(f.scopes, ",")) case checkOAuthTokeninfoAllScopes: - return fmt.Sprintf("%s(%s)", OAuthTokeninfoAllScopeName, strings.Join(f.scopes, ",")) + return fmt.Sprintf("%s(%s)", filters.OAuthTokeninfoAllScopeName, strings.Join(f.scopes, ",")) case checkOAuthTokeninfoAnyKV: - return fmt.Sprintf("%s(%s)", OAuthTokeninfoAnyKVName, f.kv) + return fmt.Sprintf("%s(%s)", filters.OAuthTokeninfoAnyKVName, f.kv) case checkOAuthTokeninfoAllKV: - return fmt.Sprintf("%s(%s)", OAuthTokeninfoAllKVName, f.kv) + return fmt.Sprintf("%s(%s)", filters.OAuthTokeninfoAllKVName, f.kv) } return AuthUnknown } diff --git a/filters/auth/tokeninfo_test.go b/filters/auth/tokeninfo_test.go index a90baa711f..b45e564973 100644 --- a/filters/auth/tokeninfo_test.go +++ b/filters/auth/tokeninfo_test.go @@ -26,11 +26,11 @@ func TestOAuth2Tokeninfo(t *testing.T) { expected int }{{ msg: "uninitialized filter, no authorization header, scope check", - authType: OAuthTokeninfoAnyScopeName, + authType: filters.OAuthTokeninfoAnyScopeName, expected: http.StatusNotFound, }, { msg: "invalid token", - authType: OAuthTokeninfoAnyScopeName, + authType: filters.OAuthTokeninfoAnyScopeName, authBaseURL: testAuthPath, args: []interface{}{"not-matching-scope"}, hasAuth: true, @@ -38,7 +38,7 @@ func TestOAuth2Tokeninfo(t *testing.T) { expected: http.StatusUnauthorized, }, { msg: "invalid scope", - authType: OAuthTokeninfoAnyScopeName, + authType: filters.OAuthTokeninfoAnyScopeName, authBaseURL: testAuthPath, args: []interface{}{"not-matching-scope"}, hasAuth: true, @@ -46,7 +46,7 @@ func TestOAuth2Tokeninfo(t *testing.T) { expected: http.StatusForbidden, }, { msg: "oauthTokeninfoAnyScope: valid token, one valid scope", - authType: OAuthTokeninfoAnyScopeName, + authType: filters.OAuthTokeninfoAnyScopeName, authBaseURL: testAuthPath, args: []interface{}{testScope}, hasAuth: true, @@ -54,7 +54,7 @@ func TestOAuth2Tokeninfo(t *testing.T) { expected: http.StatusOK, }, { msg: "OAuthTokeninfoAnyScopeName: valid token, one valid scope, one invalid scope", - authType: OAuthTokeninfoAnyScopeName, + authType: filters.OAuthTokeninfoAnyScopeName, authBaseURL: testAuthPath, args: []interface{}{testScope, "other-scope"}, hasAuth: true, @@ -62,7 +62,7 @@ func TestOAuth2Tokeninfo(t *testing.T) { expected: http.StatusOK, }, { msg: "oauthTokeninfoAllScope(): valid token, valid scopes", - authType: OAuthTokeninfoAllScopeName, + authType: filters.OAuthTokeninfoAllScopeName, authBaseURL: testAuthPath, args: []interface{}{testScope, testScope2, testScope3}, hasAuth: true, @@ -70,7 +70,7 @@ func TestOAuth2Tokeninfo(t *testing.T) { expected: http.StatusOK, }, { msg: "oauthTokeninfoAllScope(): valid token, one valid scope, one invalid scope", - authType: OAuthTokeninfoAllScopeName, + authType: filters.OAuthTokeninfoAllScopeName, authBaseURL: testAuthPath, args: []interface{}{testScope, "other-scope"}, hasAuth: true, @@ -78,7 +78,7 @@ func TestOAuth2Tokeninfo(t *testing.T) { expected: http.StatusForbidden, }, { msg: "anyKV(): invalid key", - authType: OAuthTokeninfoAnyKVName, + authType: filters.OAuthTokeninfoAnyKVName, authBaseURL: testAuthPath, args: []interface{}{"not-matching-scope"}, hasAuth: true, @@ -86,7 +86,7 @@ func TestOAuth2Tokeninfo(t *testing.T) { expected: http.StatusOK, }, { msg: "anyKV(): valid token, one valid key, wrong value", - authType: OAuthTokeninfoAnyKVName, + authType: filters.OAuthTokeninfoAnyKVName, authBaseURL: testAuthPath, args: []interface{}{testKey, "other-value"}, hasAuth: true, @@ -94,7 +94,7 @@ func TestOAuth2Tokeninfo(t *testing.T) { expected: http.StatusForbidden, }, { msg: "anyKV(): valid token, one valid key value pair", - authType: OAuthTokeninfoAnyKVName, + authType: filters.OAuthTokeninfoAnyKVName, authBaseURL: testAuthPath, args: []interface{}{testKey, testValue}, hasAuth: true, @@ -102,7 +102,7 @@ func TestOAuth2Tokeninfo(t *testing.T) { expected: http.StatusOK, }, { msg: "anyKV(): valid token, one valid kv, multiple key value pairs1", - authType: OAuthTokeninfoAnyKVName, + authType: filters.OAuthTokeninfoAnyKVName, authBaseURL: testAuthPath, args: []interface{}{testKey, testValue, "wrongKey", "wrongValue"}, hasAuth: true, @@ -110,7 +110,7 @@ func TestOAuth2Tokeninfo(t *testing.T) { expected: http.StatusOK, }, { msg: "anyKV(): valid token, one valid kv, multiple key value pairs2", - authType: OAuthTokeninfoAnyKVName, + authType: filters.OAuthTokeninfoAnyKVName, authBaseURL: testAuthPath, args: []interface{}{"wrongKey", "wrongValue", testKey, testValue}, hasAuth: true, @@ -118,7 +118,7 @@ func TestOAuth2Tokeninfo(t *testing.T) { expected: http.StatusOK, }, { msg: "anyKV(): valid token, one valid kv, same key multiple times should pass", - authType: OAuthTokeninfoAnyKVName, + authType: filters.OAuthTokeninfoAnyKVName, authBaseURL: testAuthPath, args: []interface{}{testKey, testValue, testKey, "someValue"}, hasAuth: true, @@ -126,7 +126,7 @@ func TestOAuth2Tokeninfo(t *testing.T) { expected: http.StatusOK, }, { msg: "allKV(): invalid key", - authType: OAuthTokeninfoAllKVName, + authType: filters.OAuthTokeninfoAllKVName, authBaseURL: testAuthPath, args: []interface{}{"not-matching-scope"}, hasAuth: true, @@ -134,7 +134,7 @@ func TestOAuth2Tokeninfo(t *testing.T) { expected: http.StatusNotFound, }, { msg: "allKV(): valid token, one valid key, wrong value", - authType: OAuthTokeninfoAllKVName, + authType: filters.OAuthTokeninfoAllKVName, authBaseURL: testAuthPath, args: []interface{}{testKey, "other-value"}, hasAuth: true, @@ -142,7 +142,7 @@ func TestOAuth2Tokeninfo(t *testing.T) { expected: http.StatusForbidden, }, { msg: "allKV(): valid token, one valid key value pair", - authType: OAuthTokeninfoAllKVName, + authType: filters.OAuthTokeninfoAllKVName, authBaseURL: testAuthPath, args: []interface{}{testKey, testValue}, hasAuth: true, @@ -150,7 +150,7 @@ func TestOAuth2Tokeninfo(t *testing.T) { expected: http.StatusOK, }, { msg: "allKV(): valid token, one valid key value pair, check realm", - authType: OAuthTokeninfoAllKVName, + authType: filters.OAuthTokeninfoAllKVName, authBaseURL: testAuthPath, args: []interface{}{testRealmKey, testRealm, testKey, testValue}, hasAuth: true, @@ -158,7 +158,7 @@ func TestOAuth2Tokeninfo(t *testing.T) { expected: http.StatusOK, }, { msg: "allKV(): valid token, valid key value pairs", - authType: OAuthTokeninfoAllKVName, + authType: filters.OAuthTokeninfoAllKVName, authBaseURL: testAuthPath, args: []interface{}{testKey, testValue, testKey, testValue}, hasAuth: true, @@ -166,7 +166,7 @@ func TestOAuth2Tokeninfo(t *testing.T) { expected: http.StatusOK, }, { msg: "allKV(): valid token, one valid kv, multiple key value pairs1", - authType: OAuthTokeninfoAllKVName, + authType: filters.OAuthTokeninfoAllKVName, authBaseURL: testAuthPath, args: []interface{}{testKey, testValue, "wrongKey", "wrongValue"}, hasAuth: true, @@ -174,7 +174,7 @@ func TestOAuth2Tokeninfo(t *testing.T) { expected: http.StatusForbidden, }, { msg: "allKV(): valid token, one valid kv, multiple key value pairs2", - authType: OAuthTokeninfoAllKVName, + authType: filters.OAuthTokeninfoAllKVName, authBaseURL: testAuthPath, args: []interface{}{"wrongKey", "wrongValue", testKey, testValue}, hasAuth: true, @@ -212,13 +212,13 @@ func TestOAuth2Tokeninfo(t *testing.T) { args := []interface{}{} u := authServer.URL + ti.authBaseURL switch ti.authType { - case OAuthTokeninfoAnyScopeName: + case filters.OAuthTokeninfoAnyScopeName: spec = NewOAuthTokeninfoAnyScope(u, testAuthTimeout) - case OAuthTokeninfoAllScopeName: + case filters.OAuthTokeninfoAllScopeName: spec = NewOAuthTokeninfoAllScope(u, testAuthTimeout) - case OAuthTokeninfoAnyKVName: + case filters.OAuthTokeninfoAnyKVName: spec = NewOAuthTokeninfoAnyKV(u, testAuthTimeout) - case OAuthTokeninfoAllKVName: + case filters.OAuthTokeninfoAllKVName: spec = NewOAuthTokeninfoAllKV(u, testAuthTimeout) } @@ -276,12 +276,12 @@ func TestOAuth2TokenTimeout(t *testing.T) { }{{ msg: "get token within specified timeout", timeout: 2 * testAuthTimeout, - authType: OAuthTokeninfoAnyScopeName, + authType: filters.OAuthTokeninfoAnyScopeName, expected: http.StatusOK, }, { msg: "get token request timeout", timeout: 50 * time.Millisecond, - authType: OAuthTokeninfoAnyScopeName, + authType: filters.OAuthTokeninfoAnyScopeName, expected: http.StatusUnauthorized, }} { t.Run(ti.msg, func(t *testing.T) { diff --git a/filters/auth/tokenintrospection.go b/filters/auth/tokenintrospection.go index d112bb27b9..3cf77addf7 100644 --- a/filters/auth/tokenintrospection.go +++ b/filters/auth/tokenintrospection.go @@ -15,14 +15,22 @@ import ( ) const ( - OAuthTokenintrospectionAnyClaimsName = "oauthTokenintrospectionAnyClaims" - OAuthTokenintrospectionAllClaimsName = "oauthTokenintrospectionAllClaims" - OAuthTokenintrospectionAnyKVName = "oauthTokenintrospectionAnyKV" - OAuthTokenintrospectionAllKVName = "oauthTokenintrospectionAllKV" - SecureOAuthTokenintrospectionAnyClaimsName = "secureOauthTokenintrospectionAnyClaims" - SecureOAuthTokenintrospectionAllClaimsName = "secureOauthTokenintrospectionAllClaims" - SecureOAuthTokenintrospectionAnyKVName = "secureOauthTokenintrospectionAnyKV" - SecureOAuthTokenintrospectionAllKVName = "secureOauthTokenintrospectionAllKV" + // Deprecated, use filters.OAuthTokenintrospectionAnyClaimsName instead + OAuthTokenintrospectionAnyClaimsName = filters.OAuthTokenintrospectionAnyClaimsName + // Deprecated, use filters.OAuthTokenintrospectionAllClaimsName instead + OAuthTokenintrospectionAllClaimsName = filters.OAuthTokenintrospectionAllClaimsName + // Deprecated, use filters.OAuthTokenintrospectionAnyKVName instead + OAuthTokenintrospectionAnyKVName = filters.OAuthTokenintrospectionAnyKVName + // Deprecated, use filters.OAuthTokenintrospectionAllKVName instead + OAuthTokenintrospectionAllKVName = filters.OAuthTokenintrospectionAllKVName + // Deprecated, use filters.SecureOAuthTokenintrospectionAnyClaimsName instead + SecureOAuthTokenintrospectionAnyClaimsName = filters.SecureOAuthTokenintrospectionAnyClaimsName + // Deprecated, use filters.SecureOAuthTokenintrospectionAllClaimsName instead + SecureOAuthTokenintrospectionAllClaimsName = filters.SecureOAuthTokenintrospectionAllClaimsName + // Deprecated, use filters.SecureOAuthTokenintrospectionAnyKVName instead + SecureOAuthTokenintrospectionAnyKVName = filters.SecureOAuthTokenintrospectionAnyKVName + // Deprecated, use filters.SecureOAuthTokenintrospectionAllKVName instead + SecureOAuthTokenintrospectionAllKVName = filters.SecureOAuthTokenintrospectionAllKVName tokenintrospectionCacheKey = "tokenintrospection" TokenIntrospectionConfigPath = "/.well-known/openid-configuration" @@ -227,21 +235,21 @@ func getOpenIDConfig(issuerURL string) (*openIDConfig, error) { func (s *tokenIntrospectionSpec) Name() string { switch s.typ { case checkOAuthTokenintrospectionAnyClaims: - return OAuthTokenintrospectionAnyClaimsName + return filters.OAuthTokenintrospectionAnyClaimsName case checkOAuthTokenintrospectionAllClaims: - return OAuthTokenintrospectionAllClaimsName + return filters.OAuthTokenintrospectionAllClaimsName case checkOAuthTokenintrospectionAnyKV: - return OAuthTokenintrospectionAnyKVName + return filters.OAuthTokenintrospectionAnyKVName case checkOAuthTokenintrospectionAllKV: - return OAuthTokenintrospectionAllKVName + return filters.OAuthTokenintrospectionAllKVName case checkSecureOAuthTokenintrospectionAnyClaims: - return SecureOAuthTokenintrospectionAnyClaimsName + return filters.SecureOAuthTokenintrospectionAnyClaimsName case checkSecureOAuthTokenintrospectionAllClaims: - return SecureOAuthTokenintrospectionAllClaimsName + return filters.SecureOAuthTokenintrospectionAllClaimsName case checkSecureOAuthTokenintrospectionAnyKV: - return SecureOAuthTokenintrospectionAnyKVName + return filters.SecureOAuthTokenintrospectionAnyKVName case checkSecureOAuthTokenintrospectionAllKV: - return SecureOAuthTokenintrospectionAllKVName + return filters.SecureOAuthTokenintrospectionAllKVName } return AuthUnknown } @@ -339,21 +347,21 @@ func (s *tokenIntrospectionSpec) CreateFilter(args []interface{}) (filters.Filte func (f *tokenintrospectFilter) String() string { switch f.typ { case checkOAuthTokenintrospectionAnyClaims: - return fmt.Sprintf("%s(%s)", OAuthTokenintrospectionAnyClaimsName, strings.Join(f.claims, ",")) + return fmt.Sprintf("%s(%s)", filters.OAuthTokenintrospectionAnyClaimsName, strings.Join(f.claims, ",")) case checkOAuthTokenintrospectionAllClaims: - return fmt.Sprintf("%s(%s)", OAuthTokenintrospectionAllClaimsName, strings.Join(f.claims, ",")) + return fmt.Sprintf("%s(%s)", filters.OAuthTokenintrospectionAllClaimsName, strings.Join(f.claims, ",")) case checkOAuthTokenintrospectionAnyKV: - return fmt.Sprintf("%s(%s)", OAuthTokenintrospectionAnyKVName, f.kv) + return fmt.Sprintf("%s(%s)", filters.OAuthTokenintrospectionAnyKVName, f.kv) case checkOAuthTokenintrospectionAllKV: - return fmt.Sprintf("%s(%s)", OAuthTokenintrospectionAllKVName, f.kv) + return fmt.Sprintf("%s(%s)", filters.OAuthTokenintrospectionAllKVName, f.kv) case checkSecureOAuthTokenintrospectionAnyClaims: - return fmt.Sprintf("%s(%s)", SecureOAuthTokenintrospectionAnyClaimsName, strings.Join(f.claims, ",")) + return fmt.Sprintf("%s(%s)", filters.SecureOAuthTokenintrospectionAnyClaimsName, strings.Join(f.claims, ",")) case checkSecureOAuthTokenintrospectionAllClaims: - return fmt.Sprintf("%s(%s)", SecureOAuthTokenintrospectionAllClaimsName, strings.Join(f.claims, ",")) + return fmt.Sprintf("%s(%s)", filters.SecureOAuthTokenintrospectionAllClaimsName, strings.Join(f.claims, ",")) case checkSecureOAuthTokenintrospectionAnyKV: - return fmt.Sprintf("%s(%s)", SecureOAuthTokenintrospectionAnyKVName, f.kv) + return fmt.Sprintf("%s(%s)", filters.SecureOAuthTokenintrospectionAnyKVName, f.kv) case checkSecureOAuthTokenintrospectionAllKV: - return fmt.Sprintf("%s(%s)", SecureOAuthTokenintrospectionAllKVName, f.kv) + return fmt.Sprintf("%s(%s)", filters.SecureOAuthTokenintrospectionAllKVName, f.kv) } return AuthUnknown } diff --git a/filters/auth/tokenintrospection_test.go b/filters/auth/tokenintrospection_test.go index c068781037..154d97c322 100644 --- a/filters/auth/tokenintrospection_test.go +++ b/filters/auth/tokenintrospection_test.go @@ -125,11 +125,11 @@ func TestOAuth2Tokenintrospection(t *testing.T) { }{{ msg: "oauthTokenintrospectionAnyClaims: uninitialized filter, no authorization header, scope check", - authType: OAuthTokenintrospectionAnyClaimsName, + authType: filters.OAuthTokenintrospectionAnyClaimsName, expected: invalidFilterExpected, }, { msg: "oauthTokenintrospectionAnyClaims: invalid token", - authType: OAuthTokenintrospectionAnyClaimsName, + authType: filters.OAuthTokenintrospectionAnyClaimsName, authBaseURL: testAuthPath, args: []interface{}{validClaim1}, hasAuth: true, @@ -137,7 +137,7 @@ func TestOAuth2Tokenintrospection(t *testing.T) { expected: http.StatusUnauthorized, }, { msg: "oauthTokenintrospectionAnyClaims: unsupported claim", - authType: OAuthTokenintrospectionAnyClaimsName, + authType: filters.OAuthTokenintrospectionAnyClaimsName, authBaseURL: testAuthPath, args: []interface{}{"unsupported-claim"}, hasAuth: true, @@ -145,7 +145,7 @@ func TestOAuth2Tokenintrospection(t *testing.T) { expected: invalidFilterExpected, }, { msg: "oauthTokenintrospectionAnyClaims: valid claim", - authType: OAuthTokenintrospectionAnyClaimsName, + authType: filters.OAuthTokenintrospectionAnyClaimsName, authBaseURL: testAuthPath, args: []interface{}{validClaim1}, hasAuth: true, @@ -153,7 +153,7 @@ func TestOAuth2Tokenintrospection(t *testing.T) { expected: http.StatusOK, }, { msg: "oauthTokenintrospectionAnyClaims: invalid claim", - authType: OAuthTokenintrospectionAnyClaimsName, + authType: filters.OAuthTokenintrospectionAnyClaimsName, authBaseURL: testAuthPath, args: []interface{}{invalidSupportedClaim}, hasAuth: true, @@ -161,7 +161,7 @@ func TestOAuth2Tokenintrospection(t *testing.T) { expected: http.StatusUnauthorized, }, { msg: "oauthTokenintrospectionAnyClaims: valid token, one valid claim", - authType: OAuthTokenintrospectionAnyClaimsName, + authType: filters.OAuthTokenintrospectionAnyClaimsName, authBaseURL: testAuthPath, args: []interface{}{validClaim1, validClaim2}, hasAuth: true, @@ -169,7 +169,7 @@ func TestOAuth2Tokenintrospection(t *testing.T) { expected: http.StatusOK, }, { msg: "oauthTokenintrospectionAnyClaims: valid token, one valid claim, one invalid supported claim", - authType: OAuthTokenintrospectionAnyClaimsName, + authType: filters.OAuthTokenintrospectionAnyClaimsName, authBaseURL: testAuthPath, args: []interface{}{validClaim1, invalidSupportedClaim}, hasAuth: true, @@ -178,7 +178,7 @@ func TestOAuth2Tokenintrospection(t *testing.T) { }, { msg: "oauthTokenintrospectionAllClaim: invalid token", - authType: OAuthTokenintrospectionAllClaimsName, + authType: filters.OAuthTokenintrospectionAllClaimsName, authBaseURL: testAuthPath, args: []interface{}{validClaim1}, hasAuth: true, @@ -186,7 +186,7 @@ func TestOAuth2Tokenintrospection(t *testing.T) { expected: http.StatusUnauthorized, }, { msg: "oauthTokenintrospectionAllClaim: unsupported claim", - authType: OAuthTokenintrospectionAllClaimsName, + authType: filters.OAuthTokenintrospectionAllClaimsName, authBaseURL: testAuthPath, args: []interface{}{"unsupported-claim"}, hasAuth: true, @@ -194,7 +194,7 @@ func TestOAuth2Tokenintrospection(t *testing.T) { expected: invalidFilterExpected, }, { msg: "oauthTokenintrospectionAllClaim: valid claim", - authType: OAuthTokenintrospectionAllClaimsName, + authType: filters.OAuthTokenintrospectionAllClaimsName, authBaseURL: testAuthPath, args: []interface{}{validClaim1}, hasAuth: true, @@ -202,7 +202,7 @@ func TestOAuth2Tokenintrospection(t *testing.T) { expected: http.StatusOK, }, { msg: "oauthTokenintrospectionAllClaim: invalid claim", - authType: OAuthTokenintrospectionAllClaimsName, + authType: filters.OAuthTokenintrospectionAllClaimsName, authBaseURL: testAuthPath, args: []interface{}{invalidSupportedClaim}, hasAuth: true, @@ -210,7 +210,7 @@ func TestOAuth2Tokenintrospection(t *testing.T) { expected: http.StatusUnauthorized, }, { msg: "oauthTokenintrospectionAllClaim: valid token, one valid claim", - authType: OAuthTokenintrospectionAllClaimsName, + authType: filters.OAuthTokenintrospectionAllClaimsName, authBaseURL: testAuthPath, args: []interface{}{validClaim1, validClaim2}, hasAuth: true, @@ -218,7 +218,7 @@ func TestOAuth2Tokenintrospection(t *testing.T) { expected: http.StatusOK, }, { msg: "OAuthTokenintrospectionAllClaimsName: valid token, one valid claim, one invalid supported claim", - authType: OAuthTokenintrospectionAllClaimsName, + authType: filters.OAuthTokenintrospectionAllClaimsName, authBaseURL: testAuthPath, args: []interface{}{validClaim1, invalidSupportedClaim}, hasAuth: true, @@ -227,7 +227,7 @@ func TestOAuth2Tokenintrospection(t *testing.T) { }, { msg: "anyKV(): invalid KV", - authType: OAuthTokenintrospectionAnyKVName, + authType: filters.OAuthTokenintrospectionAnyKVName, authBaseURL: testAuthPath, args: []interface{}{validClaim1}, hasAuth: true, @@ -235,7 +235,7 @@ func TestOAuth2Tokenintrospection(t *testing.T) { expected: invalidFilterExpected, }, { msg: "anyKV(): valid token, one valid key, wrong value", - authType: OAuthTokenintrospectionAnyKVName, + authType: filters.OAuthTokenintrospectionAnyKVName, authBaseURL: testAuthPath, args: []interface{}{testKey, "other-value"}, hasAuth: true, @@ -243,7 +243,7 @@ func TestOAuth2Tokenintrospection(t *testing.T) { expected: http.StatusUnauthorized, }, { msg: "anyKV(): valid token, one valid key value pair", - authType: OAuthTokenintrospectionAnyKVName, + authType: filters.OAuthTokenintrospectionAnyKVName, authBaseURL: testAuthPath, args: []interface{}{testKey, testValue}, hasAuth: true, @@ -251,7 +251,7 @@ func TestOAuth2Tokenintrospection(t *testing.T) { expected: http.StatusOK, }, { msg: "anyKV(): valid token, one valid kv, multiple key value pairs1", - authType: OAuthTokenintrospectionAnyKVName, + authType: filters.OAuthTokenintrospectionAnyKVName, authBaseURL: testAuthPath, args: []interface{}{testKey, testValue, "wrongKey", "wrongValue"}, hasAuth: true, @@ -259,7 +259,7 @@ func TestOAuth2Tokenintrospection(t *testing.T) { expected: http.StatusOK, }, { msg: "anyKV(): valid token, one valid kv, multiple key value pairs2", - authType: OAuthTokenintrospectionAnyKVName, + authType: filters.OAuthTokenintrospectionAnyKVName, authBaseURL: testAuthPath, args: []interface{}{"wrongKey", "wrongValue", testKey, testValue}, hasAuth: true, @@ -267,7 +267,7 @@ func TestOAuth2Tokenintrospection(t *testing.T) { expected: http.StatusOK, }, { msg: "anyKV(): valid token, one valid kv, same key multiple times should pass", - authType: OAuthTokenintrospectionAnyKVName, + authType: filters.OAuthTokenintrospectionAnyKVName, authBaseURL: testAuthPath, args: []interface{}{testKey, testValue, testKey, "someValue"}, hasAuth: true, @@ -275,7 +275,7 @@ func TestOAuth2Tokenintrospection(t *testing.T) { expected: http.StatusOK, }, { msg: "allKV(): invalid KV", - authType: OAuthTokenintrospectionAllKVName, + authType: filters.OAuthTokenintrospectionAllKVName, authBaseURL: testAuthPath, args: []interface{}{testKey}, hasAuth: true, @@ -283,7 +283,7 @@ func TestOAuth2Tokenintrospection(t *testing.T) { expected: invalidFilterExpected, }, { msg: "allKV(): valid token, one valid key, wrong value", - authType: OAuthTokenintrospectionAllKVName, + authType: filters.OAuthTokenintrospectionAllKVName, authBaseURL: testAuthPath, args: []interface{}{testKey, "other-value"}, hasAuth: true, @@ -291,7 +291,7 @@ func TestOAuth2Tokenintrospection(t *testing.T) { expected: http.StatusUnauthorized, }, { msg: "allKV(): valid token, one valid key value pair", - authType: OAuthTokenintrospectionAllKVName, + authType: filters.OAuthTokenintrospectionAllKVName, authBaseURL: testAuthPath, args: []interface{}{testKey, testValue}, hasAuth: true, @@ -299,7 +299,7 @@ func TestOAuth2Tokenintrospection(t *testing.T) { expected: http.StatusOK, }, { msg: "allKV(): valid token, one valid key value pair, check realm", - authType: OAuthTokenintrospectionAllKVName, + authType: filters.OAuthTokenintrospectionAllKVName, authBaseURL: testAuthPath, args: []interface{}{testRealmKey, testRealm, testKey, testValue}, hasAuth: true, @@ -307,7 +307,7 @@ func TestOAuth2Tokenintrospection(t *testing.T) { expected: http.StatusOK, }, { msg: "allKV(): valid token, valid key value pairs", - authType: OAuthTokenintrospectionAllKVName, + authType: filters.OAuthTokenintrospectionAllKVName, authBaseURL: testAuthPath, args: []interface{}{testKey, testValue, testKey, testValue}, hasAuth: true, @@ -315,7 +315,7 @@ func TestOAuth2Tokenintrospection(t *testing.T) { expected: http.StatusOK, }, { msg: "allKV(): valid token, one valid kv, multiple key value pairs1", - authType: OAuthTokenintrospectionAllKVName, + authType: filters.OAuthTokenintrospectionAllKVName, authBaseURL: testAuthPath, args: []interface{}{testKey, testValue, "wrongKey", "wrongValue"}, hasAuth: true, @@ -323,7 +323,7 @@ func TestOAuth2Tokenintrospection(t *testing.T) { expected: http.StatusUnauthorized, }, { msg: "allKV(): valid token, one valid kv, multiple key value pairs2", - authType: OAuthTokenintrospectionAllKVName, + authType: filters.OAuthTokenintrospectionAllKVName, authBaseURL: testAuthPath, args: []interface{}{"wrongKey", "wrongValue", testKey, testValue}, hasAuth: true, @@ -331,11 +331,11 @@ func TestOAuth2Tokenintrospection(t *testing.T) { expected: http.StatusUnauthorized, }, { msg: "secureOauthTokenintrospectionAnyClaims: uninitialized filter, no authorization header, scope check", - authType: SecureOAuthTokenintrospectionAnyClaimsName, + authType: filters.SecureOAuthTokenintrospectionAnyClaimsName, expected: invalidFilterExpected, }, { msg: "secureOauthTokenintrospectionAnyClaims: invalid token", - authType: SecureOAuthTokenintrospectionAnyClaimsName, + authType: filters.SecureOAuthTokenintrospectionAnyClaimsName, authBaseURL: testAuthPath, args: []interface{}{"client-id", "client-secret", validClaim1}, hasAuth: true, @@ -343,7 +343,7 @@ func TestOAuth2Tokenintrospection(t *testing.T) { expected: http.StatusUnauthorized, }, { msg: "secureOauthTokenintrospectionAnyClaims: unsupported claim", - authType: SecureOAuthTokenintrospectionAnyClaimsName, + authType: filters.SecureOAuthTokenintrospectionAnyClaimsName, authBaseURL: testAuthPath, args: []interface{}{"client-id", "client-secret", "unsupported-claim"}, hasAuth: true, @@ -351,7 +351,7 @@ func TestOAuth2Tokenintrospection(t *testing.T) { expected: invalidFilterExpected, }, { msg: "secureOauthTokenintrospectionAnyClaims: valid claim", - authType: SecureOAuthTokenintrospectionAnyClaimsName, + authType: filters.SecureOAuthTokenintrospectionAnyClaimsName, authBaseURL: testAuthPath, args: []interface{}{"client-id", "client-secret", validClaim1}, hasAuth: true, @@ -359,7 +359,7 @@ func TestOAuth2Tokenintrospection(t *testing.T) { expected: http.StatusOK, }, { msg: "secureOauthTokenintrospectionAnyClaims: invalid claim", - authType: SecureOAuthTokenintrospectionAnyClaimsName, + authType: filters.SecureOAuthTokenintrospectionAnyClaimsName, authBaseURL: testAuthPath, args: []interface{}{"client-id", "client-secret", invalidSupportedClaim}, hasAuth: true, @@ -367,7 +367,7 @@ func TestOAuth2Tokenintrospection(t *testing.T) { expected: http.StatusUnauthorized, }, { msg: "secureOauthTokenintrospectionAnyClaims: valid token, one valid claim", - authType: SecureOAuthTokenintrospectionAnyClaimsName, + authType: filters.SecureOAuthTokenintrospectionAnyClaimsName, authBaseURL: testAuthPath, args: []interface{}{"client-id", "client-secret", validClaim1, validClaim2}, hasAuth: true, @@ -375,7 +375,7 @@ func TestOAuth2Tokenintrospection(t *testing.T) { expected: http.StatusOK, }, { msg: "secureOauthTokenintrospectionAnyClaims: valid token, one valid claim, one invalid supported claim", - authType: SecureOAuthTokenintrospectionAnyClaimsName, + authType: filters.SecureOAuthTokenintrospectionAnyClaimsName, authBaseURL: testAuthPath, args: []interface{}{"client-id", "client-secret", validClaim1, invalidSupportedClaim}, hasAuth: true, @@ -383,7 +383,7 @@ func TestOAuth2Tokenintrospection(t *testing.T) { expected: http.StatusOK, }, { msg: "secureOauthTokenintrospectionAllClaim: invalid token", - authType: SecureOAuthTokenintrospectionAllClaimsName, + authType: filters.SecureOAuthTokenintrospectionAllClaimsName, authBaseURL: testAuthPath, args: []interface{}{"client-id", "client-secret", validClaim1}, hasAuth: true, @@ -391,7 +391,7 @@ func TestOAuth2Tokenintrospection(t *testing.T) { expected: http.StatusUnauthorized, }, { msg: "secureOauthTokenintrospectionAllClaim: unsupported claim", - authType: SecureOAuthTokenintrospectionAllClaimsName, + authType: filters.SecureOAuthTokenintrospectionAllClaimsName, authBaseURL: testAuthPath, args: []interface{}{"client-id", "client-secret", "unsupported-claim"}, hasAuth: true, @@ -399,7 +399,7 @@ func TestOAuth2Tokenintrospection(t *testing.T) { expected: invalidFilterExpected, }, { msg: "secureOauthTokenintrospectionAllClaim: valid claim", - authType: SecureOAuthTokenintrospectionAllClaimsName, + authType: filters.SecureOAuthTokenintrospectionAllClaimsName, authBaseURL: testAuthPath, args: []interface{}{"client-id", "client-secret", validClaim1}, hasAuth: true, @@ -407,7 +407,7 @@ func TestOAuth2Tokenintrospection(t *testing.T) { expected: http.StatusOK, }, { msg: "secureOauthTokenintrospectionAllClaim: invalid claim", - authType: SecureOAuthTokenintrospectionAllClaimsName, + authType: filters.SecureOAuthTokenintrospectionAllClaimsName, authBaseURL: testAuthPath, args: []interface{}{"client-id", "client-secret", invalidSupportedClaim}, hasAuth: true, @@ -415,7 +415,7 @@ func TestOAuth2Tokenintrospection(t *testing.T) { expected: http.StatusUnauthorized, }, { msg: "secureOauthTokenintrospectionAllClaim: valid token, one valid claim", - authType: SecureOAuthTokenintrospectionAllClaimsName, + authType: filters.SecureOAuthTokenintrospectionAllClaimsName, authBaseURL: testAuthPath, args: []interface{}{"client-id", "client-secret", validClaim1, validClaim2}, hasAuth: true, @@ -423,7 +423,7 @@ func TestOAuth2Tokenintrospection(t *testing.T) { expected: http.StatusOK, }, { msg: "SecureOAuthTokenintrospectionAllClaimsName: valid token, one valid claim, one invalid supported claim", - authType: SecureOAuthTokenintrospectionAllClaimsName, + authType: filters.SecureOAuthTokenintrospectionAllClaimsName, authBaseURL: testAuthPath, args: []interface{}{"client-id", "client-secret", validClaim1, invalidSupportedClaim}, hasAuth: true, @@ -432,7 +432,7 @@ func TestOAuth2Tokenintrospection(t *testing.T) { }, { msg: "secureAnyKV(): invalid KV", - authType: SecureOAuthTokenintrospectionAnyKVName, + authType: filters.SecureOAuthTokenintrospectionAnyKVName, authBaseURL: testAuthPath, args: []interface{}{"client-id", "client-secret", validClaim1}, hasAuth: true, @@ -440,7 +440,7 @@ func TestOAuth2Tokenintrospection(t *testing.T) { expected: invalidFilterExpected, }, { msg: "secureAnyKV(): valid token, one valid key, wrong value", - authType: SecureOAuthTokenintrospectionAnyKVName, + authType: filters.SecureOAuthTokenintrospectionAnyKVName, authBaseURL: testAuthPath, args: []interface{}{"client-id", "client-secret", testKey, "other-value"}, hasAuth: true, @@ -448,7 +448,7 @@ func TestOAuth2Tokenintrospection(t *testing.T) { expected: http.StatusUnauthorized, }, { msg: "secureAnyKV(): valid token, one valid key value pair", - authType: SecureOAuthTokenintrospectionAnyKVName, + authType: filters.SecureOAuthTokenintrospectionAnyKVName, authBaseURL: testAuthPath, args: []interface{}{"client-id", "client-secret", testKey, testValue}, hasAuth: true, @@ -456,7 +456,7 @@ func TestOAuth2Tokenintrospection(t *testing.T) { expected: http.StatusOK, }, { msg: "secureAnyKV(): valid token, one valid kv, multiple key value pairs1", - authType: SecureOAuthTokenintrospectionAnyKVName, + authType: filters.SecureOAuthTokenintrospectionAnyKVName, authBaseURL: testAuthPath, args: []interface{}{"client-id", "client-secret", testKey, testValue, "wrongKey", "wrongValue"}, hasAuth: true, @@ -464,7 +464,7 @@ func TestOAuth2Tokenintrospection(t *testing.T) { expected: http.StatusOK, }, { msg: "secureAnyKV(): valid token, one valid kv, multiple key value pairs2", - authType: SecureOAuthTokenintrospectionAnyKVName, + authType: filters.SecureOAuthTokenintrospectionAnyKVName, authBaseURL: testAuthPath, args: []interface{}{"client-id", "client-secret", "wrongKey", "wrongValue", testKey, testValue}, hasAuth: true, @@ -472,7 +472,7 @@ func TestOAuth2Tokenintrospection(t *testing.T) { expected: http.StatusOK, }, { msg: "secureAllKV(): invalid KV", - authType: SecureOAuthTokenintrospectionAllKVName, + authType: filters.SecureOAuthTokenintrospectionAllKVName, authBaseURL: testAuthPath, args: []interface{}{"client-id", "client-secret", testKey}, hasAuth: true, @@ -480,7 +480,7 @@ func TestOAuth2Tokenintrospection(t *testing.T) { expected: invalidFilterExpected, }, { msg: "secureAllKV(): valid token, one valid key, wrong value", - authType: SecureOAuthTokenintrospectionAllKVName, + authType: filters.SecureOAuthTokenintrospectionAllKVName, authBaseURL: testAuthPath, args: []interface{}{"client-id", "client-secret", testKey, "other-value"}, hasAuth: true, @@ -488,7 +488,7 @@ func TestOAuth2Tokenintrospection(t *testing.T) { expected: http.StatusUnauthorized, }, { msg: "secureAllKV(): valid token, one valid key value pair", - authType: SecureOAuthTokenintrospectionAllKVName, + authType: filters.SecureOAuthTokenintrospectionAllKVName, authBaseURL: testAuthPath, args: []interface{}{"client-id", "client-secret", testKey, testValue}, hasAuth: true, @@ -496,7 +496,7 @@ func TestOAuth2Tokenintrospection(t *testing.T) { expected: http.StatusOK, }, { msg: "secureAllKV(): valid token, one valid key value pair, check realm", - authType: SecureOAuthTokenintrospectionAllKVName, + authType: filters.SecureOAuthTokenintrospectionAllKVName, authBaseURL: testAuthPath, args: []interface{}{"client-id", "client-secret", testRealmKey, testRealm, testKey, testValue}, hasAuth: true, @@ -504,7 +504,7 @@ func TestOAuth2Tokenintrospection(t *testing.T) { expected: http.StatusOK, }, { msg: "secureAllKV(): valid token, valid key value pairs", - authType: SecureOAuthTokenintrospectionAllKVName, + authType: filters.SecureOAuthTokenintrospectionAllKVName, authBaseURL: testAuthPath, args: []interface{}{"client-id", "client-secret", testKey, testValue, testKey, testValue}, hasAuth: true, @@ -512,7 +512,7 @@ func TestOAuth2Tokenintrospection(t *testing.T) { expected: http.StatusOK, }, { msg: "secureAllKV(): valid token, one valid kv, multiple key value pairs1", - authType: SecureOAuthTokenintrospectionAllKVName, + authType: filters.SecureOAuthTokenintrospectionAllKVName, authBaseURL: testAuthPath, args: []interface{}{"client-id", "client-secret", testKey, testValue, "wrongKey", "wrongValue"}, hasAuth: true, @@ -520,7 +520,7 @@ func TestOAuth2Tokenintrospection(t *testing.T) { expected: http.StatusUnauthorized, }, { msg: "secureAllKV(): valid token, one valid kv, multiple key value pairs2", - authType: SecureOAuthTokenintrospectionAllKVName, + authType: filters.SecureOAuthTokenintrospectionAllKVName, authBaseURL: testAuthPath, args: []interface{}{"client-id", "client-secret", "wrongKey", "wrongValue", testKey, testValue}, hasAuth: true, @@ -534,21 +534,21 @@ func TestOAuth2Tokenintrospection(t *testing.T) { var spec filters.Spec switch ti.authType { - case OAuthTokenintrospectionAnyClaimsName: + case filters.OAuthTokenintrospectionAnyClaimsName: spec = NewOAuthTokenintrospectionAnyClaims(time.Second) - case OAuthTokenintrospectionAllClaimsName: + case filters.OAuthTokenintrospectionAllClaimsName: spec = NewOAuthTokenintrospectionAllClaims(time.Second) - case OAuthTokenintrospectionAnyKVName: + case filters.OAuthTokenintrospectionAnyKVName: spec = NewOAuthTokenintrospectionAnyKV(time.Second) - case OAuthTokenintrospectionAllKVName: + case filters.OAuthTokenintrospectionAllKVName: spec = NewOAuthTokenintrospectionAllKV(time.Second) - case SecureOAuthTokenintrospectionAnyClaimsName: + case filters.SecureOAuthTokenintrospectionAnyClaimsName: spec = NewSecureOAuthTokenintrospectionAnyClaims(time.Second) - case SecureOAuthTokenintrospectionAllClaimsName: + case filters.SecureOAuthTokenintrospectionAllClaimsName: spec = NewSecureOAuthTokenintrospectionAllClaims(time.Second) - case SecureOAuthTokenintrospectionAnyKVName: + case filters.SecureOAuthTokenintrospectionAnyKVName: spec = NewSecureOAuthTokenintrospectionAnyKV(time.Second) - case SecureOAuthTokenintrospectionAllKVName: + case filters.SecureOAuthTokenintrospectionAllKVName: spec = NewSecureOAuthTokenintrospectionAllKV(time.Second) default: t.Fatalf("FATAL: authType '%s' not supported", ti.authType) diff --git a/filters/auth/webhook.go b/filters/auth/webhook.go index 81f006c3d4..4282edc42c 100644 --- a/filters/auth/webhook.go +++ b/filters/auth/webhook.go @@ -14,7 +14,8 @@ import ( ) const ( - WebhookName = "webhook" + // Deprecated, use filters.WebhookName instead + WebhookName = filters.WebhookName ) type WebhookOptions struct { @@ -48,7 +49,7 @@ func WebhookWithOptions(o WebhookOptions) filters.Spec { } func (*webhookSpec) Name() string { - return WebhookName + return filters.WebhookName } // CreateFilter creates an auth filter. The first argument is an URL @@ -110,7 +111,7 @@ func (f *webhookFilter) Request(ctx filters.FilterContext) { // errors, redirects, auth errors, webhook errors if err != nil || resp.StatusCode >= 300 { - unauthorized(ctx, "", invalidAccess, f.authClient.url.Hostname(), WebhookName) + unauthorized(ctx, "", invalidAccess, f.authClient.url.Hostname(), filters.WebhookName) return } @@ -121,7 +122,7 @@ func (f *webhookFilter) Request(ctx filters.FilterContext) { } } - authorized(ctx, WebhookName) + authorized(ctx, filters.WebhookName) } func (*webhookFilter) Response(filters.FilterContext) {} diff --git a/filters/builtin/backendisproxy.go b/filters/builtin/backendisproxy.go index 673fefb61d..a208030afa 100644 --- a/filters/builtin/backendisproxy.go +++ b/filters/builtin/backendisproxy.go @@ -12,7 +12,7 @@ func NewBackendIsProxy() filters.Spec { } func (s *backendIsProxySpec) Name() string { - return "backendIsProxy" + return filters.BackendIsProxyName } func (s *backendIsProxySpec) CreateFilter(args []interface{}) (filters.Filter, error) { diff --git a/filters/builtin/builtin.go b/filters/builtin/builtin.go index 97a87edc71..cf512dbda3 100644 --- a/filters/builtin/builtin.go +++ b/filters/builtin/builtin.go @@ -34,45 +34,82 @@ const ( // Deprecated: use redirectTo RedirectName = "redirect" - SetRequestHeaderName = "setRequestHeader" - SetResponseHeaderName = "setResponseHeader" - AppendRequestHeaderName = "appendRequestHeader" - AppendResponseHeaderName = "appendResponseHeader" - DropRequestHeaderName = "dropRequestHeader" - DropResponseHeaderName = "dropResponseHeader" - SetContextRequestHeaderName = "setContextRequestHeader" - AppendContextRequestHeaderName = "appendContextRequestHeader" - SetContextResponseHeaderName = "setContextResponseHeader" - AppendContextResponseHeaderName = "appendContextResponseHeader" - CopyRequestHeaderName = "copyRequestHeader" - CopyResponseHeaderName = "copyResponseHeader" + // Deprecated, use filters.SetRequestHeaderName instead + SetRequestHeaderName = filters.SetRequestHeaderName + // Deprecated, use filters.SetResponseHeaderName instead + SetResponseHeaderName = filters.SetResponseHeaderName + // Deprecated, use filters.AppendRequestHeaderName instead + AppendRequestHeaderName = filters.AppendRequestHeaderName + // Deprecated, use filters.AppendResponseHeaderName instead + AppendResponseHeaderName = filters.AppendResponseHeaderName + // Deprecated, use filters.DropRequestHeaderName instead + DropRequestHeaderName = filters.DropRequestHeaderName + // Deprecated, use filters.DropResponseHeaderName instead + DropResponseHeaderName = filters.DropResponseHeaderName + // Deprecated, use filters.SetContextRequestHeaderName instead + SetContextRequestHeaderName = filters.SetContextRequestHeaderName + // Deprecated, use filters.AppendContextRequestHeaderName instead + AppendContextRequestHeaderName = filters.AppendContextRequestHeaderName + // Deprecated, use filters.SetContextResponseHeaderName instead + SetContextResponseHeaderName = filters.SetContextResponseHeaderName + // Deprecated, use filters.AppendContextResponseHeaderName instead + AppendContextResponseHeaderName = filters.AppendContextResponseHeaderName + // Deprecated, use filters.CopyRequestHeaderName instead + CopyRequestHeaderName = filters.CopyRequestHeaderName + // Deprecated, use filters.CopyResponseHeaderName instead + CopyResponseHeaderName = filters.CopyResponseHeaderName - SetDynamicBackendHostFromHeader = "setDynamicBackendHostFromHeader" - SetDynamicBackendSchemeFromHeader = "setDynamicBackendSchemeFromHeader" - SetDynamicBackendUrlFromHeader = "setDynamicBackendUrlFromHeader" - SetDynamicBackendHost = "setDynamicBackendHost" - SetDynamicBackendScheme = "setDynamicBackendScheme" - SetDynamicBackendUrl = "setDynamicBackendUrl" + // Deprecated, use filters.SetDynamicBackendHostFromHeader instead + SetDynamicBackendHostFromHeader = filters.SetDynamicBackendHostFromHeader + // Deprecated, use filters.SetDynamicBackendSchemeFromHeader instead + SetDynamicBackendSchemeFromHeader = filters.SetDynamicBackendSchemeFromHeader + // Deprecated, use filters.SetDynamicBackendUrlFromHeader instead + SetDynamicBackendUrlFromHeader = filters.SetDynamicBackendUrlFromHeader + // Deprecated, use filters.SetDynamicBackendHost instead + SetDynamicBackendHost = filters.SetDynamicBackendHost + // Deprecated, use filters.SetDynamicBackendScheme instead + SetDynamicBackendScheme = filters.SetDynamicBackendScheme + // Deprecated, use filters.SetDynamicBackendUrl instead + SetDynamicBackendUrl = filters.SetDynamicBackendUrl - HealthCheckName = "healthcheck" - ModPathName = "modPath" - SetPathName = "setPath" - ModRequestHeaderName = "modRequestHeader" - RedirectToName = "redirectTo" - RedirectToLowerName = "redirectToLower" - StaticName = "static" - StripQueryName = "stripQuery" - PreserveHostName = "preserveHost" - SetFastCgiFilenameName = "setFastCgiFilename" - StatusName = "status" - CompressName = "compress" - SetQueryName = "setQuery" - DropQueryName = "dropQuery" - InlineContentName = "inlineContent" - InlineContentIfStatusName = "inlineContentIfStatus" - HeaderToQueryName = "headerToQuery" - QueryToHeaderName = "queryToHeader" - BackendTimeoutName = "backendTimeout" + // Deprecated, use filters.HealthCheckName instead + HealthCheckName = filters.HealthCheckName + // Deprecated, use filters.ModPathName instead + ModPathName = filters.ModPathName + // Deprecated, use filters.SetPathName instead + SetPathName = filters.SetPathName + // Deprecated, use filters.ModRequestHeaderName instead + ModRequestHeaderName = filters.ModRequestHeaderName + // Deprecated, use filters.RedirectToName instead + RedirectToName = filters.RedirectToName + // Deprecated, use filters.RedirectToLowerName instead + RedirectToLowerName = filters.RedirectToLowerName + // Deprecated, use filters.StaticName instead + StaticName = filters.StaticName + // Deprecated, use filters.StripQueryName instead + StripQueryName = filters.StripQueryName + // Deprecated, use filters.PreserveHostName instead + PreserveHostName = filters.PreserveHostName + // Deprecated, use filters.SetFastCgiFilenameName instead + SetFastCgiFilenameName = filters.SetFastCgiFilenameName + // Deprecated, use filters.StatusName instead + StatusName = filters.StatusName + // Deprecated, use filters.CompressName instead + CompressName = filters.CompressName + // Deprecated, use filters.SetQueryName instead + SetQueryName = filters.SetQueryName + // Deprecated, use filters.DropQueryName instead + DropQueryName = filters.DropQueryName + // Deprecated, use filters.InlineContentName instead + InlineContentName = filters.InlineContentName + // Deprecated, use filters.InlineContentIfStatusName instead + InlineContentIfStatusName = filters.InlineContentIfStatusName + // Deprecated, use filters.HeaderToQueryName instead + HeaderToQueryName = filters.HeaderToQueryName + // Deprecated, use filters.QueryToHeaderName instead + QueryToHeaderName = filters.QueryToHeaderName + // Deprecated, use filters.BackendTimeoutName instead + BackendTimeoutName = filters.BackendTimeoutName ) // Returns a Registry object initialized with the default set of filter diff --git a/filters/builtin/compress.go b/filters/builtin/compress.go index 5eeaaa6b87..d81a1d1e0c 100644 --- a/filters/builtin/compress.go +++ b/filters/builtin/compress.go @@ -126,7 +126,7 @@ func (e encodings) Swap(i, j int) { e[i], e[j] = e[j], e[i] } func NewCompress() filters.Spec { return &compress{} } func (c *compress) Name() string { - return CompressName + return filters.CompressName } func (c *compress) CreateFilter(args []interface{}) (filters.Filter, error) { diff --git a/filters/builtin/compress_test.go b/filters/builtin/compress_test.go index 9e95a1ee3b..84a17f7391 100644 --- a/filters/builtin/compress_test.go +++ b/filters/builtin/compress_test.go @@ -432,7 +432,7 @@ func TestCompress(t *testing.T) { defer s.Close() p := proxytest.New(MakeRegistry(), &eskip.Route{ - Filters: []*eskip.Filter{{Name: CompressName, Args: ti.compressArgs}}, + Filters: []*eskip.Filter{{Name: filters.CompressName, Args: ti.compressArgs}}, Backend: s.URL}) defer p.Close() @@ -548,7 +548,7 @@ func TestStreaming(t *testing.T) { defer s.Close() p := proxytest.New(MakeRegistry(), &eskip.Route{ - Filters: []*eskip.Filter{{Name: CompressName}}, + Filters: []*eskip.Filter{{Name: filters.CompressName}}, Backend: s.URL}) defer p.Close() diff --git a/filters/builtin/decompress.go b/filters/builtin/decompress.go index 16b7cd63e8..d8bec547a1 100644 --- a/filters/builtin/decompress.go +++ b/filters/builtin/decompress.go @@ -164,7 +164,7 @@ func NewDecompress() filters.Spec { return decompress{} } -func (d decompress) Name() string { return "decompress" } +func (d decompress) Name() string { return filters.DecompressName } func (d decompress) CreateFilter([]interface{}) (filters.Filter, error) { return d, nil diff --git a/filters/builtin/dynamicbackendfilter.go b/filters/builtin/dynamicbackendfilter.go index 66d4180427..3f3ae5599a 100644 --- a/filters/builtin/dynamicbackendfilter.go +++ b/filters/builtin/dynamicbackendfilter.go @@ -97,17 +97,17 @@ func NewSetDynamicBackendUrl() filters.Spec { func (spec *dynamicBackendFilter) Name() string { switch spec.typ { case setDynamicBackendHostFromHeader: - return SetDynamicBackendHostFromHeader + return filters.SetDynamicBackendHostFromHeader case setDynamicBackendSchemeFromHeader: - return SetDynamicBackendSchemeFromHeader + return filters.SetDynamicBackendSchemeFromHeader case setDynamicBackendUrlFromHeader: - return SetDynamicBackendUrlFromHeader + return filters.SetDynamicBackendUrlFromHeader case setDynamicBackendHost: - return SetDynamicBackendHost + return filters.SetDynamicBackendHost case setDynamicBackendScheme: - return SetDynamicBackendScheme + return filters.SetDynamicBackendScheme case setDynamicBackendUrl: - return SetDynamicBackendUrl + return filters.SetDynamicBackendUrl default: panic("invalid type") } diff --git a/filters/builtin/fastcgi.go b/filters/builtin/fastcgi.go index c1bf56e0e2..a0a68a1893 100644 --- a/filters/builtin/fastcgi.go +++ b/filters/builtin/fastcgi.go @@ -26,7 +26,7 @@ type setFastCgiFilenameSpec struct { // the FastCGI filename. func NewSetFastCgiFilename() filters.Spec { return &setFastCgiFilenameSpec{} } -func (s *setFastCgiFilenameSpec) Name() string { return SetFastCgiFilenameName } +func (s *setFastCgiFilenameSpec) Name() string { return filters.SetFastCgiFilenameName } func (s *setFastCgiFilenameSpec) CreateFilter(args []interface{}) (filters.Filter, error) { if len(args) != 1 { diff --git a/filters/builtin/headerfilter.go b/filters/builtin/headerfilter.go index 632441bd6e..e9b5be770a 100644 --- a/filters/builtin/headerfilter.go +++ b/filters/builtin/headerfilter.go @@ -195,33 +195,33 @@ func NewCopyResponseHeaderDeprecated() filters.Spec { func (spec *headerFilter) Name() string { switch spec.typ { case setRequestHeader: - return SetRequestHeaderName + return filters.SetRequestHeaderName case appendRequestHeader: - return AppendRequestHeaderName + return filters.AppendRequestHeaderName case dropRequestHeader: - return DropRequestHeaderName + return filters.DropRequestHeaderName case setResponseHeader: - return SetResponseHeaderName + return filters.SetResponseHeaderName case appendResponseHeader: - return AppendResponseHeaderName + return filters.AppendResponseHeaderName case dropResponseHeader: - return DropResponseHeaderName + return filters.DropResponseHeaderName case depRequestHeader: return RequestHeaderName case depResponseHeader: return ResponseHeaderName case setContextRequestHeader: - return SetContextRequestHeaderName + return filters.SetContextRequestHeaderName case appendContextRequestHeader: - return AppendContextRequestHeaderName + return filters.AppendContextRequestHeaderName case setContextResponseHeader: - return SetContextResponseHeaderName + return filters.SetContextResponseHeaderName case appendContextResponseHeader: - return AppendContextResponseHeaderName + return filters.AppendContextResponseHeaderName case copyRequestHeader: - return CopyRequestHeaderName + return filters.CopyRequestHeaderName case copyResponseHeader: - return CopyResponseHeaderName + return filters.CopyResponseHeaderName case copyRequestHeaderDeprecated: return copyRequestHeaderDeprecatedName case copyResponseHeaderDeprecated: diff --git a/filters/builtin/headertoquery.go b/filters/builtin/headertoquery.go index a9bba493da..df68fc3208 100644 --- a/filters/builtin/headertoquery.go +++ b/filters/builtin/headertoquery.go @@ -27,7 +27,7 @@ func NewHeaderToQuery() filters.Spec { } func (*headerToQuerySpec) Name() string { - return HeaderToQueryName + return filters.HeaderToQueryName } // CreateFilter creates a `headerToQuery` filter instance with below signature diff --git a/filters/builtin/healthcheck.go b/filters/builtin/healthcheck.go index f9e463d750..03ae433cd4 100644 --- a/filters/builtin/healthcheck.go +++ b/filters/builtin/healthcheck.go @@ -26,7 +26,7 @@ type healthCheck struct{} func NewHealthCheck() filters.Spec { return &healthCheck{} } // "healthcheck" -func (h *healthCheck) Name() string { return HealthCheckName } +func (h *healthCheck) Name() string { return filters.HealthCheckName } func (h *healthCheck) CreateFilter(_ []interface{}) (filters.Filter, error) { return h, nil } func (h *healthCheck) Request(ctx filters.FilterContext) {} diff --git a/filters/builtin/inlinecontent.go b/filters/builtin/inlinecontent.go index cc599ae89b..ae43e32207 100644 --- a/filters/builtin/inlinecontent.go +++ b/filters/builtin/inlinecontent.go @@ -34,7 +34,7 @@ func NewInlineContent() filters.Spec { return &inlineContent{} } -func (c *inlineContent) Name() string { return InlineContentName } +func (c *inlineContent) Name() string { return filters.InlineContentName } func stringArg(a interface{}) (s string, err error) { var ok bool diff --git a/filters/builtin/inlinecontentifstatus.go b/filters/builtin/inlinecontentifstatus.go index 0152c23619..0103c4743e 100644 --- a/filters/builtin/inlinecontentifstatus.go +++ b/filters/builtin/inlinecontentifstatus.go @@ -30,7 +30,7 @@ func NewInlineContentIfStatus() filters.Spec { return &inlineContentIfStatus{} } -func (c *inlineContentIfStatus) Name() string { return InlineContentIfStatusName } +func (c *inlineContentIfStatus) Name() string { return filters.InlineContentIfStatusName } func (c *inlineContentIfStatus) CreateFilter(args []interface{}) (filters.Filter, error) { if len(args) < 2 || len(args) > 3 { diff --git a/filters/builtin/mod_header.go b/filters/builtin/mod_header.go index 08e0f6a982..242530afcf 100644 --- a/filters/builtin/mod_header.go +++ b/filters/builtin/mod_header.go @@ -21,7 +21,7 @@ type modRequestHeader struct { func NewModRequestHeader() filters.Spec { return &modRequestHeader{} } func (spec *modRequestHeader) Name() string { - return ModRequestHeaderName + return filters.ModRequestHeaderName } //lint:ignore ST1016 "spec" makes sense here and we reuse the type for the filter diff --git a/filters/builtin/originmarker.go b/filters/builtin/originmarker.go index a66bdf9966..6cf2d0af1c 100644 --- a/filters/builtin/originmarker.go +++ b/filters/builtin/originmarker.go @@ -8,7 +8,8 @@ import ( ) const ( - OriginMarkerName = "originMarker" + // Deprecated, use filters.OriginMarkerName instead + OriginMarkerName = filters.OriginMarkerName ) type originMarkerSpec struct{} @@ -31,12 +32,12 @@ func NewOriginMarkerSpec() filters.Spec { func NewOriginMarker(origin string, id string, created time.Time) *eskip.Filter { return &eskip.Filter{ - Name: OriginMarkerName, + Name: filters.OriginMarkerName, Args: []interface{}{origin, id, created}, } } -func (s *originMarkerSpec) Name() string { return OriginMarkerName } +func (s *originMarkerSpec) Name() string { return filters.OriginMarkerName } func (s *originMarkerSpec) CreateFilter(args []interface{}) (filters.Filter, error) { if len(args) != 3 { diff --git a/filters/builtin/path.go b/filters/builtin/path.go index b6852ab640..009eae8eef 100644 --- a/filters/builtin/path.go +++ b/filters/builtin/path.go @@ -40,9 +40,9 @@ func NewSetPath() filters.Spec { return &modPath{behavior: fullReplace} } func (spec *modPath) Name() string { switch spec.behavior { case regexpReplace: - return ModPathName + return filters.ModPathName case fullReplace: - return SetPathName + return filters.SetPathName default: panic("unspecified behavior") } diff --git a/filters/builtin/preservehost.go b/filters/builtin/preservehost.go index c5d4569758..f06346ac9a 100644 --- a/filters/builtin/preservehost.go +++ b/filters/builtin/preservehost.go @@ -36,7 +36,7 @@ type filter bool // or in the backend address. func PreserveHost() filters.Spec { return &spec{} } -func (s *spec) Name() string { return PreserveHostName } +func (s *spec) Name() string { return filters.PreserveHostName } func (s *spec) CreateFilter(args []interface{}) (filters.Filter, error) { if len(args) != 1 { diff --git a/filters/builtin/query.go b/filters/builtin/query.go index fa1b51558a..2b741429ee 100644 --- a/filters/builtin/query.go +++ b/filters/builtin/query.go @@ -39,9 +39,9 @@ func NewSetQuery() filters.Spec { return &modQuery{behavior: set} } func (spec *modQuery) Name() string { switch spec.behavior { case drop: - return DropQueryName + return filters.DropQueryName case set: - return SetQueryName + return filters.SetQueryName default: panic("unspecified behavior") } diff --git a/filters/builtin/querytoheader.go b/filters/builtin/querytoheader.go index d28386a76a..288786d861 100644 --- a/filters/builtin/querytoheader.go +++ b/filters/builtin/querytoheader.go @@ -36,7 +36,7 @@ func NewQueryToHeader() filters.Spec { } func (*queryToHeaderSpec) Name() string { - return QueryToHeaderName + return filters.QueryToHeaderName } // CreateFilter creates a `queryToHeader` filter instance with below signature diff --git a/filters/builtin/redirect.go b/filters/builtin/redirect.go index 43c2b4ab89..9b9dcad586 100644 --- a/filters/builtin/redirect.go +++ b/filters/builtin/redirect.go @@ -66,9 +66,9 @@ func (spec *redirect) Name() string { case redDeprecated: return RedirectName case redToLower: - return RedirectToLowerName + return filters.RedirectToLowerName default: - return RedirectToName + return filters.RedirectToName } } diff --git a/filters/builtin/redirect_test.go b/filters/builtin/redirect_test.go index 2b7fd05daa..602aaf1d31 100644 --- a/filters/builtin/redirect_test.go +++ b/filters/builtin/redirect_test.go @@ -8,6 +8,7 @@ import ( "time" "github.com/zalando/skipper/eskip" + "github.com/zalando/skipper/filters" "github.com/zalando/skipper/logging/loggingtest" "github.com/zalando/skipper/proxy" "github.com/zalando/skipper/routing" @@ -120,7 +121,7 @@ func TestRedirect(t *testing.T) { RedirectName, }, { "not deprecated", - RedirectToName, + filters.RedirectToName, }} { var args []interface{} if ti.skipLocationArg { @@ -206,7 +207,7 @@ func TestRedirectLower(t *testing.T) { name string }{{ "lowercase", - RedirectToLowerName, + filters.RedirectToLowerName, }} { dc := testdataclient.New([]*eskip.Route{{ Shunt: true, diff --git a/filters/builtin/static.go b/filters/builtin/static.go index 57d96aaa9e..b0b10e81e0 100644 --- a/filters/builtin/static.go +++ b/filters/builtin/static.go @@ -27,7 +27,7 @@ type static struct { func NewStatic() filters.Spec { return &static{} } // "static" -func (spec *static) Name() string { return StaticName } +func (spec *static) Name() string { return filters.StaticName } // Creates instances of the static filter. Expects two parameters: request path // prefix and file system root. diff --git a/filters/builtin/static_test.go b/filters/builtin/static_test.go index caeecac4c3..884b6df077 100644 --- a/filters/builtin/static_test.go +++ b/filters/builtin/static_test.go @@ -99,7 +99,7 @@ func TestStatic(t *testing.T) { fr := make(filters.Registry) fr.Register(NewStatic()) pr := proxytest.New(fr, &eskip.Route{ - Filters: []*eskip.Filter{{Name: StaticName, Args: ti.args}}, + Filters: []*eskip.Filter{{Name: filters.StaticName, Args: ti.args}}, Shunt: true}) defer pr.Close() @@ -143,7 +143,7 @@ func TestSameFileMultipleTimes(t *testing.T) { fr := make(filters.Registry) fr.Register(NewStatic()) pr := proxytest.New(fr, &eskip.Route{ - Filters: []*eskip.Filter{{Name: StaticName, Args: []interface{}{"/static", "/tmp"}}}, + Filters: []*eskip.Filter{{Name: filters.StaticName, Args: []interface{}{"/static", "/tmp"}}}, Shunt: true}) defer pr.Close() @@ -173,7 +173,7 @@ func TestMultipleRanges(t *testing.T) { fr := make(filters.Registry) fr.Register(NewStatic()) pr := proxytest.New(fr, &eskip.Route{ - Filters: []*eskip.Filter{{Name: StaticName, Args: []interface{}{"/static", "/tmp"}}}, + Filters: []*eskip.Filter{{Name: filters.StaticName, Args: []interface{}{"/static", "/tmp"}}}, Shunt: true}) defer pr.Close() diff --git a/filters/builtin/status.go b/filters/builtin/status.go index c161e1b720..34232d0b63 100644 --- a/filters/builtin/status.go +++ b/filters/builtin/status.go @@ -11,7 +11,7 @@ type statusFilter int // backend response. func NewStatus() filters.Spec { return new(statusSpec) } -func (s *statusSpec) Name() string { return StatusName } +func (s *statusSpec) Name() string { return filters.StatusName } func (s *statusSpec) CreateFilter(args []interface{}) (filters.Filter, error) { if len(args) != 1 { diff --git a/filters/builtin/status_test.go b/filters/builtin/status_test.go index 2a20e08d7b..2330ba06fe 100644 --- a/filters/builtin/status_test.go +++ b/filters/builtin/status_test.go @@ -33,7 +33,7 @@ func TestStatus(t *testing.T) { fr := make(filters.Registry) fr.Register(NewStatus()) pr := proxytest.New(fr, &eskip.Route{ - Filters: []*eskip.Filter{{Name: StatusName, Args: ti.args}}, + Filters: []*eskip.Filter{{Name: filters.StatusName, Args: ti.args}}, Shunt: true}) defer pr.Close() diff --git a/filters/builtin/stripquery.go b/filters/builtin/stripquery.go index 769081370d..5dd533d017 100644 --- a/filters/builtin/stripquery.go +++ b/filters/builtin/stripquery.go @@ -40,7 +40,7 @@ type stripQuery struct { func NewStripQuery() filters.Spec { return &stripQuery{} } // "stripQuery" -func (stripQuery) Name() string { return StripQueryName } +func (stripQuery) Name() string { return filters.StripQueryName } // copied from textproto/reader func validHeaderFieldByte(b byte) bool { diff --git a/filters/builtin/timeout.go b/filters/builtin/timeout.go index c733968f5e..168d535d70 100644 --- a/filters/builtin/timeout.go +++ b/filters/builtin/timeout.go @@ -14,7 +14,7 @@ func NewBackendTimeout() filters.Spec { return &timeout{} } -func (*timeout) Name() string { return BackendTimeoutName } +func (*timeout) Name() string { return filters.BackendTimeoutName } func (*timeout) CreateFilter(args []interface{}) (filters.Filter, error) { if len(args) != 1 { diff --git a/filters/builtin/timeout_test.go b/filters/builtin/timeout_test.go index 23a786f825..adc63f9994 100644 --- a/filters/builtin/timeout_test.go +++ b/filters/builtin/timeout_test.go @@ -11,7 +11,7 @@ import ( func TestBackendTimeout(t *testing.T) { bt := NewBackendTimeout() - if bt.Name() != BackendTimeoutName { + if bt.Name() != filters.BackendTimeoutName { t.Error("wrong name") } diff --git a/filters/circuit/breaker.go b/filters/circuit/breaker.go index 3c54a3d1b5..a167518874 100644 --- a/filters/circuit/breaker.go +++ b/filters/circuit/breaker.go @@ -13,10 +13,14 @@ import ( ) const ( - ConsecutiveBreakerName = "consecutiveBreaker" - RateBreakerName = "rateBreaker" - DisableBreakerName = "disableBreaker" - RouteSettingsKey = "#circuitbreakersettings" + // Deprecated, use filters.ConsecutiveBreakerName instead + ConsecutiveBreakerName = filters.ConsecutiveBreakerName + // Deprecated, use filters.RateBreakerName instead + RateBreakerName = filters.RateBreakerName + // Deprecated, use filters.DisableBreakerName instead + DisableBreakerName = filters.DisableBreakerName + + RouteSettingsKey = "#circuitbreakersettings" ) type spec struct { @@ -82,11 +86,11 @@ func NewDisableBreaker() filters.Spec { func (s *spec) Name() string { switch s.typ { case circuit.ConsecutiveFailures: - return ConsecutiveBreakerName + return filters.ConsecutiveBreakerName case circuit.FailureRate: - return RateBreakerName + return filters.RateBreakerName default: - return DisableBreakerName + return filters.DisableBreakerName } } diff --git a/filters/consistenthash/balancefactor.go b/filters/consistenthash/balancefactor.go index 2ae57fc4e1..6c20b64894 100644 --- a/filters/consistenthash/balancefactor.go +++ b/filters/consistenthash/balancefactor.go @@ -15,7 +15,9 @@ type consistentHashBalanceFactor struct { // set the balancer factor used by the `consistentHash` algorithm to avoid // popular hashes overloading a single endpoint func NewConsistentHashBalanceFactor() filters.Spec { return &consistentHashBalanceFactor{} } -func (*consistentHashBalanceFactor) Name() string { return "consistentHashBalanceFactor" } +func (*consistentHashBalanceFactor) Name() string { + return filters.ConsistentHashBalanceFactorName +} func (*consistentHashBalanceFactor) CreateFilter(args []interface{}) (filters.Filter, error) { if len(args) != 1 { diff --git a/filters/consistenthash/key.go b/filters/consistenthash/key.go index c16a7cceb1..d774a7af48 100644 --- a/filters/consistenthash/key.go +++ b/filters/consistenthash/key.go @@ -13,7 +13,9 @@ type consistentHashKey struct { // NewConsistentHashKey creates a filter Spec, whose instances // set the request key used by the `consistentHash` algorithm to select backend endpoint func NewConsistentHashKey() filters.Spec { return &consistentHashKey{} } -func (*consistentHashKey) Name() string { return "consistentHashKey" } +func (*consistentHashKey) Name() string { + return filters.ConsistentHashKeyName +} func (*consistentHashKey) CreateFilter(args []interface{}) (filters.Filter, error) { if len(args) != 1 { diff --git a/filters/cookie/cookie.go b/filters/cookie/cookie.go index 96b33b4d0b..72c6179111 100644 --- a/filters/cookie/cookie.go +++ b/filters/cookie/cookie.go @@ -44,11 +44,15 @@ import ( ) const ( - RequestCookieFilterName = "requestCookie" - ResponseCookieFilterName = "responseCookie" - ResponseJSCookieFilterName = "jsCookie" - ChangeOnlyArg = "change-only" - SetCookieHttpHeader = "Set-Cookie" + // Deprecated, use filters.RequestCookieName instead + RequestCookieFilterName = filters.RequestCookieName + // Deprecated, use filters.ResponseCookieName instead + ResponseCookieFilterName = filters.ResponseCookieName + // Deprecated, use filters.JsCookieName instead + ResponseJSCookieFilterName = filters.JsCookieName + + ChangeOnlyArg = "change-only" + SetCookieHttpHeader = "Set-Cookie" ) type direction int @@ -75,20 +79,20 @@ type filter struct { // Creates a filter spec for appending cookies to requests. // Name: requestCookie func NewRequestCookie() filters.Spec { - return &spec{request, RequestCookieFilterName} + return &spec{request, filters.RequestCookieName} } // Creates a filter spec for appending cookies to responses. // Name: responseCookie func NewResponseCookie() filters.Spec { - return &spec{response, ResponseCookieFilterName} + return &spec{response, filters.ResponseCookieName} } // Creates a filter spec for appending cookies to responses without the // HttpOnly directive. // Name: jsCookie func NewJSCookie() filters.Spec { - return &spec{responseJS, ResponseJSCookieFilterName} + return &spec{responseJS, filters.JsCookieName} } func (s *spec) Name() string { return s.filterName } diff --git a/filters/cors/cors.go b/filters/cors/cors.go index 1f359fdb5b..616e6359d9 100644 --- a/filters/cors/cors.go +++ b/filters/cors/cors.go @@ -5,7 +5,6 @@ import ( ) const ( - name = "corsOrigin" allowOriginHeader = "Access-Control-Allow-Origin" ) @@ -59,4 +58,4 @@ func (spec basicSpec) CreateFilter(args []interface{}) (filters.Filter, error) { return f, nil } -func (spec basicSpec) Name() string { return name } +func (spec basicSpec) Name() string { return filters.CorsOriginName } diff --git a/filters/diag/absorb.go b/filters/diag/absorb.go index 78983171ab..0d53601236 100644 --- a/filters/diag/absorb.go +++ b/filters/diag/absorb.go @@ -11,10 +11,12 @@ import ( ) // AbsorbName contains the name of the absorb filter. -const AbsorbName = "absorb" +// Deprecated, use filters.AbsorbName instead +const AbsorbName = filters.AbsorbName // AbsorbSilentName contains the name of the absorbSilent filter. -const AbsorbSilentName = "absorbSilent" +// Deprecated, use filters.AbsorbSilentName instead +const AbsorbSilentName = filters.AbsorbSilentName const loggingInterval = time.Second @@ -65,9 +67,9 @@ func NewAbsorbSilent() filters.Spec { func (a *absorb) Name() string { if a.silent { - return AbsorbSilentName + return filters.AbsorbSilentName } else { - return AbsorbName + return filters.AbsorbName } } diff --git a/filters/diag/absorb_test.go b/filters/diag/absorb_test.go index 1fcc34f83b..fd89012018 100644 --- a/filters/diag/absorb_test.go +++ b/filters/diag/absorb_test.go @@ -87,14 +87,14 @@ func testAbsorb(t *testing.T, silent bool) { } func TestAbsorb(t *testing.T) { - if NewAbsorb().Name() != AbsorbName { + if NewAbsorb().Name() != filters.AbsorbName { t.Error("wrong filter name") } testAbsorb(t, false) } func TestAbsorbSilent(t *testing.T) { - if NewAbsorbSilent().Name() != AbsorbSilentName { + if NewAbsorbSilent().Name() != filters.AbsorbSilentName { t.Error("wrong filter name") } testAbsorb(t, true) diff --git a/filters/diag/diag.go b/filters/diag/diag.go index 41d10cc5f0..a6a81e88d8 100644 --- a/filters/diag/diag.go +++ b/filters/diag/diag.go @@ -22,14 +22,22 @@ import ( const defaultChunkSize = 512 const ( - RandomName = "randomContent" - RepeatName = "repeatContent" - LatencyName = "latency" - ChunksName = "chunks" - BandwidthName = "bandwidth" - BackendLatencyName = "backendLatency" - BackendBandwidthName = "backendBandwidth" - BackendChunksName = "backendChunks" + // Deprecated, use filters.RandomContentName instead + RandomName = filters.RandomContentName + // Deprecated, use filters.RepeatContentName instead + RepeatName = filters.RepeatContentName + // Deprecated, use filters.LatencyName instead + LatencyName = filters.LatencyName + // Deprecated, use filters.ChunksName instead + ChunksName = filters.ChunksName + // Deprecated, use filters.BandwidthName instead + BandwidthName = filters.BandwidthName + // Deprecated, use filters.BackendLatencyName instead + BackendLatencyName = filters.BackendLatencyName + // Deprecated, use filters.BackendBandwidthName instead + BackendBandwidthName = filters.BackendBandwidthName + // Deprecated, use filters.BackendChunksName instead + BackendChunksName = filters.BackendChunksName ) type throttleType int @@ -178,7 +186,7 @@ func NewUniformResponseLatency() filters.Spec { return &jitter{typ: uniformRespo // func NewNormalResponseLatency() filters.Spec { return &jitter{typ: normalResponseDistribution} } -func (r *random) Name() string { return RandomName } +func (r *random) Name() string { return filters.RandomContentName } func (r *random) CreateFilter(args []interface{}) (filters.Filter, error) { if len(args) != 1 { @@ -210,7 +218,7 @@ func (r *random) Request(ctx filters.FilterContext) { func (r *random) Response(ctx filters.FilterContext) {} -func (r *repeat) Name() string { return RepeatName } +func (r *repeat) Name() string { return filters.RepeatContentName } func (r *repeat) CreateFilter(args []interface{}) (filters.Filter, error) { if len(args) != 2 { @@ -266,17 +274,17 @@ func (r *repeat) Response(ctx filters.FilterContext) {} func (t *throttle) Name() string { switch t.typ { case latency: - return LatencyName + return filters.LatencyName case bandwidth: - return BandwidthName + return filters.BandwidthName case chunks: - return ChunksName + return filters.ChunksName case backendLatency: - return BackendLatencyName + return filters.BackendLatencyName case backendBandwidth: - return BackendBandwidthName + return filters.BackendBandwidthName case backendChunks: - return BackendChunksName + return filters.BackendChunksName default: panic("invalid throttle type") } @@ -464,13 +472,13 @@ func (t *throttle) Response(ctx filters.FilterContext) { func (j *jitter) Name() string { switch j.typ { case normalRequestDistribution: - return "normalRequestLatency" + return filters.NormalRequestLatencyName case uniformRequestDistribution: - return "uniformRequestLatency" + return filters.UniformRequestLatencyName case normalResponseDistribution: - return "normalResponseLatency" + return filters.NormalResponseLatencyName case uniformResponseDistribution: - return "uniformResponseLatency" + return filters.UniformResponseLatencyName } return "unknown" } diff --git a/filters/diag/diag_test.go b/filters/diag/diag_test.go index 798dfd43e4..824d094f15 100644 --- a/filters/diag/diag_test.go +++ b/filters/diag/diag_test.go @@ -158,8 +158,8 @@ func TestRandom(t *testing.T) { defaultChunkSize*2 + defaultChunkSize/2, }} { func() { - p := proxytest.New(filters.Registry{RandomName: &random{}}, &eskip.Route{ - Filters: []*eskip.Filter{{Name: RandomName, Args: []interface{}{float64(ti.len)}}}, + p := proxytest.New(filters.Registry{filters.RandomContentName: &random{}}, &eskip.Route{ + Filters: []*eskip.Filter{{Name: filters.RandomContentName, Args: []interface{}{float64(ti.len)}}}, Shunt: true}) defer p.Close() @@ -269,8 +269,8 @@ func TestRepeat(t *testing.T) { } } - p := proxytest.New(filters.Registry{RepeatName: repeat}, &eskip.Route{ - Filters: []*eskip.Filter{{Name: RepeatName, Args: ti.args}}, + p := proxytest.New(filters.Registry{filters.RepeatContentName: repeat}, &eskip.Route{ + Filters: []*eskip.Filter{{Name: filters.RepeatContentName, Args: ti.args}}, Shunt: true}) defer p.Close() @@ -596,23 +596,23 @@ func TestThrottle(t *testing.T) { rc := &requestCheck{} r := filters.Registry{ - requestCheckName: rc, - RandomName: &random{}} + requestCheckName: rc, + filters.RandomContentName: &random{}} testServer := proxytest.New(r, &eskip.Route{ Filters: []*eskip.Filter{ {Name: requestCheckName, Args: nil}, - {Name: RandomName, Args: []interface{}{float64(testDataLen)}}}, + {Name: filters.RandomContentName, Args: []interface{}{float64(testDataLen)}}}, Shunt: true}) defer testServer.Close() proxyFilters := filters.Registry{ - LatencyName: NewLatency(), - BandwidthName: NewBandwidth(), - ChunksName: NewChunks(), - BackendLatencyName: NewBackendLatency(), - BackendBandwidthName: NewBackendBandwidth(), - BackendChunksName: NewBackendChunks()} + filters.LatencyName: NewLatency(), + filters.BandwidthName: NewBandwidth(), + filters.ChunksName: NewChunks(), + filters.BackendLatencyName: NewBackendLatency(), + filters.BackendBandwidthName: NewBackendBandwidth(), + filters.BackendChunksName: NewBackendChunks()} for _, ti := range []struct { msg string @@ -621,73 +621,73 @@ func TestThrottle(t *testing.T) { backendExpect messageExp }{{ msg: "zero latency", - filters: []*eskip.Filter{{Name: LatencyName, Args: []interface{}{float64(0)}}}, + filters: []*eskip.Filter{{Name: filters.LatencyName, Args: []interface{}{float64(0)}}}, clientExpect: messageExp{header: time.Millisecond}, }, { msg: "latency", - filters: []*eskip.Filter{{Name: LatencyName, Args: []interface{}{float64(smallDelay)}}}, + filters: []*eskip.Filter{{Name: filters.LatencyName, Args: []interface{}{float64(smallDelay)}}}, clientExpect: messageExp{header: smallDelay * time.Millisecond}, }, { msg: "high latency", - filters: []*eskip.Filter{{Name: LatencyName, Args: []interface{}{float64(highDelay)}}}, + filters: []*eskip.Filter{{Name: filters.LatencyName, Args: []interface{}{float64(highDelay)}}}, clientExpect: messageExp{header: highDelay * time.Millisecond}, }, { msg: "zero backend latency", - filters: []*eskip.Filter{{Name: BackendLatencyName, Args: []interface{}{float64(0)}}}, + filters: []*eskip.Filter{{Name: filters.BackendLatencyName, Args: []interface{}{float64(0)}}}, backendExpect: messageExp{header: time.Millisecond}, }, { msg: "backend latency", - filters: []*eskip.Filter{{Name: BackendLatencyName, Args: []interface{}{float64(smallDelay)}}}, + filters: []*eskip.Filter{{Name: filters.BackendLatencyName, Args: []interface{}{float64(smallDelay)}}}, backendExpect: messageExp{header: smallDelay * time.Millisecond}, }, { msg: "high backend latency", - filters: []*eskip.Filter{{Name: BackendLatencyName, Args: []interface{}{float64(highDelay)}}}, + filters: []*eskip.Filter{{Name: filters.BackendLatencyName, Args: []interface{}{float64(highDelay)}}}, backendExpect: messageExp{header: highDelay * time.Millisecond}, }, { msg: "bandwidth", - filters: []*eskip.Filter{{Name: BandwidthName, Args: []interface{}{float64(12)}}}, + filters: []*eskip.Filter{{Name: filters.BandwidthName, Args: []interface{}{float64(12)}}}, clientExpect: messageExp{kbps: 12}, }, { msg: "very high bandwidth", - filters: []*eskip.Filter{{Name: BandwidthName, Args: []interface{}{float64(12000000000)}}}, + filters: []*eskip.Filter{{Name: filters.BandwidthName, Args: []interface{}{float64(12000000000)}}}, }, { msg: "bandwidth, adjust", filters: []*eskip.Filter{{ - Name: BandwidthName, + Name: filters.BandwidthName, Args: []interface{}{float64(12)}, }, { - Name: BandwidthName, + Name: filters.BandwidthName, Args: []interface{}{float64(36)}, }}, clientExpect: messageExp{kbps: 12}, }, { msg: "backend bandwidth", - filters: []*eskip.Filter{{Name: BackendBandwidthName, Args: []interface{}{float64(12)}}}, + filters: []*eskip.Filter{{Name: filters.BackendBandwidthName, Args: []interface{}{float64(12)}}}, backendExpect: messageExp{kbps: 12}, }, { msg: "backend, very high bandwidth", - filters: []*eskip.Filter{{Name: BackendBandwidthName, Args: []interface{}{float64(12000000000)}}}, + filters: []*eskip.Filter{{Name: filters.BackendBandwidthName, Args: []interface{}{float64(12000000000)}}}, }, { msg: "backend bandwidth, adjust", filters: []*eskip.Filter{{ - Name: BackendBandwidthName, + Name: filters.BackendBandwidthName, Args: []interface{}{float64(36)}, }, { - Name: BackendBandwidthName, + Name: filters.BackendBandwidthName, Args: []interface{}{float64(12)}, }}, backendExpect: messageExp{kbps: 12}, }, { msg: "single chunk", - filters: []*eskip.Filter{{Name: ChunksName, Args: []interface{}{float64(2 * testDataLen), float64(smallDelay)}}}, + filters: []*eskip.Filter{{Name: filters.ChunksName, Args: []interface{}{float64(2 * testDataLen), float64(smallDelay)}}}, clientExpect: messageExp{chunks: []testChunk{{2 * testDataLen, time.Duration(smallDelay) * time.Millisecond}}}, }, { msg: "single chunk, long delay", - filters: []*eskip.Filter{{Name: ChunksName, Args: []interface{}{float64(2 * testDataLen), float64(highDelay)}}}, + filters: []*eskip.Filter{{Name: filters.ChunksName, Args: []interface{}{float64(2 * testDataLen), float64(highDelay)}}}, clientExpect: messageExp{chunks: []testChunk{{2 * testDataLen, time.Duration(highDelay) * time.Millisecond}}}, }, { msg: "multiple chunks", - filters: []*eskip.Filter{{Name: ChunksName, Args: []interface{}{float64(testDataLen/4 + testDataLen/8), float64(smallDelay)}}}, + filters: []*eskip.Filter{{Name: filters.ChunksName, Args: []interface{}{float64(testDataLen/4 + testDataLen/8), float64(smallDelay)}}}, clientExpect: messageExp{chunks: []testChunk{{ testDataLen/4 + testDataLen/8, time.Duration(smallDelay) * time.Millisecond, }, { @@ -697,7 +697,7 @@ func TestThrottle(t *testing.T) { }}}, }, { msg: "multiple chunks, long delay", - filters: []*eskip.Filter{{Name: ChunksName, Args: []interface{}{float64(testDataLen/4 + testDataLen/8), float64(highDelay)}}}, + filters: []*eskip.Filter{{Name: filters.ChunksName, Args: []interface{}{float64(testDataLen/4 + testDataLen/8), float64(highDelay)}}}, clientExpect: messageExp{chunks: []testChunk{{ testDataLen/4 + testDataLen/8, time.Duration(highDelay) * time.Millisecond, }, { @@ -707,15 +707,15 @@ func TestThrottle(t *testing.T) { }}}, }, { msg: "single chunk, backend", - filters: []*eskip.Filter{{Name: BackendChunksName, Args: []interface{}{float64(2 * testDataLen), float64(smallDelay)}}}, + filters: []*eskip.Filter{{Name: filters.BackendChunksName, Args: []interface{}{float64(2 * testDataLen), float64(smallDelay)}}}, backendExpect: messageExp{chunks: []testChunk{{2 * testDataLen, time.Duration(smallDelay) * time.Millisecond}}}, }, { msg: "single chunk, long delay, backend", - filters: []*eskip.Filter{{Name: BackendChunksName, Args: []interface{}{float64(2 * testDataLen), float64(highDelay)}}}, + filters: []*eskip.Filter{{Name: filters.BackendChunksName, Args: []interface{}{float64(2 * testDataLen), float64(highDelay)}}}, backendExpect: messageExp{chunks: []testChunk{{2 * testDataLen, time.Duration(highDelay) * time.Millisecond}}}, }, { msg: "multiple chunks, backend", - filters: []*eskip.Filter{{Name: BackendChunksName, Args: []interface{}{float64(testDataLen/4 + testDataLen/8), float64(smallDelay)}}}, + filters: []*eskip.Filter{{Name: filters.BackendChunksName, Args: []interface{}{float64(testDataLen/4 + testDataLen/8), float64(smallDelay)}}}, backendExpect: messageExp{chunks: []testChunk{{ testDataLen/4 + testDataLen/8, time.Duration(smallDelay) * time.Millisecond, }, { @@ -725,7 +725,7 @@ func TestThrottle(t *testing.T) { }}}, }, { msg: "multiple chunks, long delay, backend", - filters: []*eskip.Filter{{Name: BackendChunksName, Args: []interface{}{float64(testDataLen/4 + testDataLen/8), float64(highDelay)}}}, + filters: []*eskip.Filter{{Name: filters.BackendChunksName, Args: []interface{}{float64(testDataLen/4 + testDataLen/8), float64(highDelay)}}}, backendExpect: messageExp{chunks: []testChunk{{ testDataLen/4 + testDataLen/8, time.Duration(highDelay) * time.Millisecond, }, { diff --git a/filters/diag/logheader.go b/filters/diag/logheader.go index ee1670b303..e828763dbb 100644 --- a/filters/diag/logheader.go +++ b/filters/diag/logheader.go @@ -15,7 +15,11 @@ type logHeader struct { // NewLogHeader creates a filter specification for the 'logHeader()' filter. func NewLogHeader() filters.Spec { return logHeader{} } -func (logHeader) Name() string { return "logHeader" } + +// Name returns the logHeader filtern name. +func (logHeader) Name() string { + return filters.LogHeaderName +} func (logHeader) CreateFilter(args []interface{}) (filters.Filter, error) { var ( diff --git a/filters/fadein/fadein.go b/filters/fadein/fadein.go index 86efcef9cd..af673f15a8 100644 --- a/filters/fadein/fadein.go +++ b/filters/fadein/fadein.go @@ -14,8 +14,10 @@ import ( ) const ( - FadeInName = "fadeIn" - EndpointCreatedName = "endpointCreated" + // Deprecated, use filters.FadeInName instead + FadeInName = filters.FadeInName + // Deprecated, use filters.EndpointCreatedName instead + EndpointCreatedName = filters.EndpointCreatedName ) type ( @@ -46,7 +48,7 @@ func NewFadeIn() filters.Spec { return fadeIn{} } -func (fadeIn) Name() string { return FadeInName } +func (fadeIn) Name() string { return filters.FadeInName } func (fadeIn) CreateFilter(args []interface{}) (filters.Filter, error) { if len(args) == 0 || len(args) > 2 { @@ -96,7 +98,7 @@ func NewEndpointCreated() filters.Spec { return ec } -func (endpointCreated) Name() string { return EndpointCreatedName } +func (endpointCreated) Name() string { return filters.EndpointCreatedName } func normalizeSchemeHost(s, h string) (string, string, error) { // endpoint address cannot contain path, the rest is not case sensitive diff --git a/filters/fadein/fadein_test.go b/filters/fadein/fadein_test.go index bd113629f0..bafcc3a9d3 100644 --- a/filters/fadein/fadein_test.go +++ b/filters/fadein/fadein_test.go @@ -192,8 +192,8 @@ func TestPostProcessor(t *testing.T) { rt := routing.New(routing.Options{ DataClients: []routing.DataClient{dc}, FilterRegistry: filters.Registry{ - FadeInName: NewFadeIn(), - EndpointCreatedName: NewEndpointCreated(), + filters.FadeInName: NewFadeIn(), + filters.EndpointCreatedName: NewEndpointCreated(), }, PostProcessors: []routing.PostProcessor{ loadbalancer.NewAlgorithmProvider(), diff --git a/filters/filters.go b/filters/filters.go index 9121a7b956..f6fa447a45 100644 --- a/filters/filters.go +++ b/filters/filters.go @@ -171,3 +171,130 @@ var ErrInvalidFilterParameters = errors.New("invalid filter parameters") func (r Registry) Register(s Spec) { r[s.Name()] = s } + +// All Skipper filter names +const ( + BackendIsProxyName = "backendIsProxy" + ModRequestHeaderName = "modRequestHeader" + SetRequestHeaderName = "setRequestHeader" + AppendRequestHeaderName = "appendRequestHeader" + DropRequestHeaderName = "dropRequestHeader" + SetResponseHeaderName = "setResponseHeader" + AppendResponseHeaderName = "appendResponseHeader" + DropResponseHeaderName = "dropResponseHeader" + SetContextRequestHeaderName = "setContextRequestHeader" + AppendContextRequestHeaderName = "appendContextRequestHeader" + SetContextResponseHeaderName = "setContextResponseHeader" + AppendContextResponseHeaderName = "appendContextResponseHeader" + CopyRequestHeaderName = "copyRequestHeader" + CopyResponseHeaderName = "copyResponseHeader" + ModPathName = "modPath" + SetPathName = "setPath" + RedirectToName = "redirectTo" + RedirectToLowerName = "redirectToLower" + StaticName = "static" + StripQueryName = "stripQuery" + PreserveHostName = "preserveHost" + StatusName = "status" + CompressName = "compress" + DecompressName = "decompress" + SetQueryName = "setQuery" + DropQueryName = "dropQuery" + InlineContentName = "inlineContent" + InlineContentIfStatusName = "inlineContentIfStatus" + FlowIdName = "flowId" + XforwardName = "xforward" + XforwardFirstName = "xforwardFirst" + RandomContentName = "randomContent" + RepeatContentName = "repeatContent" + BackendTimeoutName = "backendTimeout" + LatencyName = "latency" + BandwidthName = "bandwidth" + ChunksName = "chunks" + BackendLatencyName = "backendLatency" + BackendBandwidthName = "backendBandwidth" + BackendChunksName = "backendChunks" + AbsorbName = "absorb" + AbsorbSilentName = "absorbSilent" + UniformRequestLatencyName = "uniformRequestLatency" + NormalRequestLatencyName = "normalRequestLatency" + UniformResponseLatencyName = "uniformResponseLatency" + NormalResponseLatencyName = "normalResponseLatency" + LogHeaderName = "logHeader" + TeeName = "tee" + TeenfName = "teenf" + TeeLoopbackName = "teeLoopback" + SedName = "sed" + SedDelimName = "sedDelim" + SedRequestName = "sedRequest" + SedRequestDelimName = "sedRequestDelim" + BasicAuthName = "basicAuth" + WebhookName = "webhook" + OAuthTokeninfoAnyScopeName = "oauthTokeninfoAnyScope" + OAuthTokeninfoAllScopeName = "oauthTokeninfoAllScope" + OAuthTokeninfoAnyKVName = "oauthTokeninfoAnyKV" + OAuthTokeninfoAllKVName = "oauthTokeninfoAllKV" + OAuthTokenintrospectionAnyClaimsName = "oauthTokenintrospectionAnyClaims" + OAuthTokenintrospectionAllClaimsName = "oauthTokenintrospectionAllClaims" + OAuthTokenintrospectionAnyKVName = "oauthTokenintrospectionAnyKV" + OAuthTokenintrospectionAllKVName = "oauthTokenintrospectionAllKV" + SecureOAuthTokenintrospectionAnyClaimsName = "secureOauthTokenintrospectionAnyClaims" + SecureOAuthTokenintrospectionAllClaimsName = "secureOauthTokenintrospectionAllClaims" + SecureOAuthTokenintrospectionAnyKVName = "secureOauthTokenintrospectionAnyKV" + SecureOAuthTokenintrospectionAllKVName = "secureOauthTokenintrospectionAllKV" + ForwardTokenName = "forwardToken" + OAuthGrantName = "oauthGrant" + GrantCallbackName = "grantCallback" + GrantLogoutName = "grantLogout" + GrantClaimsQueryName = "grantClaimsQuery" + OAuthOidcUserInfoName = "oauthOidcUserInfo" + OAuthOidcAnyClaimsName = "oauthOidcAnyClaims" + OAuthOidcAllClaimsName = "oauthOidcAllClaims" + RequestCookieName = "requestCookie" + OidcClaimsQueryName = "oidcClaimsQuery" + ResponseCookieName = "responseCookie" + JsCookieName = "jsCookie" + ConsecutiveBreakerName = "consecutiveBreaker" + RateBreakerName = "rateBreaker" + DisableBreakerName = "disableBreaker" + ClientRatelimitName = "clientRatelimit" + RatelimitName = "ratelimit" + ClusterClientRatelimitName = "clusterClientRatelimit" + ClusterRatelimitName = "clusterRatelimit" + BackendRateLimitName = "backendRatelimit" + LuaName = "lua" + CorsOriginName = "corsOrigin" + HeaderToQueryName = "headerToQuery" + QueryToHeaderName = "queryToHeader" + DisableAccessLogName = "disableAccessLog" + EnableAccessLogName = "enableAccessLog" + AuditLogName = "auditLog" + UnverifiedAuditLogName = "unverifiedAuditLog" + SetDynamicBackendHostFromHeader = "setDynamicBackendHostFromHeader" + SetDynamicBackendSchemeFromHeader = "setDynamicBackendSchemeFromHeader" + SetDynamicBackendUrlFromHeader = "setDynamicBackendUrlFromHeader" + SetDynamicBackendHost = "setDynamicBackendHost" + SetDynamicBackendScheme = "setDynamicBackendScheme" + SetDynamicBackendUrl = "setDynamicBackendUrl" + ApiUsageMonitoringName = "apiUsageMonitoring" + LifoName = "lifo" + LifoGroupName = "lifoGroup" + RfcPathName = "rfcPath" + RfcHostName = "rfcHost" + BearerInjectorName = "bearerinjector" + TracingBaggageToTagName = "tracingBaggageToTag" + StateBagToTagName = "stateBagToTag" + TracingTagName = "tracingTag" + TracingSpanNameName = "tracingSpanName" + OriginMarkerName = "originMarker" + FadeInName = "fadeIn" + EndpointCreatedName = "endpointCreated" + ConsistentHashKeyName = "consistentHashKey" + ConsistentHashBalanceFactorName = "consistentHashBalanceFactor" + + // Undocumented filters + HealthCheckName = "healthcheck" + SetFastCgiFilenameName = "setFastCgiFilename" + DisableRatelimitName = "disableRatelimit" + UnknownRatelimitName = "unknownRatelimit" +) diff --git a/filters/flowid/filter.go b/filters/flowid/filter.go index bddf3809fc..636f7d8f09 100644 --- a/filters/flowid/filter.go +++ b/filters/flowid/filter.go @@ -9,7 +9,9 @@ import ( ) const ( - Name = "flowId" + // Deprecated, use filters.FlowIdName instead + Name = filters.FlowIdName + ReuseParameterValue = "reuse" HeaderName = "X-Flow-Id" ) @@ -105,4 +107,4 @@ func (spec *flowIdSpec) CreateFilter(fc []interface{}) (filters.Filter, error) { } // Name returns the canonical filter name -func (*flowIdSpec) Name() string { return Name } +func (*flowIdSpec) Name() string { return filters.FlowIdName } diff --git a/filters/log/log.go b/filters/log/log.go index 9ecfe45d1a..063ea8fb43 100644 --- a/filters/log/log.go +++ b/filters/log/log.go @@ -20,8 +20,9 @@ import ( ) const ( - // AuditLogName is the filter name seen by the user - AuditLogName = "auditLog" + // Deprecated, use filters.AuditLogName instead + AuditLogName = filters.AuditLogName + // AuthUserKey is used by the auth package to set the user // information into the state bag to pass the information to // the auditLog filter. @@ -30,8 +31,9 @@ const ( // reject reason information into the state bag to pass the // information to the auditLog filter. AuthRejectReasonKey = "auth-reject-reason" - // UnverifiedAuditLogName is the filtername seen by the user - UnverifiedAuditLogName = "unverifiedAuditLog" + + // Deprecated, use filters.UnverifiedAuditLogName instead + UnverifiedAuditLogName = filters.UnverifiedAuditLogName // UnverifiedAuditHeader is the name of the header added to the request which contains the unverified audit details UnverifiedAuditHeader = "X-Unverified-Audit" @@ -117,7 +119,7 @@ func NewAuditLog(maxAuditBody int) filters.Spec { } } -func (al *auditLog) Name() string { return AuditLogName } +func (al *auditLog) Name() string { return filters.AuditLogName } // CreateFilter has no arguments. It creates the filter if the user // specifies auditLog() in their route. @@ -184,7 +186,7 @@ type ( // NewUnverifiedAuditLog logs "Sub" of the middle part of a JWT Token. Or else, logs the requested JSON key if present func NewUnverifiedAuditLog() filters.Spec { return &unverifiedAuditLogSpec{} } -func (ual *unverifiedAuditLogSpec) Name() string { return UnverifiedAuditLogName } +func (ual *unverifiedAuditLogSpec) Name() string { return filters.UnverifiedAuditLogName } // CreateFilter has no arguments. It creates the filter if the user // specifies unverifiedAuditLog() in their route. diff --git a/filters/ratelimit/backendratelimit.go b/filters/ratelimit/backendratelimit.go index 092d2852e0..b465d90489 100644 --- a/filters/ratelimit/backendratelimit.go +++ b/filters/ratelimit/backendratelimit.go @@ -16,7 +16,9 @@ type BackendRatelimit struct { // instruct proxy to limit request rate towards a particular backend endpoint func NewBackendRatelimit() filters.Spec { return &BackendRatelimit{} } -func (*BackendRatelimit) Name() string { return "backendRatelimit" } +func (*BackendRatelimit) Name() string { + return filters.BackendRateLimitName +} func (*BackendRatelimit) CreateFilter(args []interface{}) (filters.Filter, error) { if len(args) != 3 && len(args) != 4 { diff --git a/filters/ratelimit/ratelimit.go b/filters/ratelimit/ratelimit.go index 6f21e6a1ec..3b8551e039 100644 --- a/filters/ratelimit/ratelimit.go +++ b/filters/ratelimit/ratelimit.go @@ -85,7 +85,7 @@ func NewLocalRatelimit(provider RatelimitProvider) filters.Spec { // -> clientRatelimit(3, "1m", "Authorization") // -> "https://login.backend.net"; func NewClientRatelimit(provider RatelimitProvider) filters.Spec { - return &spec{typ: ratelimit.ClientRatelimit, provider: provider, filterName: ratelimit.ClientRatelimitName} + return &spec{typ: ratelimit.ClientRatelimit, provider: provider, filterName: filters.ClientRatelimitName} } // NewRatelimit creates a service rate limiting, that is @@ -107,7 +107,7 @@ func NewClientRatelimit(provider RatelimitProvider) filters.Spec { // -> ratelimit(20, "1s", 503) // -> "https://foo.backend.net"; func NewRatelimit(provider RatelimitProvider) filters.Spec { - return &spec{typ: ratelimit.ServiceRatelimit, provider: provider, filterName: ratelimit.ServiceRatelimitName} + return &spec{typ: ratelimit.ServiceRatelimit, provider: provider, filterName: filters.RatelimitName} } // NewClusterRatelimit creates a rate limiting that is aware of the @@ -130,7 +130,7 @@ func NewRatelimit(provider RatelimitProvider) filters.Spec { // -> clusterRatelimit("groupA", 200, "1m", 503) // -> "https://foo.backend.net"; func NewClusterRateLimit(provider RatelimitProvider) filters.Spec { - return &spec{typ: ratelimit.ClusterServiceRatelimit, provider: provider, filterName: ratelimit.ClusterServiceRatelimitName} + return &spec{typ: ratelimit.ClusterServiceRatelimit, provider: provider, filterName: filters.ClusterRatelimitName} } // NewClusterClientRatelimit creates a rate limiting that is aware of @@ -159,7 +159,7 @@ func NewClusterRateLimit(provider RatelimitProvider) filters.Spec { // -> "https://foo.backend.net"; // func NewClusterClientRateLimit(provider RatelimitProvider) filters.Spec { - return &spec{typ: ratelimit.ClusterClientRatelimit, provider: provider, filterName: ratelimit.ClusterClientRatelimitName} + return &spec{typ: ratelimit.ClusterClientRatelimit, provider: provider, filterName: filters.ClusterClientRatelimitName} } // NewDisableRatelimit disables rate limiting @@ -170,7 +170,7 @@ func NewClusterClientRateLimit(provider RatelimitProvider) filters.Spec { // -> disableRatelimit() // -> "https://foo.backend.net"; func NewDisableRatelimit(provider RatelimitProvider) filters.Spec { - return &spec{typ: ratelimit.DisableRatelimit, provider: provider, filterName: ratelimit.DisableRatelimitName} + return &spec{typ: ratelimit.DisableRatelimit, provider: provider, filterName: filters.DisableRatelimitName} } func (s *spec) Name() string { diff --git a/filters/rfc/rfc.go b/filters/rfc/rfc.go index 608b321025..501c4a6e99 100644 --- a/filters/rfc/rfc.go +++ b/filters/rfc/rfc.go @@ -6,8 +6,12 @@ import ( ) const ( - Name = "rfcPath" - NameHost = "rfcHost" + // Name is the filter name + // Deprecated, use filters.RfcPathName instead + Name = filters.RfcPathName + // NameHost is the filter name + // Deprecated, use filters.RfcHostName instead + NameHost = filters.RfcHostName ) type path struct{} @@ -20,7 +24,7 @@ type path struct{} // func NewPath() filters.Spec { return path{} } -func (p path) Name() string { return Name } +func (p path) Name() string { return filters.RfcPathName } func (p path) CreateFilter([]interface{}) (filters.Filter, error) { return path{}, nil } func (p path) Response(filters.FilterContext) {} @@ -38,7 +42,7 @@ type host struct{} // func NewHost() filters.Spec { return host{} } -func (host) Name() string { return NameHost } +func (host) Name() string { return filters.RfcHostName } func (host) CreateFilter([]interface{}) (filters.Filter, error) { return host{}, nil } func (host) Response(filters.FilterContext) {} diff --git a/filters/scheduler/lifo.go b/filters/scheduler/lifo.go index 3efe308a91..d41285ee8c 100644 --- a/filters/scheduler/lifo.go +++ b/filters/scheduler/lifo.go @@ -28,8 +28,10 @@ type ( ) const ( - LIFOName = "lifo" - LIFOGroupName = "lifoGroup" + // Deprecated, use filters.LifoName instead + LIFOName = filters.LifoName + // Deprecated, use filters.LifoGroupName instead + LIFOGroupName = filters.LifoGroupName defaultMaxConcurreny = 100 defaultMaxQueueSize = 100 @@ -64,7 +66,7 @@ func durationArg(a interface{}) (time.Duration, error) { } } -func (s *lifoSpec) Name() string { return LIFOName } +func (s *lifoSpec) Name() string { return filters.LifoName } // CreateFilter creates a lifoFilter, that will use a queue based // queue for handling requests instead of the fifo queue. The first @@ -129,7 +131,7 @@ func (s *lifoSpec) CreateFilter(args []interface{}) (filters.Filter, error) { return &l, nil } -func (*lifoGroupSpec) Name() string { return LIFOGroupName } +func (*lifoGroupSpec) Name() string { return filters.LifoGroupName } // CreateFilter creates a lifoGroupFilter, that will use a queue based // queue for handling requests instead of the fifo queue. The first diff --git a/filters/scheduler/lifo_test.go b/filters/scheduler/lifo_test.go index 634ec5df48..51b2be8039 100644 --- a/filters/scheduler/lifo_test.go +++ b/filters/scheduler/lifo_test.go @@ -33,7 +33,7 @@ func TestNewLIFO(t *testing.T) { "5s", }, schedFunc: NewLIFO, - wantName: LIFOName, + wantName: filters.LifoName, wantKey: "mykey", wantErr: false, wantConfig: scheduler.Config{ @@ -52,7 +52,7 @@ func TestNewLIFO(t *testing.T) { "5s", }, schedFunc: NewLIFOGroup, - wantName: LIFOGroupName, + wantName: filters.LifoGroupName, wantKey: "mygroup", wantErr: false, wantConfig: scheduler.Config{ @@ -71,7 +71,7 @@ func TestNewLIFO(t *testing.T) { "5s", }, schedFunc: NewLIFOGroup, - wantName: LIFOGroupName, + wantName: filters.LifoGroupName, wantKey: "mygroup", wantErr: false, wantConfig: scheduler.Config{ @@ -88,7 +88,7 @@ func TestNewLIFO(t *testing.T) { -15, }, schedFunc: NewLIFO, - wantName: LIFOName, + wantName: filters.LifoName, wantKey: "mykey", wantErr: false, wantConfig: scheduler.Config{ @@ -106,7 +106,7 @@ func TestNewLIFO(t *testing.T) { -15, }, schedFunc: NewLIFOGroup, - wantName: LIFOGroupName, + wantName: filters.LifoGroupName, wantKey: "mygroup", wantErr: false, wantConfig: scheduler.Config{ @@ -124,7 +124,7 @@ func TestNewLIFO(t *testing.T) { "4a", }, schedFunc: NewLIFO, - wantName: LIFOName, + wantName: filters.LifoName, wantKey: "mykey", wantErr: true, wantConfig: scheduler.Config{ @@ -143,7 +143,7 @@ func TestNewLIFO(t *testing.T) { "4a", }, schedFunc: NewLIFOGroup, - wantName: LIFOGroupName, + wantName: filters.LifoGroupName, wantKey: "mygroup", wantErr: true, wantConfig: scheduler.Config{ @@ -162,7 +162,7 @@ func TestNewLIFO(t *testing.T) { 4.5, }, schedFunc: NewLIFOGroup, - wantName: LIFOGroupName, + wantName: filters.LifoGroupName, wantKey: "mygroup", wantErr: true, wantConfig: scheduler.Config{ @@ -181,7 +181,7 @@ func TestNewLIFO(t *testing.T) { "4s", }, schedFunc: NewLIFOGroup, - wantName: LIFOGroupName, + wantName: filters.LifoGroupName, wantKey: "mygroup", wantErr: true, wantConfig: scheduler.Config{ diff --git a/filters/sed/sed.go b/filters/sed/sed.go index b6cc0fd8ce..047df3909b 100644 --- a/filters/sed/sed.go +++ b/filters/sed/sed.go @@ -7,10 +7,14 @@ import ( ) const ( - Name = "sed" - NameDelimit = "sedDelim" - NameRequest = "sedRequest" - NameRequestDelimit = "sedRequestDelim" + // Deprecated, use filters.SedName instead + Name = filters.SedName + // Deprecated, use filters.SedDelimName instead + NameDelimit = filters.SedDelimName + // Deprecated, use filters.SedRequestName instead + NameRequest = filters.SedRequestName + // Deprecated, use filters.SedRequestDelimName instead + NameRequestDelimit = filters.SedRequestDelimName ) type typ int @@ -62,13 +66,13 @@ func NewDelimitedRequest() filters.Spec { func (s spec) Name() string { switch s.typ { case delimited: - return NameDelimit + return filters.SedDelimName case simpleRequest: - return NameRequest + return filters.SedRequestName case delimitedRequest: - return NameRequestDelimit + return filters.SedRequestDelimName default: - return Name + return filters.SedName } } diff --git a/filters/sed/sed_test.go b/filters/sed/sed_test.go index 34e81d6c27..4e0deea491 100644 --- a/filters/sed/sed_test.go +++ b/filters/sed/sed_test.go @@ -9,8 +9,8 @@ import ( "testing" "github.com/zalando/skipper/eskip" + "github.com/zalando/skipper/filters" "github.com/zalando/skipper/filters/builtin" - "github.com/zalando/skipper/filters/sed" "github.com/zalando/skipper/proxy/proxytest" ) @@ -172,8 +172,8 @@ func TestSed(t *testing.T) { body: "foobarbazfoobarbazfoobarbaz", expect: "foobarbazbarbazfoobarbazbarbazfoobarbazbarbaz", }} { - t.Run(fmt.Sprintf("%s/%s", sed.NameRequest, test.title), testRequest(sed.NameRequest, test)) - t.Run(fmt.Sprintf("%s/%s", sed.Name, test.title), testResponse(sed.Name, test)) + t.Run(fmt.Sprintf("%s/%s", filters.SedRequestName, test.title), testRequest(filters.SedRequestName, test)) + t.Run(fmt.Sprintf("%s/%s", filters.SedName, test.title), testResponse(filters.SedName, test)) } } @@ -196,18 +196,18 @@ func TestSedLongStream(t *testing.T) { baseArgs := []interface{}{pattern, outputString} - t.Run("below max buffer size", testResponse(sed.Name, testItem{ + t.Run("below max buffer size", testResponse(filters.SedName, testItem{ args: append(baseArgs, bodySize*2), bodyReader: createBody(), expect: "qux", })) - t.Run("above max buffer size, abort", testResponse(sed.Name, testItem{ + t.Run("above max buffer size, abort", testResponse(filters.SedName, testItem{ args: append(baseArgs, bodySize/2, "abort"), bodyReader: createBody(), })) - t.Run("above max buffer size, best effort", testResponse(sed.Name, testItem{ + t.Run("above max buffer size, best effort", testResponse(filters.SedName, testItem{ args: append(baseArgs, bodySize/2), bodyReader: createBody(), expect: "quxqux", diff --git a/filters/sed/seddelim_test.go b/filters/sed/seddelim_test.go index 0b6b77794e..8d3ecba5b0 100644 --- a/filters/sed/seddelim_test.go +++ b/filters/sed/seddelim_test.go @@ -6,7 +6,7 @@ import ( "io" "testing" - "github.com/zalando/skipper/filters/sed" + "github.com/zalando/skipper/filters" ) func TestSedDelim(t *testing.T) { @@ -73,11 +73,11 @@ func TestSedDelim(t *testing.T) { expect: "foobarbazbarbaz\nfoobarbazbarbaz\nfoobarbazbarbaz", }} { t.Run( - fmt.Sprintf("%s/%s", sed.NameRequestDelimit, test.title), - testRequest(sed.NameRequestDelimit, test), + fmt.Sprintf("%s/%s", filters.SedRequestDelimName, test.title), + testRequest(filters.SedRequestDelimName, test), ) - t.Run(fmt.Sprintf("%s/%s", sed.NameDelimit, test.title), testResponse(sed.NameDelimit, test)) + t.Run(fmt.Sprintf("%s/%s", filters.SedDelimName, test.title), testResponse(filters.SedDelimName, test)) } } @@ -128,11 +128,11 @@ func TestSedDelimNoDelim(t *testing.T) { expect: "foobarbazbarbazfoobarbazbarbazfoobarbazbarbaz", }} { t.Run( - fmt.Sprintf("%s/%s", sed.NameRequestDelimit, test.title), - testRequest(sed.NameRequestDelimit, test), + fmt.Sprintf("%s/%s", filters.SedRequestDelimName, test.title), + testRequest(filters.SedRequestDelimName, test), ) - t.Run(fmt.Sprintf("%s/%s", sed.NameDelimit, test.title), testResponse(sed.NameDelimit, test)) + t.Run(fmt.Sprintf("%s/%s", filters.SedDelimName, test.title), testResponse(filters.SedDelimName, test)) } } @@ -155,18 +155,18 @@ func TestSedDelimLongStream(t *testing.T) { baseArgs := []interface{}{pattern, outputString, "\n"} - t.Run("below max buffer size", testResponse(sed.NameDelimit, testItem{ + t.Run("below max buffer size", testResponse(filters.SedDelimName, testItem{ args: append(baseArgs, bodySize*2), bodyReader: createBody(), expect: "qux", })) - t.Run("above max buffer size, abort", testResponse(sed.NameDelimit, testItem{ + t.Run("above max buffer size, abort", testResponse(filters.SedDelimName, testItem{ args: append(baseArgs, bodySize/2, "abort"), bodyReader: createBody(), })) - t.Run("above max buffer size, best effort", testResponse(sed.NameDelimit, testItem{ + t.Run("above max buffer size, best effort", testResponse(filters.SedDelimName, testItem{ args: append(baseArgs, bodySize/2), bodyReader: createBody(), expect: "quxqux", diff --git a/filters/tee/tee.go b/filters/tee/tee.go index f4049da642..53fac8c18b 100644 --- a/filters/tee/tee.go +++ b/filters/tee/tee.go @@ -13,9 +13,12 @@ import ( ) const ( - Name = "tee" + // Deprecated, use filters.TeeName instead + Name = filters.TeeName + // Deprecated, use filters.TeeName instead DeprecatedName = "Tee" - NoFollowName = "teenf" + // Deprecated, use filters.TeenfName instead + NoFollowName = filters.TeenfName ) const defaultTeeTimeout = time.Second @@ -250,12 +253,12 @@ func (spec *teeSpec) CreateFilter(config []interface{}) (filters.Filter, error) if len(config) == 3 { expr, ok := config[1].(string) if !ok { - return nil, fmt.Errorf("invalid filter config in %s, expecting regexp and string, got: %v", Name, config) + return nil, fmt.Errorf("invalid filter config in %s, expecting regexp and string, got: %v", filters.TeeName, config) } replacement, ok := config[2].(string) if !ok { - return nil, fmt.Errorf("invalid filter config in %s, expecting regexp and string, got: %v", Name, config) + return nil, fmt.Errorf("invalid filter config in %s, expecting regexp and string, got: %v", filters.TeeName, config) } rx, err := regexp.Compile(expr) @@ -278,7 +281,7 @@ func (spec *teeSpec) Name() string { return DeprecatedName } if spec.options.NoFollow { - return NoFollowName + return filters.TeenfName } - return Name + return filters.TeeName } diff --git a/filters/tee/teeloopback.go b/filters/tee/teeloopback.go index 1d086346ca..82da05c7b1 100644 --- a/filters/tee/teeloopback.go +++ b/filters/tee/teeloopback.go @@ -6,7 +6,9 @@ import ( teepredicate "github.com/zalando/skipper/predicates/tee" ) -const FilterName = "teeLoopback" +// FilterName is the filter name +// Deprecated, use filters.TeeLoopbackName instead +const FilterName = filters.TeeLoopbackName type teeLoopbackSpec struct{} type teeLoopbackFilter struct { @@ -14,7 +16,7 @@ type teeLoopbackFilter struct { } func (t *teeLoopbackSpec) Name() string { - return FilterName + return filters.TeeLoopbackName } func (t *teeLoopbackSpec) CreateFilter(args []interface{}) (filters.Filter, error) { diff --git a/filters/tracing/baggagetotag.go b/filters/tracing/baggagetotag.go index 459d28b554..c09f67f438 100644 --- a/filters/tracing/baggagetotag.go +++ b/filters/tracing/baggagetotag.go @@ -6,7 +6,8 @@ import ( ) const ( - BaggageToTagFilterName = "tracingBaggageToTag" + // Deprecated, use filters.TracingBaggageToTagName instead + BaggageToTagFilterName = filters.TracingBaggageToTagName ) type baggageToTagSpec struct{} @@ -17,7 +18,7 @@ type baggageToTagFilter struct { } func (baggageToTagSpec) Name() string { - return BaggageToTagFilterName + return filters.TracingBaggageToTagName } func (baggageToTagSpec) CreateFilter(args []interface{}) (filters.Filter, error) { diff --git a/filters/tracing/spanname.go b/filters/tracing/spanname.go index 60cb119e88..5c56fbd5a3 100644 --- a/filters/tracing/spanname.go +++ b/filters/tracing/spanname.go @@ -8,8 +8,8 @@ import ( ) const ( - // SpanNameFilterName is the name of the filter in eskip. - SpanNameFilterName = "tracingSpanName" + // Deprecated, use filters.TracingSpanNameName instead + SpanNameFilterName = filters.TracingSpanNameName // OpenTracingProxySpanKey is the key used in the state bag to pass the span name to the proxy. OpenTracingProxySpanKey = "statebag:opentracing:proxy:span" @@ -29,7 +29,7 @@ func NewSpanName() filters.Spec { return &spec{} } -func (s *spec) Name() string { return SpanNameFilterName } +func (s *spec) Name() string { return filters.TracingSpanNameName } func (s *spec) CreateFilter(args []interface{}) (filters.Filter, error) { if len(args) != 1 { diff --git a/filters/tracing/spanname_test.go b/filters/tracing/spanname_test.go index d537f8a124..df7ae8e90f 100644 --- a/filters/tracing/spanname_test.go +++ b/filters/tracing/spanname_test.go @@ -3,6 +3,7 @@ package tracing import ( "testing" + "github.com/zalando/skipper/filters" "github.com/zalando/skipper/filters/filtertest" ) @@ -41,7 +42,7 @@ func TestInvalid(t *testing.T) { } func TestBoring(t *testing.T) { s := NewSpanName().Name() - if s != SpanNameFilterName { + if s != filters.TracingSpanNameName { t.Fatalf("Wrong name") } } diff --git a/filters/tracing/statebagtotag.go b/filters/tracing/statebagtotag.go index 17b3828ad2..c96092e128 100644 --- a/filters/tracing/statebagtotag.go +++ b/filters/tracing/statebagtotag.go @@ -9,7 +9,8 @@ import ( ) const ( - StateBagToTagFilterName = "stateBagToTag" + // Deprecated, use filters.StateBagToTagName instead + StateBagToTagFilterName = filters.StateBagToTagName ) type stateBagToTagSpec struct{} @@ -20,7 +21,7 @@ type stateBagToTagFilter struct { } func (stateBagToTagSpec) Name() string { - return StateBagToTagFilterName + return filters.StateBagToTagName } func (stateBagToTagSpec) CreateFilter(args []interface{}) (filters.Filter, error) { diff --git a/filters/tracing/tag.go b/filters/tracing/tag.go index 681892e5e4..72672c682c 100644 --- a/filters/tracing/tag.go +++ b/filters/tracing/tag.go @@ -6,10 +6,6 @@ import ( "github.com/zalando/skipper/filters" ) -const ( - name = "tracingTag" -) - type tagSpec struct { } @@ -24,7 +20,7 @@ func NewTag() filters.Spec { } func (s tagSpec) Name() string { - return name + return filters.TracingTagName } func (s tagSpec) CreateFilter(args []interface{}) (filters.Filter, error) { diff --git a/filters/tracing/tag_test.go b/filters/tracing/tag_test.go index 52e897b949..e2743717a4 100644 --- a/filters/tracing/tag_test.go +++ b/filters/tracing/tag_test.go @@ -31,7 +31,7 @@ func TestTracingTagNil(t *testing.T) { } func TestTagName(t *testing.T) { - if (tagSpec{}).Name() != name { + if (tagSpec{}).Name() != filters.TracingTagName { t.Error("Wrong tag spec name") } } diff --git a/filters/xforward/xforward.go b/filters/xforward/xforward.go index d6323dbbcb..5fb179e60d 100644 --- a/filters/xforward/xforward.go +++ b/filters/xforward/xforward.go @@ -6,11 +6,11 @@ import ( ) const ( - // Name of the "xforward" filter. - Name = "xforward" + // Deprecated, use filters.XforwardName instead + Name = filters.XforwardName - // NameFirst is the name of the "xforwardFirst" filter. - NameFirst = "xforwardFirst" + // Deprecated, use filters.XforwardFirstName instead + NameFirst = filters.XforwardFirstName ) type filter struct { @@ -35,9 +35,9 @@ func NewFirst() filters.Spec { func (f filter) Name() string { if f.headers.PrependFor { - return NameFirst + return filters.XforwardFirstName } - return Name + return filters.XforwardName } func (f filter) CreateFilter([]interface{}) (filters.Filter, error) { diff --git a/predicates/auth/jwt.go b/predicates/auth/jwt.go index a56132724b..06e85c0c8a 100644 --- a/predicates/auth/jwt.go +++ b/predicates/auth/jwt.go @@ -41,11 +41,6 @@ type valueMatcher interface { } const ( - matchJWTPayloadAllKVName = "JWTPayloadAllKV" - matchJWTPayloadAnyKVName = "JWTPayloadAnyKV" - matchJWTPayloadAllKVRegexpName = "JWTPayloadAllKVRegexp" - matchJWTPayloadAnyKVRegexpName = "JWTPayloadAnyKVRegexp" - matchBehaviorAll matchBehavior = iota matchBehaviorAny @@ -73,7 +68,7 @@ type ( func NewJWTPayloadAnyKV() routing.PredicateSpec { return &spec{ - name: matchJWTPayloadAnyKVName, + name: predicates.JWTPayloadAnyKVName, matchBehavior: matchBehaviorAny, matchMode: matchModeExact, } @@ -81,7 +76,7 @@ func NewJWTPayloadAnyKV() routing.PredicateSpec { func NewJWTPayloadAllKV() routing.PredicateSpec { return &spec{ - name: matchJWTPayloadAllKVName, + name: predicates.JWTPayloadAllKVName, matchBehavior: matchBehaviorAll, matchMode: matchModeExact, } @@ -89,7 +84,7 @@ func NewJWTPayloadAllKV() routing.PredicateSpec { func NewJWTPayloadAnyKVRegexp() routing.PredicateSpec { return &spec{ - name: matchJWTPayloadAnyKVRegexpName, + name: predicates.JWTPayloadAnyKVRegexpName, matchBehavior: matchBehaviorAny, matchMode: matchModeRegexp, } @@ -97,7 +92,7 @@ func NewJWTPayloadAnyKVRegexp() routing.PredicateSpec { func NewJWTPayloadAllKVRegexp() routing.PredicateSpec { return &spec{ - name: matchJWTPayloadAllKVRegexpName, + name: predicates.JWTPayloadAllKVRegexpName, matchBehavior: matchBehaviorAll, matchMode: matchModeRegexp, } diff --git a/predicates/auth/jwt_test.go b/predicates/auth/jwt_test.go index e2c1b4e128..359bb592e9 100644 --- a/predicates/auth/jwt_test.go +++ b/predicates/auth/jwt_test.go @@ -7,6 +7,7 @@ import ( "testing" "github.com/stretchr/testify/require" + "github.com/zalando/skipper/predicates" "github.com/zalando/skipper/routing" ) @@ -17,19 +18,19 @@ func Test_spec(t *testing.T) { }{ { spec: NewJWTPayloadAllKV(), - name: matchJWTPayloadAllKVName, + name: predicates.JWTPayloadAllKVName, }, { spec: NewJWTPayloadAnyKV(), - name: matchJWTPayloadAnyKVName, + name: predicates.JWTPayloadAnyKVName, }, { spec: NewJWTPayloadAllKVRegexp(), - name: matchJWTPayloadAllKVRegexpName, + name: predicates.JWTPayloadAllKVRegexpName, }, { spec: NewJWTPayloadAnyKVRegexp(), - name: matchJWTPayloadAnyKVRegexpName, + name: predicates.JWTPayloadAnyKVRegexpName, }, } { t.Run(tc.name, func(t *testing.T) { diff --git a/predicates/cookie/cookie.go b/predicates/cookie/cookie.go index 47cfda77a1..734077d43e 100644 --- a/predicates/cookie/cookie.go +++ b/predicates/cookie/cookie.go @@ -12,7 +12,8 @@ import ( ) // Name the predicate can be referenced in eskip by the name "Cookie". -const Name = "Cookie" +// Deprecated, use predicates.CookieName instead +const Name = predicates.CookieName type ( spec struct{} @@ -34,7 +35,7 @@ type ( // func New() routing.PredicateSpec { return &spec{} } -func (s *spec) Name() string { return Name } +func (s *spec) Name() string { return predicates.CookieName } func (s *spec) Create(args []interface{}) (routing.Predicate, error) { if len(args) != 2 { diff --git a/predicates/cron/cron.go b/predicates/cron/cron.go index a8f8143893..76b73a37ac 100644 --- a/predicates/cron/cron.go +++ b/predicates/cron/cron.go @@ -24,7 +24,7 @@ type spec struct { } func (*spec) Name() string { - return "Cron" + return predicates.CronName } func (*spec) Create(args []interface{}) (routing.Predicate, error) { diff --git a/predicates/cron/cron_test.go b/predicates/cron/cron_test.go index a496fb890b..755c9c92d0 100644 --- a/predicates/cron/cron_test.go +++ b/predicates/cron/cron_test.go @@ -3,6 +3,8 @@ package cron import ( "testing" "time" + + "github.com/zalando/skipper/predicates" ) func TestCreate(t *testing.T) { @@ -50,7 +52,7 @@ func TestCreate(t *testing.T) { } func TestPredicateName(t *testing.T) { - if name := New().Name(); name != "Cron" { + if name := New().Name(); name != predicates.CronName { t.Errorf("predicate name does not match expecetation: %s", name) } } diff --git a/predicates/forwarded/forwarded.go b/predicates/forwarded/forwarded.go index c531235f33..5abecf0ff0 100644 --- a/predicates/forwarded/forwarded.go +++ b/predicates/forwarded/forwarded.go @@ -27,8 +27,10 @@ import ( ) const ( - NameHost = "ForwardedHost" - NameProto = "ForwardedProtocol" + // Deprecated, use predicates.ForwardedHostName instead + NameHost = predicates.ForwardedHostName + // Deprecated, use predicates.ForwardedProtocolName instead + NameProto = predicates.ForwardedProtocolName ) type hostPredicateSpec struct{} @@ -88,11 +90,11 @@ func NewForwardedHost() routing.PredicateSpec { return &hostPredicateSpec{} } func NewForwardedProto() routing.PredicateSpec { return &protoPredicateSpec{} } func (p *hostPredicateSpec) Name() string { - return NameHost + return predicates.ForwardedHostName } func (p *protoPredicateSpec) Name() string { - return NameProto + return predicates.ForwardedProtocolName } func (p hostPredicate) Match(r *http.Request) bool { diff --git a/predicates/interval/interval.go b/predicates/interval/interval.go index a526942103..96b3abc53d 100644 --- a/predicates/interval/interval.go +++ b/predicates/interval/interval.go @@ -75,11 +75,11 @@ func NewAfter() routing.PredicateSpec { return after } func (s spec) Name() string { switch s { case between: - return "Between" + return predicates.BetweenName case before: - return "Before" + return predicates.BeforeName case after: - return "After" + return predicates.AfterName default: panic("invalid interval predicate type") } diff --git a/predicates/interval/interval_test.go b/predicates/interval/interval_test.go index 192dbf2404..58df26b93c 100644 --- a/predicates/interval/interval_test.go +++ b/predicates/interval/interval_test.go @@ -233,7 +233,7 @@ func TestCreateAfter(t *testing.T) { } func TestMatchBetween(t *testing.T) { - reqeust := &http.Request{} + request := &http.Request{} cases := []struct { msg string @@ -329,7 +329,7 @@ func TestMatchBetween(t *testing.T) { betweenPredicate.getTime = c.getTime } - matches := betweenPredicate.Match(reqeust) + matches := betweenPredicate.Match(request) if matches != c.matches { t.Errorf("%q: Expected result - %t; Actual result - %t", c.msg, c.matches, matches) @@ -339,7 +339,7 @@ func TestMatchBetween(t *testing.T) { } func TestMatchBefore(t *testing.T) { - reqeust := &http.Request{} + request := &http.Request{} cases := []struct { msg string @@ -403,7 +403,7 @@ func TestMatchBefore(t *testing.T) { beforePredicate.getTime = c.getTime } - matches := beforePredicate.Match(reqeust) + matches := beforePredicate.Match(request) if matches != c.matches { t.Errorf("%q: Expected result - %t; Actual result - %t", c.msg, c.matches, matches) @@ -413,7 +413,7 @@ func TestMatchBefore(t *testing.T) { } func TestMatchAfter(t *testing.T) { - reqeust := &http.Request{} + request := &http.Request{} cases := []struct { msg string @@ -477,7 +477,7 @@ func TestMatchAfter(t *testing.T) { afterPredicate.getTime = c.getTime } - matches := afterPredicate.Match(reqeust) + matches := afterPredicate.Match(request) if matches != c.matches { t.Errorf("%q: Expected result - %t; Actual result - %t", c.msg, c.matches, matches) diff --git a/predicates/methods/methods.go b/predicates/methods/methods.go index cde1e88010..18a4914742 100644 --- a/predicates/methods/methods.go +++ b/predicates/methods/methods.go @@ -19,12 +19,16 @@ package methods import ( "errors" "fmt" - "github.com/zalando/skipper/routing" "net/http" "strings" + + "github.com/zalando/skipper/predicates" + "github.com/zalando/skipper/routing" ) -const Name = "Methods" +// Name is the predicate name +// Deprecated, use predicates.MethodsName instead +const Name = predicates.MethodsName var ErrInvalidArgumentsCount = errors.New("at least one method should be specified") var ErrInvalidArgumentType = errors.New("only string values are allowed") @@ -54,7 +58,7 @@ func New() routing.PredicateSpec { }} } -func (s *spec) Name() string { return Name } +func (s *spec) Name() string { return predicates.MethodsName } func (s *spec) Create(args []interface{}) (routing.Predicate, error) { if len(args) == 0 { diff --git a/predicates/predicates.go b/predicates/predicates.go index 052602f1aa..a9d475a2a8 100644 --- a/predicates/predicates.go +++ b/predicates/predicates.go @@ -4,3 +4,41 @@ import "errors" // ErrInvalidPredicateParameters is used in case of invalid predicate parameters. var ErrInvalidPredicateParameters = errors.New("invalid predicate parameters") + +// All Skipper Predicate names +const ( + // PathName represents the name of builtin path predicate. + // (See more details about the Path and PathSubtree predicates + // at https://godoc.org/github.com/zalando/skipper/eskip) + PathName = "Path" + // PathSubtreeName represents the name of the builtin path subtree predicate. + // (See more details about the Path and PathSubtree predicates + // at https://godoc.org/github.com/zalando/skipper/eskip) + PathSubtreeName = "PathSubtree" + PathRegexpName = "PathRegexp" + HostName = "Host" + ForwardedHostName = "ForwardedHost" + ForwardedProtocolName = "ForwardedProtocol" + WeightName = "Weight" + TrueName = "True" + FalseName = "False" + MethodName = "Method" + MethodsName = "Methods" + HeaderName = "Header" + HeaderRegexpName = "HeaderRegexp" + CookieName = "Cookie" + JWTPayloadAnyKVName = "JWTPayloadAnyKV" + JWTPayloadAllKVName = "JWTPayloadAllKV" + JWTPayloadAnyKVRegexpName = "JWTPayloadAnyKVRegexp" + JWTPayloadAllKVRegexpName = "JWTPayloadAllKVRegexp" + AfterName = "After" + BeforeName = "Before" + BetweenName = "Between" + CronName = "Cron" + QueryParamName = "QueryParam" + SourceName = "Source" + SourceFromLastName = "SourceFromLast" + ClientIPName = "ClientIP" + TeeName = "Tee" + TrafficName = "Traffic" +) diff --git a/predicates/primitive/false.go b/predicates/primitive/false.go index 178e5c571d..50af141c0b 100644 --- a/predicates/primitive/false.go +++ b/predicates/primitive/false.go @@ -3,11 +3,13 @@ package primitive import ( "net/http" + "github.com/zalando/skipper/predicates" "github.com/zalando/skipper/routing" ) const ( - NameFalse = "False" + // Deprecated, use predicates.FalseName instead + NameFalse = predicates.FalseName ) type falseSpec struct{} @@ -18,7 +20,7 @@ type falsePredicate struct{} func NewFalse() routing.PredicateSpec { return &falseSpec{} } func (*falseSpec) Name() string { - return NameFalse + return predicates.FalseName } // Create a predicate instance that always evaluates to false diff --git a/predicates/primitive/true.go b/predicates/primitive/true.go index 10a94b42b7..94e748afe7 100644 --- a/predicates/primitive/true.go +++ b/predicates/primitive/true.go @@ -3,11 +3,13 @@ package primitive import ( "net/http" + "github.com/zalando/skipper/predicates" "github.com/zalando/skipper/routing" ) const ( - NameTrue = "True" + // Deprecated, use predicates.TrueName instead + NameTrue = predicates.TrueName ) type trueSpec struct{} @@ -18,7 +20,7 @@ type truePredicate struct{} func NewTrue() routing.PredicateSpec { return &trueSpec{} } func (*trueSpec) Name() string { - return NameTrue + return predicates.TrueName } // Create a predicate instance that always evaluates to true diff --git a/predicates/query/query.go b/predicates/query/query.go index ab68635dd5..ec047f56ad 100644 --- a/predicates/query/query.go +++ b/predicates/query/query.go @@ -27,10 +27,11 @@ Examples: package query import ( - "github.com/zalando/skipper/predicates" - "github.com/zalando/skipper/routing" "net/http" "regexp" + + "github.com/zalando/skipper/predicates" + "github.com/zalando/skipper/routing" ) type matchType int @@ -47,13 +48,11 @@ type predicate struct { } type spec struct{} -const name = "QueryParam" - // New creates a new QueryParam predicate specification. func New() routing.PredicateSpec { return &spec{} } func (s *spec) Name() string { - return name + return predicates.QueryParamName } func (s *spec) Create(args []interface{}) (routing.Predicate, error) { diff --git a/predicates/source/source.go b/predicates/source/source.go index e82a5716d8..cff90e49df 100644 --- a/predicates/source/source.go +++ b/predicates/source/source.go @@ -45,13 +45,17 @@ import ( "net/http" snet "github.com/zalando/skipper/net" + "github.com/zalando/skipper/predicates" "github.com/zalando/skipper/routing" ) const ( - Name = "Source" - NameLast = "SourceFromLast" - NameClientIP = "ClientIP" + // Deprecated, use predicates.SourceName instead + Name = predicates.SourceName + // Deprecated, use predicates.SourceFromLastName instead + NameLast = predicates.SourceFromLastName + // Deprecated, use predicates.ClientIPName instead + NameClientIP = predicates.ClientIPName ) var InvalidArgsError = errors.New("invalid arguments") @@ -80,11 +84,11 @@ func NewClientIP() routing.PredicateSpec { return &spec{typ: clientIP} } func (s *spec) Name() string { switch s.typ { case sourceFromLast: - return NameLast + return predicates.SourceFromLastName case clientIP: - return NameClientIP + return predicates.ClientIPName default: - return Name + return predicates.SourceName } } diff --git a/predicates/source/source_test.go b/predicates/source/source_test.go index d58344e38e..f0a0a06dc2 100644 --- a/predicates/source/source_test.go +++ b/predicates/source/source_test.go @@ -3,17 +3,19 @@ package source import ( "net/http" "testing" + + "github.com/zalando/skipper/predicates" ) func TestName(t *testing.T) { - if s := New().Name(); s != Name { - t.Fatalf("Failed to get Name %s, got %s", Name, s) + if s := New().Name(); s != predicates.SourceName { + t.Fatalf("Failed to get Name %s, got %s", predicates.SourceName, s) } - if s := NewFromLast().Name(); s != NameLast { - t.Fatalf("Failed to get Name %s, got %s", NameLast, s) + if s := NewFromLast().Name(); s != predicates.SourceFromLastName { + t.Fatalf("Failed to get Name %s, got %s", predicates.SourceFromLastName, s) } - if s := NewClientIP().Name(); s != NameClientIP { - t.Fatalf("Failed to get Name %s, got %s", NameClientIP, s) + if s := NewClientIP().Name(); s != predicates.ClientIPName { + t.Fatalf("Failed to get Name %s, got %s", predicates.ClientIPName, s) } } diff --git a/predicates/tee/tee.go b/predicates/tee/tee.go index 73b52dc5f8..d1f338b92f 100644 --- a/predicates/tee/tee.go +++ b/predicates/tee/tee.go @@ -1,15 +1,17 @@ package tee import ( + "net/http" + "github.com/zalando/skipper/predicates" "github.com/zalando/skipper/routing" - "net/http" ) const ( - // The eskip name of the predicate. - PredicateName = "Tee" - HeaderKey = "x-tee-loopback-key" + // Deprecated, use predicates.TeeName instead + PredicateName = predicates.TeeName + + HeaderKey = "x-tee-loopback-key" ) type spec struct{} @@ -20,7 +22,7 @@ type predicate struct { func New() routing.PredicateSpec { return &spec{} } -func (s *spec) Name() string { return PredicateName } +func (s *spec) Name() string { return predicates.TeeName } func (s *spec) Create(args []interface{}) (routing.Predicate, error) { if len(args) != 1 { diff --git a/predicates/traffic/traffic.go b/predicates/traffic/traffic.go index d21f201d2c..8bfb1a66ab 100644 --- a/predicates/traffic/traffic.go +++ b/predicates/traffic/traffic.go @@ -78,8 +78,8 @@ import ( ) const ( - // The eskip name of the predicate. - PredicateName = "Traffic" + // Deprecated, use predicates.TrafficName instead + PredicateName = predicates.TrafficName ) type spec struct{} @@ -93,7 +93,7 @@ type predicate struct { // Creates a new traffic control predicate specification. func New() routing.PredicateSpec { return &spec{} } -func (s *spec) Name() string { return PredicateName } +func (s *spec) Name() string { return predicates.TrafficName } func (s *spec) Create(args []interface{}) (routing.Predicate, error) { if !(len(args) == 1 || len(args) == 3) { diff --git a/proxy/breaker_test.go b/proxy/breaker_test.go index 1b0f0a63b5..7e2669289d 100644 --- a/proxy/breaker_test.go +++ b/proxy/breaker_test.go @@ -12,8 +12,8 @@ import ( "github.com/zalando/skipper/circuit" "github.com/zalando/skipper/eskip" + "github.com/zalando/skipper/filters" "github.com/zalando/skipper/filters/builtin" - circuitfilters "github.com/zalando/skipper/filters/circuit" "github.com/zalando/skipper/proxy" "github.com/zalando/skipper/proxy/proxytest" ) @@ -569,10 +569,10 @@ func TestBreakerMultipleHostsAndRouteBasedSettings(t *testing.T) { }}, filters: map[string][]*eskip.Filter{ "foo": {{ - Name: circuitfilters.DisableBreakerName, + Name: filters.DisableBreakerName, }}, "bar": {{ - Name: circuitfilters.RateBreakerName, + Name: filters.RateBreakerName, Args: []interface{}{ testRateFailures, testRateWindow, diff --git a/proxy/fadeintesting_test.go b/proxy/fadeintesting_test.go index 61692e20fe..cc6b3073b7 100644 --- a/proxy/fadeintesting_test.go +++ b/proxy/fadeintesting_test.go @@ -138,7 +138,7 @@ func (b *fadeInBackend) route() *eskip.Route { if b.withFadeIn { r.Filters = append(r.Filters, &eskip.Filter{ - Name: fadein.FadeInName, + Name: filters.FadeInName, Args: []interface{}{testFadeInDuration}, }) } @@ -147,7 +147,7 @@ func (b *fadeInBackend) route() *eskip.Route { r.LBEndpoints = append(r.LBEndpoints, i.server.URL) if !i.created.IsZero() { r.Filters = append(r.Filters, &eskip.Filter{ - Name: fadein.EndpointCreatedName, + Name: filters.EndpointCreatedName, Args: []interface{}{ i.server.URL, i.created, diff --git a/ratelimit/ratelimit.go b/ratelimit/ratelimit.go index e3e28d13c0..195fe450d6 100644 --- a/ratelimit/ratelimit.go +++ b/ratelimit/ratelimit.go @@ -12,6 +12,7 @@ import ( log "github.com/sirupsen/logrus" circularbuffer "github.com/szuecs/rate-limit-buffer" + "github.com/zalando/skipper/filters" "github.com/zalando/skipper/net" ) @@ -23,26 +24,26 @@ const ( // long a client should wait before making a new request RetryAfterHeader = "Retry-After" - // ServiceRatelimitName is the name of the Ratelimit filter, which will be shown in log - ServiceRatelimitName = "ratelimit" + // Deprecated, use filters.RatelimitName instead + ServiceRatelimitName = filters.RatelimitName // LocalRatelimitName *DEPRECATED*, use ClientRatelimitName instead LocalRatelimitName = "localRatelimit" - // ClientRatelimitName is the name of the ClientRatelimit filter, which will be shown in log - ClientRatelimitName = "clientRatelimit" + // Deprecated, use filters.ClientRatelimitName instead + ClientRatelimitName = filters.ClientRatelimitName - // ClusterServiceRatelimitName is the name of the ClusterServiceRatelimit filter, which will be shown in log - ClusterServiceRatelimitName = "clusterRatelimit" + // Deprecated, use filters.ClusterRatelimitName instead + ClusterServiceRatelimitName = filters.ClusterRatelimitName - // ClusterClientRatelimitName is the name of the ClusterClientRatelimit filter, which will be shown in log - ClusterClientRatelimitName = "clusterClientRatelimit" + // Deprecated, use filters.ClusterClientRatelimitName instead + ClusterClientRatelimitName = filters.ClusterClientRatelimitName - // DisableRatelimitName is the name of the DisableRatelimit, which will be shown in log - DisableRatelimitName = "disableRatelimit" + // Deprecated, use filters.DisableRatelimitName instead + DisableRatelimitName = filters.DisableRatelimitName - // UknownRatelimitName is to print unknown ratelimit settings in error messages - UknownRatelimitName = "unknownRatelimit" + // Deprecated, use filters.UnknownRatelimitName instead + UknownRatelimitName = filters.UnknownRatelimitName ) // RatelimitType defines the type of the used ratelimit @@ -129,19 +130,19 @@ const ( func (rt RatelimitType) String() string { switch rt { case DisableRatelimit: - return DisableRatelimitName + return filters.DisableRatelimitName case ClientRatelimit: - return ClientRatelimitName + return filters.ClientRatelimitName case ClusterClientRatelimit: - return ClusterClientRatelimitName + return filters.ClusterClientRatelimitName case ClusterServiceRatelimit: - return ClusterServiceRatelimitName + return filters.ClusterRatelimitName case LocalRatelimit: return LocalRatelimitName case ServiceRatelimit: - return ServiceRatelimitName + return filters.RatelimitName default: - return UknownRatelimitName + return filters.UnknownRatelimitName } diff --git a/routing/datasource.go b/routing/datasource.go index c821dee4e6..a1af30708d 100644 --- a/routing/datasource.go +++ b/routing/datasource.go @@ -20,15 +20,6 @@ const ( incomingUpdate ) -// legacy, non-tree predicate names: -const ( - hostRegexpName = "Host" - pathRegexpName = "PathRegexp" - methodName = "Method" - headerName = "Header" - headerRegexpName = "HeaderRegexp" -) - var errInvalidWeightParams = errors.New("invalid argument for the Weight predicate") func (it incomingType) String() string { @@ -220,7 +211,7 @@ func splitBackend(r *eskip.Route) (string, string, error) { func createFilter(fr filters.Registry, def *eskip.Filter, cpm map[string]PredicateSpec) (filters.Filter, error) { spec, ok := fr[def.Name] if !ok { - if isTreePredicate(def.Name) || def.Name == hostRegexpName || def.Name == pathRegexpName || def.Name == methodName || def.Name == headerName || def.Name == headerRegexpName { + if isTreePredicate(def.Name) || def.Name == predicates.HostName || def.Name == predicates.PathRegexpName || def.Name == predicates.MethodName || def.Name == predicates.HeaderName || def.Name == predicates.HeaderRegexpName { return nil, fmt.Errorf("trying to use '%s' as filter, but it is only available as predicate", def.Name) } @@ -252,9 +243,9 @@ func createFilters(fr filters.Registry, defs []*eskip.Filter, cpm map[string]Pre // check if a predicate is a distinguished, path tree predicate func isTreePredicate(name string) bool { switch name { - case PathSubtreeName: + case predicates.PathSubtreeName: return true - case PathName: + case predicates.PathName: return true default: return false @@ -295,28 +286,28 @@ func mergeLegacyNonTreePredicates(r *eskip.Route) (*eskip.Route, error) { } switch p.Name { - case hostRegexpName: + case predicates.HostName: a, err := getFreeStringArgs(1, p) if err != nil { return nil, err } c.HostRegexps = append(c.HostRegexps, a[0]) - case pathRegexpName: + case predicates.PathRegexpName: a, err := getFreeStringArgs(1, p) if err != nil { return nil, err } c.PathRegexps = append(c.PathRegexps, a[0]) - case methodName: + case predicates.MethodName: a, err := getFreeStringArgs(1, p) if err != nil { return nil, err } c.Method = a[0] - case headerName: + case predicates.HeaderName: a, err := getFreeStringArgs(2, p) if err != nil { return nil, err @@ -327,7 +318,7 @@ func mergeLegacyNonTreePredicates(r *eskip.Route) (*eskip.Route, error) { } c.Headers[a[0]] = a[1] - case headerRegexpName: + case predicates.HeaderRegexpName: a, err := getFreeStringArgs(2, p) if err != nil { return nil, err @@ -410,11 +401,11 @@ func processPathOrSubTree(p *eskip.Predicate) (string, error) { return "", predicates.ErrInvalidPredicateParameters } -func validTreePredicates(predicates []*eskip.Predicate) bool { +func validTreePredicates(predicateList []*eskip.Predicate) bool { var has bool - for _, p := range predicates { + for _, p := range predicateList { switch p.Name { - case PathName, PathSubtreeName: + case predicates.PathName, predicates.PathSubtreeName: if has { return false } @@ -425,25 +416,25 @@ func validTreePredicates(predicates []*eskip.Predicate) bool { } // processes path tree relevant predicates -func processTreePredicates(r *Route, predicates []*eskip.Predicate) error { +func processTreePredicates(r *Route, predicateList []*eskip.Predicate) error { // backwards compatibility if r.Path != "" { - predicates = append(predicates, &eskip.Predicate{Name: PathName, Args: []interface{}{r.Path}}) + predicateList = append(predicateList, &eskip.Predicate{Name: predicates.PathName, Args: []interface{}{r.Path}}) } - if !validTreePredicates(predicates) { + if !validTreePredicates(predicateList) { return fmt.Errorf("multiple tree predicates (Path, PathSubtree) in the route: %s", r.Id) } - for _, p := range predicates { + for _, p := range predicateList { switch p.Name { - case PathName: + case predicates.PathName: path, err := processPathOrSubTree(p) if err != nil { return err } r.path = path - case PathSubtreeName: + case predicates.PathSubtreeName: pst, err := processPathOrSubTree(p) if err != nil { return err diff --git a/routing/routing.go b/routing/routing.go index fe4550b276..e74b4ee80a 100644 --- a/routing/routing.go +++ b/routing/routing.go @@ -12,20 +12,18 @@ import ( "github.com/zalando/skipper/eskip" "github.com/zalando/skipper/filters" "github.com/zalando/skipper/logging" + "github.com/zalando/skipper/predicates" ) const ( - // PathName represents the name of builtin path predicate. - // (See more details about the Path and PathSubtree predicates - // at https://godoc.org/github.com/zalando/skipper/eskip) - PathName = "Path" + // Deprecated, use predicates.PathName instead + PathName = predicates.PathName - // PathSubtreeName represents the name of the builtin path subtree predicate. - // (See more details about the Path and PathSubtree predicates - // at https://godoc.org/github.com/zalando/skipper/eskip) - PathSubtreeName = "PathSubtree" + // Deprecated, use predicates.PathSubtreeName instead + PathSubtreeName = predicates.PathSubtreeName - WeightPredicateName = "Weight" + // Deprecated, use predicates.WeightName instead + WeightPredicateName = predicates.WeightName routesTimestampName = "X-Timestamp" routesCountName = "X-Count" diff --git a/script/script.go b/script/script.go index acac1b92fd..bfa48008a8 100644 --- a/script/script.go +++ b/script/script.go @@ -40,7 +40,7 @@ func NewLuaScript() filters.Spec { // Name returns the name of the filter ("lua") func (ls *luaScript) Name() string { - return "lua" + return filters.LuaName } // CreateFilter creates the filter