diff --git a/api/v1alpha1/ratelimit_types.go b/api/v1alpha1/ratelimit_types.go index e013579efdf0..5904e7f1eeb8 100644 --- a/api/v1alpha1/ratelimit_types.go +++ b/api/v1alpha1/ratelimit_types.go @@ -108,49 +108,25 @@ type SourceMatch struct { } // HeaderMatch defines the match attributes within the HTTP Headers of the request. -type HeaderMatch struct { // TODO: zhaohuabing this type could be replaced with a general purpose StringMatch type. - // Type specifies how to match against the value of the header. - // - // +optional - // +kubebuilder:default=Exact - Type *HeaderMatchType `json:"type,omitempty"` - +type HeaderMatch struct { // Name of the HTTP header. // +kubebuilder:validation:MinLength=1 // +kubebuilder:validation:MaxLength=256 Name string `json:"name"` - // Value within the HTTP header. Due to the - // case-insensitivity of header names, "foo" and "Foo" are considered equivalent. + // Distinct matches any and all possible unique values encountered in the + // specified HTTP Header. + // Note that each unique value will receive its own rate limit bucket. + // Only one of Distinct or Match can be set. + Distinct *bool `json:"distinct,omitempty"` + + // Match specifies how to match against the value of the header. // Do not set this field when Type="Distinct", implying matching on any/all unique // values within the header. - // - // +optional - // +kubebuilder:validation:MaxLength=1024 - Value *string `json:"value,omitempty"` + // Only one of Distinct or Match can be set. + Match *StringMatch `json:"match,omitempty"` } -// HeaderMatchType specifies the semantics of how HTTP header values should be compared. -// Valid HeaderMatchType values are "Exact", "RegularExpression", and "Distinct". -// -// +kubebuilder:validation:Enum=Exact;RegularExpression;Distinct -type HeaderMatchType string - -// HeaderMatchType constants. -const ( - // HeaderMatchExact matches the exact value of the Value field against the value of - // the specified HTTP Header. - HeaderMatchExact HeaderMatchType = "Exact" - // HeaderMatchRegularExpression matches a regular expression against the value of the - // specified HTTP Header. The regex string must adhere to the syntax documented in - // https://github.com/google/re2/wiki/Syntax. - HeaderMatchRegularExpression HeaderMatchType = "RegularExpression" - // HeaderMatchDistinct matches any and all possible unique values encountered in the - // specified HTTP Header. Note that each unique value will receive its own rate limit - // bucket. - HeaderMatchDistinct HeaderMatchType = "Distinct" -) - // RateLimitValue defines the limits for rate limiting. type RateLimitValue struct { Requests uint `json:"requests"` diff --git a/api/v1alpha1/zz_generated.deepcopy.go b/api/v1alpha1/zz_generated.deepcopy.go index 87eb64069275..90604002da6d 100644 --- a/api/v1alpha1/zz_generated.deepcopy.go +++ b/api/v1alpha1/zz_generated.deepcopy.go @@ -1180,15 +1180,15 @@ func (in *GroupVersionKind) DeepCopy() *GroupVersionKind { // DeepCopyInto is an autogenerated deepcopy function, copying the receiver, writing into out. in must be non-nil. func (in *HeaderMatch) DeepCopyInto(out *HeaderMatch) { *out = *in - if in.Type != nil { - in, out := &in.Type, &out.Type - *out = new(HeaderMatchType) + if in.Distinct != nil { + in, out := &in.Distinct, &out.Distinct + *out = new(bool) **out = **in } - if in.Value != nil { - in, out := &in.Value, &out.Value - *out = new(string) - **out = **in + if in.Match != nil { + in, out := &in.Match, &out.Match + *out = new(StringMatch) + (*in).DeepCopyInto(*out) } }