Skip to content

Commit

Permalink
Rename paths to rules (#36)
Browse files Browse the repository at this point in the history
  • Loading branch information
strekm authored Sep 12, 2019
1 parent 6029e49 commit 33c9ca4
Show file tree
Hide file tree
Showing 19 changed files with 124 additions and 127 deletions.
10 changes: 5 additions & 5 deletions api/v2alpha1/gate_types.go
Original file line number Diff line number Diff line change
Expand Up @@ -49,9 +49,7 @@ type GateSpec struct {
// +kubebuilder:validation:Pattern=^(?:[_a-z0-9](?:[_a-z0-9-]+[a-z0-9])?\.)+(?:[a-z](?:[a-z0-9-]+[a-z0-9])?)?$
Gateway *string `json:"gateway"`
//Paths represents collection of Path to secure
Paths []Path `json:"paths,omitempty"`
// Mutators to be used
Mutators []*rulev1alpha1.Mutator `json:"mutators,omitempty"`
Rules []Rule `json:"rules,omitempty"`
}

// GateStatus defines the observed state of Gate
Expand Down Expand Up @@ -112,15 +110,17 @@ type AuthStrategy struct {
Config *runtime.RawExtension `json:"config,omitempty"`
}

//Path .
type Path struct {
//Rule .
type Rule struct {
// Path to be exposed
// +kubebuilder:validation:Pattern=^/([0-9a-zA-Z./*]+)
Path string `json:"path"`
// Set of allowed scopes
Scopes []string `json:"scopes,omitempty"`
// Set of allowed HTTP methods
Methods []string `json:"methods,omitempty"`
// Mutators to be used
Mutators []*rulev1alpha1.Mutator `json:"mutators,omitempty"`
}

//GatewayResourceStatus .
Expand Down
36 changes: 18 additions & 18 deletions api/v2alpha1/zz_generated.deepcopy.go
Original file line number Diff line number Diff line change
Expand Up @@ -127,24 +127,13 @@ func (in *GateSpec) DeepCopyInto(out *GateSpec) {
*out = new(string)
**out = **in
}
if in.Paths != nil {
in, out := &in.Paths, &out.Paths
*out = make([]Path, len(*in))
if in.Rules != nil {
in, out := &in.Rules, &out.Rules
*out = make([]Rule, len(*in))
for i := range *in {
(*in)[i].DeepCopyInto(&(*out)[i])
}
}
if in.Mutators != nil {
in, out := &in.Mutators, &out.Mutators
*out = make([]*v1alpha1.Mutator, len(*in))
for i := range *in {
if (*in)[i] != nil {
in, out := &(*in)[i], &(*out)[i]
*out = new(v1alpha1.Mutator)
(*in).DeepCopyInto(*out)
}
}
}
}

// DeepCopy is an autogenerated deepcopy function, copying the receiver, creating a new GateSpec.
Expand Down Expand Up @@ -315,7 +304,7 @@ func (in *OauthModeConfig) DeepCopy() *OauthModeConfig {
}

// DeepCopyInto is an autogenerated deepcopy function, copying the receiver, writing into out. in must be non-nil.
func (in *Path) DeepCopyInto(out *Path) {
func (in *Rule) DeepCopyInto(out *Rule) {
*out = *in
if in.Scopes != nil {
in, out := &in.Scopes, &out.Scopes
Expand All @@ -327,14 +316,25 @@ func (in *Path) DeepCopyInto(out *Path) {
*out = make([]string, len(*in))
copy(*out, *in)
}
if in.Mutators != nil {
in, out := &in.Mutators, &out.Mutators
*out = make([]*v1alpha1.Mutator, len(*in))
for i := range *in {
if (*in)[i] != nil {
in, out := &(*in)[i], &(*out)[i]
*out = new(v1alpha1.Mutator)
(*in).DeepCopyInto(*out)
}
}
}
}

// DeepCopy is an autogenerated deepcopy function, copying the receiver, creating a new Path.
func (in *Path) DeepCopy() *Path {
// DeepCopy is an autogenerated deepcopy function, copying the receiver, creating a new Rule.
func (in *Rule) DeepCopy() *Rule {
if in == nil {
return nil
}
out := new(Path)
out := new(Rule)
in.DeepCopyInto(out)
return out
}
Expand Down
32 changes: 16 additions & 16 deletions config/crd/bases/gateway.kyma-project.io_gates.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -407,22 +407,7 @@ spec:
description: Gateway to be used
pattern: ^(?:[_a-z0-9](?:[_a-z0-9-]+[a-z0-9])?\.)+(?:[a-z](?:[a-z0-9-]+[a-z0-9])?)?$
type: string
mutators:
description: Mutators to be used
items:
properties:
config:
description: Config configures the handler. Configuration keys
vary per handler.
type: object
handler:
description: Name is the name of a handler
type: string
required:
- handler
type: object
type: array
paths:
rules:
description: Paths represents collection of Path to secure
items:
properties:
Expand All @@ -431,6 +416,21 @@ spec:
items:
type: string
type: array
mutators:
description: Mutators to be used
items:
properties:
config:
description: Config configures the handler. Configuration
keys vary per handler.
type: object
handler:
description: Name is the name of a handler
type: string
required:
- handler
type: object
type: array
path:
description: Path to be exposed
pattern: ^/([0-9a-zA-Z./*]+)
Expand Down
11 changes: 4 additions & 7 deletions config/samples/invalid.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -37,8 +37,7 @@ spec:
port: 8000
auth:
name: OAUTH
paths: []
mutators: []
rules: []
---
apiVersion: gateway.kyma-project.io/v2alpha1
kind: Gate
Expand All @@ -52,14 +51,13 @@ spec:
port: 8000
auth:
name: OAUTH
paths:
rules:
- path: /foo
scopes: ["read"]
methods: ["GET"]
- path: /bar
scopes: ["read"]
methods: ["GET"]
mutators: []
---
apiVersion: gateway.kyma-project.io/v2alpha1
kind: Gate
Expand All @@ -76,11 +74,10 @@ spec:
config:
issuer: not-a-valid-url
jwks: []
paths:
rules:
- path: /.*
scopes: ["foo", "bar"]
methods: ["GET"]
mutators: []
---
apiVersion: gateway.kyma-project.io/v2alpha1
kind: Gate
Expand All @@ -107,7 +104,7 @@ spec:
auth:
name: ALLOW
gateway: kyma-gateway.kyma-system.svc.cluster.local
paths:
rules:
- path: /.*
scopes: ["foo", "bar"]
methods: ["GET"]
36 changes: 18 additions & 18 deletions config/samples/valid.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -11,11 +11,11 @@ spec:
auth:
name: ALLOW
gateway: kyma-gateway.kyma-system.svc.cluster.local
paths:
rules:
- path: /.*
scopes: []
methods: ["GET"]
mutators: []
mutators: []
---
apiVersion: gateway.kyma-project.io/v2alpha1
kind: Gate
Expand All @@ -29,11 +29,11 @@ spec:
auth:
name: ALLOW
gateway: kyma-gateway.kyma-system.svc.cluster.local
paths:
rules:
- path: /.*
methods: ["GET"]
mutators:
- handler: noop
mutators:
- handler: noop
---
apiVersion: gateway.kyma-project.io/v2alpha1
kind: Gate
Expand All @@ -50,11 +50,11 @@ spec:
config:
issuer: http://dex.kyma.local
jwks: []
paths:
rules:
- path: /.*
scopes: []
methods: ["GET"]
mutators: []
mutators: []
---
apiVersion: gateway.kyma-project.io/v2alpha1
kind: Gate
Expand All @@ -71,12 +71,12 @@ spec:
config:
issuer: http://dex.kyma.local
jwks: []
paths:
rules:
- path: /.*
scopes: ["foo", "bar"]
methods: ["GET"]
mutators:
- handler: noop
mutators:
- handler: noop
---
apiVersion: gateway.kyma-project.io/v2alpha1
kind: Gate
Expand All @@ -93,11 +93,11 @@ spec:
config:
issuer: http://dex.kyma.local
jwks: []
paths:
rules:
- path: /.*
scopes: ["foo", "bar"]
methods: ["GET"]
mutators: []
mutators: []
---
apiVersion: gateway.kyma-project.io/v2alpha1
kind: Gate
Expand All @@ -111,11 +111,11 @@ spec:
port: 8000
auth:
name: OAUTH
paths:
rules:
- path: /.*
scopes: ["read"]
methods: ["GET"]
mutators: []
mutators: []
---
apiVersion: gateway.kyma-project.io/v2alpha1
kind: Gate
Expand All @@ -129,10 +129,10 @@ spec:
port: 8000
auth:
name: OAUTH
paths:
rules:
- path: /.*
scopes: ["read"]
methods: ["GET"]
mutators:
- handler: noop
config: {}
mutators:
- handler: noop
config: {}
10 changes: 5 additions & 5 deletions controllers/api_controller_integration_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -363,14 +363,14 @@ func testInstance(authStrategyName, configJSON, name, namespace, serviceName, se
Name: &authStrategyName,
Config: rawCfg,
},
Paths: []gatewayv2alpha1.Path{
Rules: []gatewayv2alpha1.Rule{
{
Path: path,
Scopes: scopes,
Methods: methods,
Path: path,
Scopes: scopes,
Methods: methods,
Mutators: mutators,
},
},
Mutators: mutators,
},
}
}
Expand Down
2 changes: 1 addition & 1 deletion controllers/api_controller_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -82,7 +82,7 @@ func fixAPI() *gatewayv2alpha1.Gate {
Config: nil,
},
Gateway: &gateway,
Paths: []gatewayv2alpha1.Path{
Rules: []gatewayv2alpha1.Rule{
{
Path: "/.*",
Methods: []string{"GET"},
Expand Down
10 changes: 5 additions & 5 deletions internal/processing/allow.go
Original file line number Diff line number Diff line change
Expand Up @@ -19,7 +19,7 @@ type allow struct {
func (a *allow) Process(ctx context.Context, api *gatewayv2alpha1.Gate) error {
destinationHost := ""
var destinationPort uint32
if a.isSecured(api, api.Spec.Paths[0]) {
if a.isSecured(api.Spec.Rules[0]) {
destinationHost = fmt.Sprintf("%s.svc.cluster.local", a.oathkeeperSvc)
destinationPort = a.oathkeeperSvcPort
} else {
Expand All @@ -33,10 +33,10 @@ func (a *allow) Process(ctx context.Context, api *gatewayv2alpha1.Gate) error {
}

if oldVS != nil {
newVS := prepareVirtualService(api, oldVS, destinationHost, destinationPort, api.Spec.Paths[0].Path)
newVS := prepareVirtualService(api, oldVS, destinationHost, destinationPort, api.Spec.Rules[0].Path)
return a.updateVirtualService(ctx, newVS)
}
vs := generateVirtualService(api, destinationHost, destinationPort, api.Spec.Paths[0].Path)
vs := generateVirtualService(api, destinationHost, destinationPort, api.Spec.Rules[0].Path)
return a.createVirtualService(ctx, vs)

}
Expand All @@ -61,8 +61,8 @@ func (a *allow) updateVirtualService(ctx context.Context, vs *networkingv1alpha3
return a.vsClient.Update(ctx, vs)
}

func (a *allow) isSecured(api *gatewayv2alpha1.Gate, path gatewayv2alpha1.Path) bool {
if len(path.Scopes) > 0 || len(api.Spec.Mutators) > 0 {
func (a *allow) isSecured(rule gatewayv2alpha1.Rule) bool {
if len(rule.Scopes) > 0 || len(rule.Mutators) > 0 {
return true
}
return false
Expand Down
16 changes: 8 additions & 8 deletions internal/processing/allow_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -41,7 +41,7 @@ func TestVSforAllowModeNoMutators(t *testing.T) {
assert.Equal(len(vs.Spec.HTTP[0].Match), 1)
assert.Equal(vs.Spec.HTTP[0].Route[0].Destination.Host, serviceName+"."+apiNamespace+".svc.cluster.local")
assert.Equal(vs.Spec.HTTP[0].Route[0].Destination.Port.Number, servicePort)
assert.Equal(vs.Spec.HTTP[0].Match[0].URI.Regex, exampleAPI.Spec.Paths[0].Path)
assert.Equal(vs.Spec.HTTP[0].Match[0].URI.Regex, exampleAPI.Spec.Rules[0].Path)

assert.Equal(vs.ObjectMeta.Name, apiName+"-"+serviceName)
assert.Equal(vs.ObjectMeta.Namespace, apiNamespace)
Expand Down Expand Up @@ -71,16 +71,16 @@ func getGate4Allow() *gatewayv2alpha1.Gate {
Host: &serviceHost,
Port: &servicePort,
},
Paths: []gatewayv2alpha1.Path{
Rules: []gatewayv2alpha1.Rule{
{
Path: "/.*",
Methods: []string{"GET"},
},
},
Mutators: []*rulev1alpha1.Mutator{
{
&rulev1alpha1.Handler{
Name: "noop",
Mutators: []*rulev1alpha1.Mutator{
&rulev1alpha1.Mutator{
Handler: &rulev1alpha1.Handler{
Name: "noop",
},
},
},
},
},
Expand Down
Loading

0 comments on commit 33c9ca4

Please sign in to comment.