diff --git a/api/v1beta2/ratelimitpolicy_types.go b/api/v1beta2/ratelimitpolicy_types.go index e4f8912a1..0c659bf87 100644 --- a/api/v1beta2/ratelimitpolicy_types.go +++ b/api/v1beta2/ratelimitpolicy_types.go @@ -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 diff --git a/bundle/manifests/kuadrant.io_ratelimitpolicies.yaml b/bundle/manifests/kuadrant.io_ratelimitpolicies.yaml index 2d52f40d1..2eeebd93a 100644 --- a/bundle/manifests/kuadrant.io_ratelimitpolicies.yaml +++ b/bundle/manifests/kuadrant.io_ratelimitpolicies.yaml @@ -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 diff --git a/config/crd/bases/kuadrant.io_ratelimitpolicies.yaml b/config/crd/bases/kuadrant.io_ratelimitpolicies.yaml index 000ff75fc..be4b708de 100644 --- a/config/crd/bases/kuadrant.io_ratelimitpolicies.yaml +++ b/config/crd/bases/kuadrant.io_ratelimitpolicies.yaml @@ -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 diff --git a/pkg/rlptools/wasm/types.go b/pkg/rlptools/wasm/types.go index d971bba57..9355734e2 100644 --- a/pkg/rlptools/wasm/types.go +++ b/pkg/rlptools/wasm/types.go @@ -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 @@ -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) diff --git a/pkg/rlptools/wasm_utils.go b/pkg/rlptools/wasm_utils.go index 149524a9b..fde2ebe04 100644 --- a/pkg/rlptools/wasm_utils.go +++ b/pkg/rlptools/wasm_utils.go @@ -165,7 +165,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, } @@ -190,7 +190,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