Skip to content

Skipper as code route helpers temp #1683

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Draft
wants to merge 14 commits into
base: master
Choose a base branch
from
Draft
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
7 changes: 4 additions & 3 deletions _test_plugins/multitype_noop.go
Original file line number Diff line number Diff line change
@@ -1,6 +1,7 @@
package main

import (
"github.com/zalando/skipper/predicates"
"net/http"

"github.com/zalando/skipper/filters"
Expand All @@ -11,8 +12,8 @@ type multiSpec struct {
Type string
}

func InitPlugin(opts []string) ([]filters.Spec, []routing.PredicateSpec, []routing.DataClient, error) {
return []filters.Spec{multiSpec{"noop"}}, []routing.PredicateSpec{multiSpec{"None"}}, nil, nil
func InitPlugin(opts []string) ([]filters.Spec, []predicates.PredicateSpec, []routing.DataClient, error) {
return []filters.Spec{multiSpec{"noop"}}, []predicates.PredicateSpec{multiSpec{"None"}}, nil, nil
}

func (s multiSpec) Name() string {
Expand All @@ -23,7 +24,7 @@ func (s multiSpec) CreateFilter(config []interface{}) (filters.Filter, error) {
return noop{}, nil
}

func (s multiSpec) Create(config []interface{}) (routing.Predicate, error) {
func (s multiSpec) Create(config []interface{}) (predicates.Predicate, error) {
return noop{}, nil
}

Expand Down
7 changes: 3 additions & 4 deletions _test_plugins/predicate_match_none.go
Original file line number Diff line number Diff line change
@@ -1,21 +1,20 @@
package main

import (
"github.com/zalando/skipper/predicates"
"net/http"

"github.com/zalando/skipper/routing"
)

type noneSpec struct{}

func InitPredicate(opts []string) (routing.PredicateSpec, error) {
func InitPredicate(opts []string) (predicates.PredicateSpec, error) {
return noneSpec{}, nil
}

func (s noneSpec) Name() string {
return "None"
}
func (s noneSpec) Create(config []interface{}) (routing.Predicate, error) {
func (s noneSpec) Create(config []interface{}) (predicates.Predicate, error) {
return nonePredicate{}, nil
}

Expand Down
6 changes: 3 additions & 3 deletions _test_plugins_fail/fail.go
Original file line number Diff line number Diff line change
@@ -1,10 +1,10 @@
package main

import (
"github.com/zalando/skipper/predicates"
"net/http"

"github.com/zalando/skipper/filters"
"github.com/zalando/skipper/routing"
)

// this fails to load, because it implements multiple Init* functions
Expand All @@ -13,7 +13,7 @@ func InitFilter(opts []string) (filters.Spec, error) {
return noopSpec{}, nil
}

func InitPredicate(opts []string) (routing.PredicateSpec, error) {
func InitPredicate(opts []string) (predicates.PredicateSpec, error) {
return noneSpec{}, nil
}

Expand All @@ -36,7 +36,7 @@ type noneSpec struct{}
func (s noneSpec) Name() string {
return "None"
}
func (s noneSpec) Create(config []interface{}) (routing.Predicate, error) {
func (s noneSpec) Create(config []interface{}) (predicates.Predicate, error) {
return nonePredicate{}, nil
}

Expand Down
7 changes: 3 additions & 4 deletions dataclients/kubernetes/ingress.go
Original file line number Diff line number Diff line change
Expand Up @@ -3,15 +3,14 @@ package kubernetes
import (
"encoding/json"
"fmt"
"github.com/zalando/skipper/predicates"
"regexp"
"strconv"
"strings"

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"
)

const (
Expand Down Expand Up @@ -228,14 +227,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...)
}
Expand Down
6 changes: 3 additions & 3 deletions dataclients/kubernetes/kube.go
Original file line number Diff line number Diff line change
Expand Up @@ -2,6 +2,7 @@ package kubernetes

import (
"fmt"
"github.com/zalando/skipper/predicates"
"net"
"net/http"
"os"
Expand All @@ -15,7 +16,6 @@ import (
"github.com/zalando/skipper/eskip"
"github.com/zalando/skipper/filters/accesslog"
"github.com/zalando/skipper/filters/builtin"
"github.com/zalando/skipper/predicates/source"
)

const (
Expand Down Expand Up @@ -367,12 +367,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,
}}
}
Expand Down
6 changes: 3 additions & 3 deletions dataclients/kubernetes/kube_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -9,6 +9,7 @@ import (
"encoding/json"
"encoding/pem"
"fmt"
"github.com/zalando/skipper/predicates"
"io"
"io/ioutil"
"math/big"
Expand All @@ -34,7 +35,6 @@ 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"
)

type testAPI struct {
Expand Down Expand Up @@ -367,10 +367,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
}

Expand Down
6 changes: 3 additions & 3 deletions dataclients/kubernetes/redirect.go
Original file line number Diff line number Diff line change
Expand Up @@ -2,13 +2,13 @@ package kubernetes

import (
"fmt"
"github.com/zalando/skipper/predicates"
"net/http"
"strconv"

log "github.com/sirupsen/logrus"
"github.com/zalando/skipper/dataclients/kubernetes/definitions"
"github.com/zalando/skipper/eskip"
"github.com/zalando/skipper/routing"
)

const (
Expand Down Expand Up @@ -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...)

Expand All @@ -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...)
}
Expand Down
17 changes: 11 additions & 6 deletions docs/reference/filters.md
Original file line number Diff line number Diff line change
Expand Up @@ -961,7 +961,7 @@ token, it will allow the request to pass.
Examples:

```
oauthTokenintrospectionAnyClaims("c1", "c2", "c3")
oauthTokenintrospectionAnyClaims("https://accounts.google.com", c1", "c2", "c3")
```

## oauthTokenintrospectionAllClaims
Expand All @@ -980,7 +980,7 @@ token, it will allow the request to pass.
Examples:

```
oauthTokenintrospectionAllClaims("c1", "c2", "c3")
oauthTokenintrospectionAllClaims("https://accounts.google.com", c1", "c2", "c3")
```

## oauthTokenintrospectionAnyKV
Expand All @@ -1000,8 +1000,8 @@ it will allow the request to pass.
Examples:

```
oauthTokenintrospectionAnyKV("k1", "v1", "k2", "v2")
oauthTokenintrospectionAnyKV("k1", "v1", "k1", "v2")
oauthTokenintrospectionAnyKV("https://accounts.google.com", "k1", "v1", "k2", "v2")
oauthTokenintrospectionAnyKV("https://accounts.google.com", "k1", "v1", "k1", "v2")
```

## oauthTokenintrospectionAllKV
Expand All @@ -1021,7 +1021,7 @@ it will allow the request to pass.
Examples:

```
oauthTokenintrospectionAllKV("k1", "v1", "k2", "v2")
oauthTokenintrospectionAllKV("https://accounts.google.com", "k1", "v1", "k2", "v2")
```

## secureOauthTokenintrospectionAnyClaims
Expand All @@ -1033,6 +1033,7 @@ for example `https://accounts.google.com`, that will be used as
described in [RFC Draft](https://tools.ietf.org/html/draft-ietf-oauth-discovery-06#section-5)
to find the configuration and for example supported claims.

Second and third arguments are the client-id and client-secret.
Use this filter if the Token Introspection endpoint requires authorization to validate and decode the incoming token.
The filter will optionally read client-id and client-secret from environment variables: OAUTH_CLIENT_ID, OAUTH_CLIENT_SECRET

Expand Down Expand Up @@ -1060,6 +1061,7 @@ for example `https://accounts.google.com`, that will be used as
described in [RFC Draft](https://tools.ietf.org/html/draft-ietf-oauth-discovery-06#section-5)
to find the configuration and for example supported claims.

Second and third arguments are the client-id and client-secret.
Use this filter if the Token Introspection endpoint requires authorization to validate and decode the incoming token.
The filter will optionally read client-id and client-secret from environment variables: OAUTH_CLIENT_ID, OAUTH_CLIENT_SECRET

Expand Down Expand Up @@ -1088,6 +1090,7 @@ that will be used as described in
[RFC Draft](https://tools.ietf.org/html/draft-ietf-oauth-discovery-06#section-5)
to find the configuration and for example supported claims.

Second and third arguments are the client-id and client-secret.
Use this filter if the Token Introspection endpoint requires authorization to validate and decode the incoming token.
The filter will optionally read client-id and client-secret from environment variables: OAUTH_CLIENT_ID, OAUTH_CLIENT_SECRET

Expand Down Expand Up @@ -1116,6 +1119,7 @@ that will be used as described in
[RFC Draft](https://tools.ietf.org/html/draft-ietf-oauth-discovery-06#section-5)
to find the configuration and for example supported claims.

Second and third arguments are the client-id and client-secret.
Use this filter if the Token Introspection endpoint requires authorization to validate and decode the incoming token.
The filter will optionally read client-id and client-secret from environment variables: OAUTH_CLIENT_ID, OAUTH_CLIENT_SECRET

Expand Down Expand Up @@ -1441,7 +1445,8 @@ and allows the same breaker characteristics for low and high rate traffic.
Parameters:

* number of consecutive failures to open (int)
* sliding window (time string, parseable by [time.Duration](https://godoc.org/time#ParseDuration))
* sliding window (int)
* timeout (time string, parseable by [time.Duration](https://godoc.org/time#ParseDuration)) - optional
* half-open requests (int) - optional
* idle-ttl (time string, parseable by [time.Duration](https://godoc.org/time#ParseDuration)) - optional

Expand Down
2 changes: 1 addition & 1 deletion filters/apiusagemonitoring/filter.go
Original file line number Diff line number Diff line change
Expand Up @@ -24,7 +24,7 @@ const (
)

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

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

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

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

const (
Name = "apiUsageMonitoring"
ApiUsageMonitoringName = "apiUsageMonitoring"

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

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

Expand All @@ -47,7 +47,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.", ApiUsageMonitoringName)
return &noopSpec{&noopFilter{}}
}

Expand Down Expand Up @@ -104,8 +104,8 @@ func NewApiUsageMonitoring(
return spec
}

// apiConfig is the structure used to parse the parameters of the filter.
type apiConfig struct {
// ApiConfig is the structure used to parse the parameters of the filter.
type ApiConfig struct {
ApplicationId string `json:"application_id"`
Tag string `json:"tag"`
ApiId string `json:"api_id"`
Expand All @@ -122,7 +122,7 @@ type apiUsageMonitoringSpec struct {
}

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

func (s *apiUsageMonitoringSpec) CreateFilter(args []interface{}) (filter filters.Filter, err error) {
Expand All @@ -143,15 +143,15 @@ func (s *apiUsageMonitoringSpec) CreateFilter(args []interface{}) (filter filter
return
}

func (s *apiUsageMonitoringSpec) parseJsonConfiguration(args []interface{}) []*apiConfig {
apis := make([]*apiConfig, 0, len(args))
func (s *apiUsageMonitoringSpec) parseJsonConfiguration(args []interface{}) []*ApiConfig {
apis := make([]*ApiConfig, 0, len(args))
for i, a := range args {
rawJsonConfiguration, ok := a.(string)
if !ok {
log.Errorf("args[%d] ignored: expecting a string, was %t", i, a)
continue
}
config := &apiConfig{
config := &ApiConfig{
ClientTrackingPattern: ".*", // track all clients per default
}
decoder := json.NewDecoder(strings.NewReader(rawJsonConfiguration))
Expand Down Expand Up @@ -186,7 +186,7 @@ func (s *apiUsageMonitoringSpec) buildUnknownPathInfo(paths []*pathInfo) *pathIn
return s.unknownPath
}

func (s *apiUsageMonitoringSpec) buildPathInfoListFromConfiguration(apis []*apiConfig) []*pathInfo {
func (s *apiUsageMonitoringSpec) buildPathInfoListFromConfiguration(apis []*ApiConfig) []*pathInfo {
var paths []*pathInfo
existingPathTemplates := make(map[string]*pathInfo)
existingPathPattern := make(map[string]*pathInfo)
Expand Down Expand Up @@ -271,7 +271,7 @@ func (s *apiUsageMonitoringSpec) buildPathInfoListFromConfiguration(apis []*apiC
return paths
}

func (s *apiUsageMonitoringSpec) buildClientTrackingInfo(apiIndex int, api *apiConfig, realmsTrackingMatcher *regexp.Regexp) *clientTrackingInfo {
func (s *apiUsageMonitoringSpec) buildClientTrackingInfo(apiIndex int, api *ApiConfig, realmsTrackingMatcher *regexp.Regexp) *clientTrackingInfo {
if len(s.realmKeys) == 0 {
log.Infof(
`args[%d]: skipper wide configuration "api-usage-monitoring-realm-keys" not provided, not tracking client metrics`,
Expand Down
Loading