From e2e3de27e262ee77a0020013d0c760bf90936b52 Mon Sep 17 00:00:00 2001 From: Krishanx92 Date: Wed, 6 Dec 2023 12:09:52 +0530 Subject: [PATCH] Add missing types to common-go-lib --- common-go-libs/build.gradle | 9 +++ .../dp/v1alpha1/custom_ratelimit_policy.go | 40 +++++++++++ .../pkg/apis/dp/v1alpha1/resolveRatelimit.go | 50 ++++++++++++++ .../apis/dp/v1alpha1/zz_generated.deepcopy.go | 67 +++++++++++++++++++ 4 files changed, 166 insertions(+) create mode 100644 common-go-libs/pkg/apis/dp/v1alpha1/custom_ratelimit_policy.go create mode 100644 common-go-libs/pkg/apis/dp/v1alpha1/resolveRatelimit.go diff --git a/common-go-libs/build.gradle b/common-go-libs/build.gradle index c3a82e511..64e410a4b 100644 --- a/common-go-libs/build.gradle +++ b/common-go-libs/build.gradle @@ -21,6 +21,15 @@ plugins { apply from: "$rootDir/../common-gradle-scripts/go.gradle" +release { + tagTemplate = 'common-go-libs-$version' + + git { + requireBranch= "main" + pushToRemote= "origin" + } +} + allprojects { group = project.group version = project.version diff --git a/common-go-libs/pkg/apis/dp/v1alpha1/custom_ratelimit_policy.go b/common-go-libs/pkg/apis/dp/v1alpha1/custom_ratelimit_policy.go new file mode 100644 index 000000000..638c98d86 --- /dev/null +++ b/common-go-libs/pkg/apis/dp/v1alpha1/custom_ratelimit_policy.go @@ -0,0 +1,40 @@ +/* + * Copyright (c) 2023, WSO2 LLC. (http://www.wso2.org) All Rights Reserved. + * + * Licensed under the Apache License, Version 2.0 (the "License"); + * you may not use this file except in compliance with the License. + * You may obtain a copy of the License at + * + * http://www.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to in writing, software + * distributed under the License is distributed on an "AS IS" BASIS, + * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. + * See the License for the specific language governing permissions and + * limitations under the License. + * + */ + +package v1alpha1 + +// CustomRateLimitPolicyDef defines the desired state of CustomPolicy +type CustomRateLimitPolicyDef struct { + Key string `json:"key,omitempty"` + Value string `json:"value,omitempty"` + RequestsPerUnit uint32 `json:"requestsPerUnit,omitempty"` + + Unit string `json:"unit,omitempty"` + // RateLimit RateLimit `json:"rateLimit,omitempty"` + Organization string `json:"organization,omitempty"` +} + +// ParseCustomRateLimitPolicy parses the custom rate limit policy +func ParseCustomRateLimitPolicy(customRateLimitCR RateLimitPolicy) *CustomRateLimitPolicyDef { + return &CustomRateLimitPolicyDef{ + Key: customRateLimitCR.Spec.Override.Custom.Key, + Value: customRateLimitCR.Spec.Override.Custom.Value, + RequestsPerUnit: customRateLimitCR.Spec.Override.Custom.RequestsPerUnit, + Unit: customRateLimitCR.Spec.Override.Custom.Unit, + Organization: customRateLimitCR.Spec.Override.Custom.Organization, + } +} diff --git a/common-go-libs/pkg/apis/dp/v1alpha1/resolveRatelimit.go b/common-go-libs/pkg/apis/dp/v1alpha1/resolveRatelimit.go new file mode 100644 index 000000000..e3787acc0 --- /dev/null +++ b/common-go-libs/pkg/apis/dp/v1alpha1/resolveRatelimit.go @@ -0,0 +1,50 @@ +/* +Copyright 2023. + +Licensed under the Apache License, Version 2.0 (the "License"); +you may not use this file except in compliance with the License. +You may obtain a copy of the License at + + http://www.apache.org/licenses/LICENSE-2.0 + +Unless required by applicable law or agreed to in writing, software +distributed under the License is distributed on an "AS IS" BASIS, +WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. +See the License for the specific language governing permissions and +limitations under the License. +*/ +package v1alpha1 + +import ( + gwapiv1b1 "sigs.k8s.io/gateway-api/apis/v1beta1" +) + +// ResolveRateLimitAPIPolicy defines the desired state of Policy +type ResolveRateLimitAPIPolicy struct { + API ResolveRateLimit `json:"api,omitempty"` + Resources []ResolveResource `json:"resourceList,omitempty"` + Organization string `json:"organization,omitempty"` + BasePath string `json:"basePath,omitempty"` + UUID string `json:"uuid,omitempty"` + Environment string `json:"environment,omitempty"` +} + +// ResolveRateLimit is the rate limit value for the applied policy +type ResolveRateLimit struct { + // RequestPerUnit is the number of requests allowed per unit time + // + RequestsPerUnit uint32 `json:"requestsPerUnit,omitempty"` + + // Unit is the unit of the requestsPerUnit + // + // +kubebuilder:validation:Enum=Minute;Hour;Day + Unit string `json:"unit,omitempty"` +} + +// ResolveResource defines the desired state of Resource +type ResolveResource struct { + ResourceRatelimit ResolveRateLimit `json:"resourceRatelimit,omitempty"` + Path string `json:"path,omitempty"` + PathMatchType gwapiv1b1.PathMatchType `json:"pathMatchType,omitempty"` + Method string `json:"method,omitempty"` +} diff --git a/common-go-libs/pkg/apis/dp/v1alpha1/zz_generated.deepcopy.go b/common-go-libs/pkg/apis/dp/v1alpha1/zz_generated.deepcopy.go index d70d020d7..c70e95c27 100644 --- a/common-go-libs/pkg/apis/dp/v1alpha1/zz_generated.deepcopy.go +++ b/common-go-libs/pkg/apis/dp/v1alpha1/zz_generated.deepcopy.go @@ -807,6 +807,21 @@ func (in *CustomRateLimitPolicy) DeepCopy() *CustomRateLimitPolicy { return out } +// DeepCopyInto is an autogenerated deepcopy function, copying the receiver, writing into out. in must be non-nil. +func (in *CustomRateLimitPolicyDef) DeepCopyInto(out *CustomRateLimitPolicyDef) { + *out = *in +} + +// DeepCopy is an autogenerated deepcopy function, copying the receiver, creating a new CustomRateLimitPolicyDef. +func (in *CustomRateLimitPolicyDef) DeepCopy() *CustomRateLimitPolicyDef { + if in == nil { + return nil + } + out := new(CustomRateLimitPolicyDef) + in.DeepCopyInto(out) + return out +} + // DeepCopyInto is an autogenerated deepcopy function, copying the receiver, writing into out. in must be non-nil. func (in *DeploymentStatus) DeepCopyInto(out *DeploymentStatus) { *out = *in @@ -1230,6 +1245,58 @@ func (in *RefConfig) DeepCopy() *RefConfig { return out } +// DeepCopyInto is an autogenerated deepcopy function, copying the receiver, writing into out. in must be non-nil. +func (in *ResolveRateLimit) DeepCopyInto(out *ResolveRateLimit) { + *out = *in +} + +// DeepCopy is an autogenerated deepcopy function, copying the receiver, creating a new ResolveRateLimit. +func (in *ResolveRateLimit) DeepCopy() *ResolveRateLimit { + if in == nil { + return nil + } + out := new(ResolveRateLimit) + in.DeepCopyInto(out) + return out +} + +// DeepCopyInto is an autogenerated deepcopy function, copying the receiver, writing into out. in must be non-nil. +func (in *ResolveRateLimitAPIPolicy) DeepCopyInto(out *ResolveRateLimitAPIPolicy) { + *out = *in + out.API = in.API + if in.Resources != nil { + in, out := &in.Resources, &out.Resources + *out = make([]ResolveResource, len(*in)) + copy(*out, *in) + } +} + +// DeepCopy is an autogenerated deepcopy function, copying the receiver, creating a new ResolveRateLimitAPIPolicy. +func (in *ResolveRateLimitAPIPolicy) DeepCopy() *ResolveRateLimitAPIPolicy { + if in == nil { + return nil + } + out := new(ResolveRateLimitAPIPolicy) + in.DeepCopyInto(out) + return out +} + +// DeepCopyInto is an autogenerated deepcopy function, copying the receiver, writing into out. in must be non-nil. +func (in *ResolveResource) DeepCopyInto(out *ResolveResource) { + *out = *in + out.ResourceRatelimit = in.ResourceRatelimit +} + +// DeepCopy is an autogenerated deepcopy function, copying the receiver, creating a new ResolveResource. +func (in *ResolveResource) DeepCopy() *ResolveResource { + if in == nil { + return nil + } + out := new(ResolveResource) + in.DeepCopyInto(out) + return out +} + // DeepCopyInto is an autogenerated deepcopy function, copying the receiver, writing into out. in must be non-nil. func (in *ResolvedBackend) DeepCopyInto(out *ResolvedBackend) { *out = *in