From 5c8fc177394c71ffadef38ae56c19ca09a21ad7b Mon Sep 17 00:00:00 2001 From: Shubhendu Ram Tripathi Date: Mon, 4 Dec 2023 18:53:41 +0530 Subject: [PATCH] Added bucket throttle configuration struct Signed-off-by: Shubhendu Ram Tripathi --- pkg/throttle/throttle.go | 71 ++++++++++++++++++++++++++++++++++++++++ 1 file changed, 71 insertions(+) create mode 100644 pkg/throttle/throttle.go diff --git a/pkg/throttle/throttle.go b/pkg/throttle/throttle.go new file mode 100644 index 0000000000..d5e945eece --- /dev/null +++ b/pkg/throttle/throttle.go @@ -0,0 +1,71 @@ +/* + * MinIO Go Library for Amazon S3 Compatible Cloud Storage + * Copyright 2020 MinIO, Inc. + * + * 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 lifecycle contains all the lifecycle related data types and marshallers. +package throttle + +import ( + "encoding/json" + "encoding/xml" + //"errors" + //"time" +) + +// MarshalJSON customizes json encoding by omitting empty values +func (r Rule) MarshalJSON() ([]byte, error) { + type rule struct { + ConcurrentRequestsCount uint64 `json:"ConcurrentRequestsCount,omitempty"` + APIs string `json:"APIs",omitempty` + ID string `json:"ID"` + } + newr := rule{ + ConcurrentRequestsCount: r.ConcurrentRequestsCount, + APIs: r.APIs, + ID: r.ID, + } + + return json.Marshal(newr) +} + +// Rule represents a single rule in throttle configuration +type Rule struct { + XMLName xml.Name `xml:"Rule,omitempty" json:"-"` + ConcurrentRequestsCount uint64 `xml:"ConcurrentRequestsCount" json:"ConcurrentRequestsCount"` + APIs string `xml:"APIs" json:"APIs"` + ID string `xml:"ID" json:"ID"` +} + +// Configuration is a collection of Rule objects. +type Configuration struct { + XMLName xml.Name `xml:"ThrottleConfiguration,omitempty" json:"-"` + Rules []Rule `xml:"Rule"` +} + +// Empty check if lifecycle configuration is empty +func (c *Configuration) Empty() bool { + if c == nil { + return true + } + return len(c.Rules) == 0 +} + +// NewConfiguration initializes a fresh lifecycle configuration +// for manipulation, such as setting and removing lifecycle rules +// and filters. +func NewConfiguration() *Configuration { + return &Configuration{} +}