Skip to content

Commit

Permalink
Merge pull request #1883 from Krishanx92/pkg
Browse files Browse the repository at this point in the history
Add missing types to common-go-lib
  • Loading branch information
Krishanx92 authored Dec 6, 2023
2 parents 131edcc + e2e3de2 commit 7cef684
Show file tree
Hide file tree
Showing 4 changed files with 166 additions and 0 deletions.
9 changes: 9 additions & 0 deletions common-go-libs/build.gradle
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down
40 changes: 40 additions & 0 deletions common-go-libs/pkg/apis/dp/v1alpha1/custom_ratelimit_policy.go
Original file line number Diff line number Diff line change
@@ -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,
}
}
50 changes: 50 additions & 0 deletions common-go-libs/pkg/apis/dp/v1alpha1/resolveRatelimit.go
Original file line number Diff line number Diff line change
@@ -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"`
}
67 changes: 67 additions & 0 deletions common-go-libs/pkg/apis/dp/v1alpha1/zz_generated.deepcopy.go

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

0 comments on commit 7cef684

Please sign in to comment.