Skip to content

Commit

Permalink
different selectors share type: ContextSelector
Browse files Browse the repository at this point in the history
  • Loading branch information
eguzki authored and KevFan committed Aug 14, 2023
1 parent 4a2232c commit 70d61c0
Show file tree
Hide file tree
Showing 5 changed files with 14 additions and 16 deletions.
2 changes: 2 additions & 0 deletions api/v1beta2/ratelimitpolicy_types.go
Original file line number Diff line number Diff line change
Expand Up @@ -34,6 +34,8 @@ import (
// ContextSelector defines one item from the well known attributes
// Attributes: https://www.envoyproxy.io/docs/envoy/latest/intro/arch_overview/advanced/attributes
// Well-known selectors: https://github.com/Kuadrant/architecture/blob/main/rfcs/0001-rlp-v2.md#well-known-selectors
// They are named by a dot-separated path (e.g. request.path)
// Example: "request.path" -> The path portion of the URL
// +kubebuilder:validation:MinLength=1
// +kubebuilder:validation:MaxLength=253
type ContextSelector string
Expand Down
4 changes: 3 additions & 1 deletion bundle/manifests/kuadrant.io_ratelimitpolicies.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -47,7 +47,9 @@ spec:
items:
description: 'ContextSelector defines one item from the well
known attributes Attributes: https://www.envoyproxy.io/docs/envoy/latest/intro/arch_overview/advanced/attributes
Well-known selectors: https://github.com/Kuadrant/architecture/blob/main/rfcs/0001-rlp-v2.md#well-known-selectors'
Well-known selectors: https://github.com/Kuadrant/architecture/blob/main/rfcs/0001-rlp-v2.md#well-known-selectors
They are named by a dot-separated path (e.g. request.path)
Example: "request.path" -> The path portion of the URL'
maxLength: 253
minLength: 1
type: string
Expand Down
4 changes: 3 additions & 1 deletion config/crd/bases/kuadrant.io_ratelimitpolicies.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -46,7 +46,9 @@ spec:
items:
description: 'ContextSelector defines one item from the well
known attributes Attributes: https://www.envoyproxy.io/docs/envoy/latest/intro/arch_overview/advanced/attributes
Well-known selectors: https://github.com/Kuadrant/architecture/blob/main/rfcs/0001-rlp-v2.md#well-known-selectors'
Well-known selectors: https://github.com/Kuadrant/architecture/blob/main/rfcs/0001-rlp-v2.md#well-known-selectors
They are named by a dot-separated path (e.g. request.path)
Example: "request.path" -> The path portion of the URL'
maxLength: 253
minLength: 1
type: string
Expand Down
16 changes: 4 additions & 12 deletions pkg/rlptools/wasm/types.go
Original file line number Diff line number Diff line change
Expand Up @@ -18,13 +18,9 @@ var (
)

type SelectorSpec struct {
// Selector of an attribute from the contextual properties provided by Envoy
// Selector of an attribute from the contextual properties provided by kuadrant
// during request and connection processing
// https://www.envoyproxy.io/docs/envoy/latest/intro/arch_overview/advanced/attributes
// They are named by a dot-separated path (e.g. request.path)
// Examples:
// "request.path" -> The path portion of the URL
Selector string `json:"selector"`
Selector kuadrantv1beta2.ContextSelector `json:"selector"`

// If not set it defaults to `selector` field value as the descriptor key.
// +optional
Expand Down Expand Up @@ -54,13 +50,9 @@ type DataItem struct {
type PatternOperator kuadrantv1beta2.WhenConditionOperator

type PatternExpression struct {
// Selector of an attribute from the contextual properties provided by Envoy
// Selector of an attribute from the contextual properties provided by kuadrant
// during request and connection processing
// https://www.envoyproxy.io/docs/envoy/latest/intro/arch_overview/advanced/attributes
// They are named by a dot-separated path (e.g. request.path)
// Examples:
// "request.path" -> The path portion of the URL
Selector string `json:"selector"`
Selector kuadrantv1beta2.ContextSelector `json:"selector"`

// The binary operator to be applied to the content fetched from context, for comparison with "value".
// Possible values are: "eq" (equal to), "neq" (not equal to), "incl" (includes; for arrays), "excl" (excludes; for arrays), "matches" (regex)
Expand Down
4 changes: 2 additions & 2 deletions pkg/rlptools/wasm_utils.go
Original file line number Diff line number Diff line change
Expand Up @@ -164,7 +164,7 @@ func patternExpresionFromMethod(method gatewayapiv1beta1.HTTPMethod) wasm.Patter

func patternExpresionFromWhen(when kuadrantv1beta2.WhenCondition) wasm.PatternExpression {
return wasm.PatternExpression{
Selector: string(when.Selector),
Selector: when.Selector,
Operator: wasm.PatternOperator(when.Operator),
Value: when.Value,
}
Expand All @@ -189,7 +189,7 @@ func dataFromLimt(limitFullName string, limit *kuadrantv1beta2.Limit) []wasm.Dat
data = append(data, wasm.DataItem{Static: &wasm.StaticSpec{Key: limitFullName, Value: "1"}})

for _, counter := range limit.Counters {
data = append(data, wasm.DataItem{Selector: &wasm.SelectorSpec{Selector: string(counter)}})
data = append(data, wasm.DataItem{Selector: &wasm.SelectorSpec{Selector: counter}})
}

return data
Expand Down

0 comments on commit 70d61c0

Please sign in to comment.