Added lifecycle rules to multiple buckets at once support (#1566)

Signed-off-by: Benjamin Perez <benjamin@bexsoft.net>

Co-authored-by: Benjamin Perez <benjamin@bexsoft.net>
This commit is contained in:
Alex
2022-02-15 10:47:28 -07:00
committed by GitHub
parent 5b2715ccc0
commit 81714bbbed
18 changed files with 1771 additions and 81 deletions

View File

@@ -698,6 +698,39 @@ func init() {
}
}
},
"/buckets/multi-lifecycle": {
"post": {
"tags": [
"UserAPI"
],
"summary": "Add Multi Bucket Lifecycle",
"operationId": "AddMultiBucketLifecycle",
"parameters": [
{
"name": "body",
"in": "body",
"required": true,
"schema": {
"$ref": "#/definitions/addMultiBucketLifecycle"
}
}
],
"responses": {
"200": {
"description": "A successful response.",
"schema": {
"$ref": "#/definitions/multiLifecycleResult"
}
},
"default": {
"description": "Generic error response.",
"schema": {
"$ref": "#/definitions/error"
}
}
}
}
},
"/buckets/{bucket_name}/delete-objects": {
"post": {
"tags": [
@@ -3850,10 +3883,6 @@ func init() {
"description": "Non required, toggle to disable or enable rule",
"type": "boolean"
},
"expiry_date": {
"description": "Required in case of expiry_days or transition fields are not set. it defines an expiry date for ILM",
"type": "string"
},
"expiry_days": {
"description": "Required in case of expiry_date or transition fields are not set. it defines an expiry days for ILM",
"type": "integer",
@@ -3888,10 +3917,6 @@ func init() {
"description": "Non required field, tags to match ILM files",
"type": "string"
},
"transition_date": {
"description": "Required in case of transition_days or expiry fields are not set. it defines a transition date for ILM",
"type": "string"
},
"transition_days": {
"description": "Required in case of transition_date or expiry fields are not set. it defines a transition days for ILM",
"type": "integer",
@@ -3937,6 +3962,73 @@ func init() {
}
}
},
"addMultiBucketLifecycle": {
"type": "object",
"required": [
"buckets",
"type"
],
"properties": {
"buckets": {
"type": "array",
"items": {
"type": "string"
}
},
"expired_object_delete_marker": {
"description": "Non required, toggle to disable or enable rule",
"type": "boolean"
},
"expiry_days": {
"description": "Required in case of expiry_date or transition fields are not set. it defines an expiry days for ILM",
"type": "integer",
"format": "int32",
"default": 0
},
"noncurrentversion_expiration_days": {
"description": "Non required, can be set in case of expiration is enabled",
"type": "integer",
"format": "int32",
"default": 0
},
"noncurrentversion_transition_days": {
"description": "Non required, can be set in case of transition is enabled",
"type": "integer",
"format": "int32",
"default": 0
},
"noncurrentversion_transition_storage_class": {
"description": "Non required, can be set in case of transition is enabled",
"type": "string"
},
"prefix": {
"description": "Non required field, it matches a prefix to perform ILM operations on it",
"type": "string"
},
"storage_class": {
"description": "Required only in case of transition is set. it refers to a tier",
"type": "string"
},
"tags": {
"description": "Non required field, tags to match ILM files",
"type": "string"
},
"transition_days": {
"description": "Required in case of transition_date or expiry fields are not set. it defines a transition days for ILM",
"type": "integer",
"format": "int32",
"default": 0
},
"type": {
"description": "ILM Rule type (Expiry or transition)",
"type": "string",
"enum": [
"expiry",
"transition"
]
}
}
},
"addPolicyRequest": {
"type": "object",
"required": [
@@ -5043,6 +5135,27 @@ func init() {
}
}
},
"multiLifecycleResult": {
"properties": {
"results": {
"type": "array",
"items": {
"$ref": "#/definitions/multicycleResultItem"
}
}
}
},
"multicycleResultItem": {
"type": "object",
"properties": {
"bucketName": {
"type": "string"
},
"error": {
"type": "string"
}
}
},
"nofiticationService": {
"type": "string",
"enum": [
@@ -6956,6 +7069,39 @@ func init() {
}
}
},
"/buckets/multi-lifecycle": {
"post": {
"tags": [
"UserAPI"
],
"summary": "Add Multi Bucket Lifecycle",
"operationId": "AddMultiBucketLifecycle",
"parameters": [
{
"name": "body",
"in": "body",
"required": true,
"schema": {
"$ref": "#/definitions/addMultiBucketLifecycle"
}
}
],
"responses": {
"200": {
"description": "A successful response.",
"schema": {
"$ref": "#/definitions/multiLifecycleResult"
}
},
"default": {
"description": "Generic error response.",
"schema": {
"$ref": "#/definitions/error"
}
}
}
}
},
"/buckets/{bucket_name}/delete-objects": {
"post": {
"tags": [
@@ -10226,10 +10372,6 @@ func init() {
"description": "Non required, toggle to disable or enable rule",
"type": "boolean"
},
"expiry_date": {
"description": "Required in case of expiry_days or transition fields are not set. it defines an expiry date for ILM",
"type": "string"
},
"expiry_days": {
"description": "Required in case of expiry_date or transition fields are not set. it defines an expiry days for ILM",
"type": "integer",
@@ -10264,10 +10406,6 @@ func init() {
"description": "Non required field, tags to match ILM files",
"type": "string"
},
"transition_date": {
"description": "Required in case of transition_days or expiry fields are not set. it defines a transition date for ILM",
"type": "string"
},
"transition_days": {
"description": "Required in case of transition_date or expiry fields are not set. it defines a transition days for ILM",
"type": "integer",
@@ -10313,6 +10451,73 @@ func init() {
}
}
},
"addMultiBucketLifecycle": {
"type": "object",
"required": [
"buckets",
"type"
],
"properties": {
"buckets": {
"type": "array",
"items": {
"type": "string"
}
},
"expired_object_delete_marker": {
"description": "Non required, toggle to disable or enable rule",
"type": "boolean"
},
"expiry_days": {
"description": "Required in case of expiry_date or transition fields are not set. it defines an expiry days for ILM",
"type": "integer",
"format": "int32",
"default": 0
},
"noncurrentversion_expiration_days": {
"description": "Non required, can be set in case of expiration is enabled",
"type": "integer",
"format": "int32",
"default": 0
},
"noncurrentversion_transition_days": {
"description": "Non required, can be set in case of transition is enabled",
"type": "integer",
"format": "int32",
"default": 0
},
"noncurrentversion_transition_storage_class": {
"description": "Non required, can be set in case of transition is enabled",
"type": "string"
},
"prefix": {
"description": "Non required field, it matches a prefix to perform ILM operations on it",
"type": "string"
},
"storage_class": {
"description": "Required only in case of transition is set. it refers to a tier",
"type": "string"
},
"tags": {
"description": "Non required field, tags to match ILM files",
"type": "string"
},
"transition_days": {
"description": "Required in case of transition_date or expiry fields are not set. it defines a transition days for ILM",
"type": "integer",
"format": "int32",
"default": 0
},
"type": {
"description": "ILM Rule type (Expiry or transition)",
"type": "string",
"enum": [
"expiry",
"transition"
]
}
}
},
"addPolicyRequest": {
"type": "object",
"required": [
@@ -11419,6 +11624,27 @@ func init() {
}
}
},
"multiLifecycleResult": {
"properties": {
"results": {
"type": "array",
"items": {
"$ref": "#/definitions/multicycleResultItem"
}
}
}
},
"multicycleResultItem": {
"type": "object",
"properties": {
"bucketName": {
"type": "string"
},
"error": {
"type": "string"
}
}
},
"nofiticationService": {
"type": "string",
"enum": [

View File

@@ -74,6 +74,9 @@ func NewConsoleAPI(spec *loads.Document) *ConsoleAPI {
AdminAPIAddGroupHandler: admin_api.AddGroupHandlerFunc(func(params admin_api.AddGroupParams, principal *models.Principal) middleware.Responder {
return middleware.NotImplemented("operation admin_api.AddGroup has not yet been implemented")
}),
UserAPIAddMultiBucketLifecycleHandler: user_api.AddMultiBucketLifecycleHandlerFunc(func(params user_api.AddMultiBucketLifecycleParams, principal *models.Principal) middleware.Responder {
return middleware.NotImplemented("operation user_api.AddMultiBucketLifecycle has not yet been implemented")
}),
AdminAPIAddNotificationEndpointHandler: admin_api.AddNotificationEndpointHandlerFunc(func(params admin_api.AddNotificationEndpointParams, principal *models.Principal) middleware.Responder {
return middleware.NotImplemented("operation admin_api.AddNotificationEndpoint has not yet been implemented")
}),
@@ -456,6 +459,8 @@ type ConsoleAPI struct {
UserAPIAddBucketLifecycleHandler user_api.AddBucketLifecycleHandler
// AdminAPIAddGroupHandler sets the operation handler for the add group operation
AdminAPIAddGroupHandler admin_api.AddGroupHandler
// UserAPIAddMultiBucketLifecycleHandler sets the operation handler for the add multi bucket lifecycle operation
UserAPIAddMultiBucketLifecycleHandler user_api.AddMultiBucketLifecycleHandler
// AdminAPIAddNotificationEndpointHandler sets the operation handler for the add notification endpoint operation
AdminAPIAddNotificationEndpointHandler admin_api.AddNotificationEndpointHandler
// AdminAPIAddPolicyHandler sets the operation handler for the add policy operation
@@ -766,6 +771,9 @@ func (o *ConsoleAPI) Validate() error {
if o.AdminAPIAddGroupHandler == nil {
unregistered = append(unregistered, "admin_api.AddGroupHandler")
}
if o.UserAPIAddMultiBucketLifecycleHandler == nil {
unregistered = append(unregistered, "user_api.AddMultiBucketLifecycleHandler")
}
if o.AdminAPIAddNotificationEndpointHandler == nil {
unregistered = append(unregistered, "admin_api.AddNotificationEndpointHandler")
}
@@ -1204,6 +1212,10 @@ func (o *ConsoleAPI) initHandlerCache() {
if o.handlers["POST"] == nil {
o.handlers["POST"] = make(map[string]http.Handler)
}
o.handlers["POST"]["/buckets/multi-lifecycle"] = user_api.NewAddMultiBucketLifecycle(o.context, o.UserAPIAddMultiBucketLifecycleHandler)
if o.handlers["POST"] == nil {
o.handlers["POST"] = make(map[string]http.Handler)
}
o.handlers["POST"]["/admin/notification_endpoints"] = admin_api.NewAddNotificationEndpoint(o.context, o.AdminAPIAddNotificationEndpointHandler)
if o.handlers["POST"] == nil {
o.handlers["POST"] = make(map[string]http.Handler)

View File

@@ -0,0 +1,88 @@
// Code generated by go-swagger; DO NOT EDIT.
// This file is part of MinIO Console Server
// Copyright (c) 2021 MinIO, Inc.
//
// This program is free software: you can redistribute it and/or modify
// it under the terms of the GNU Affero General Public License as published by
// the Free Software Foundation, either version 3 of the License, or
// (at your option) any later version.
//
// This program is distributed in the hope that it will be useful,
// but WITHOUT ANY WARRANTY; without even the implied warranty of
// MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
// GNU Affero General Public License for more details.
//
// You should have received a copy of the GNU Affero General Public License
// along with this program. If not, see <http://www.gnu.org/licenses/>.
//
package user_api
// This file was generated by the swagger tool.
// Editing this file might prove futile when you re-run the generate command
import (
"net/http"
"github.com/go-openapi/runtime/middleware"
"github.com/minio/console/models"
)
// AddMultiBucketLifecycleHandlerFunc turns a function with the right signature into a add multi bucket lifecycle handler
type AddMultiBucketLifecycleHandlerFunc func(AddMultiBucketLifecycleParams, *models.Principal) middleware.Responder
// Handle executing the request and returning a response
func (fn AddMultiBucketLifecycleHandlerFunc) Handle(params AddMultiBucketLifecycleParams, principal *models.Principal) middleware.Responder {
return fn(params, principal)
}
// AddMultiBucketLifecycleHandler interface for that can handle valid add multi bucket lifecycle params
type AddMultiBucketLifecycleHandler interface {
Handle(AddMultiBucketLifecycleParams, *models.Principal) middleware.Responder
}
// NewAddMultiBucketLifecycle creates a new http.Handler for the add multi bucket lifecycle operation
func NewAddMultiBucketLifecycle(ctx *middleware.Context, handler AddMultiBucketLifecycleHandler) *AddMultiBucketLifecycle {
return &AddMultiBucketLifecycle{Context: ctx, Handler: handler}
}
/* AddMultiBucketLifecycle swagger:route POST /buckets/multi-lifecycle UserAPI addMultiBucketLifecycle
Add Multi Bucket Lifecycle
*/
type AddMultiBucketLifecycle struct {
Context *middleware.Context
Handler AddMultiBucketLifecycleHandler
}
func (o *AddMultiBucketLifecycle) ServeHTTP(rw http.ResponseWriter, r *http.Request) {
route, rCtx, _ := o.Context.RouteInfo(r)
if rCtx != nil {
*r = *rCtx
}
var Params = NewAddMultiBucketLifecycleParams()
uprinc, aCtx, err := o.Context.Authorize(r, route)
if err != nil {
o.Context.Respond(rw, r, route.Produces, route, err)
return
}
if aCtx != nil {
*r = *aCtx
}
var principal *models.Principal
if uprinc != nil {
principal = uprinc.(*models.Principal) // this is really a models.Principal, I promise
}
if err := o.Context.BindValidRequest(r, route, &Params); err != nil { // bind params
o.Context.Respond(rw, r, route.Produces, route, err)
return
}
res := o.Handler.Handle(Params, principal) // actually handle the request
o.Context.Respond(rw, r, route.Produces, route, res)
}

View File

@@ -0,0 +1,102 @@
// Code generated by go-swagger; DO NOT EDIT.
// This file is part of MinIO Console Server
// Copyright (c) 2021 MinIO, Inc.
//
// This program is free software: you can redistribute it and/or modify
// it under the terms of the GNU Affero General Public License as published by
// the Free Software Foundation, either version 3 of the License, or
// (at your option) any later version.
//
// This program is distributed in the hope that it will be useful,
// but WITHOUT ANY WARRANTY; without even the implied warranty of
// MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
// GNU Affero General Public License for more details.
//
// You should have received a copy of the GNU Affero General Public License
// along with this program. If not, see <http://www.gnu.org/licenses/>.
//
package user_api
// This file was generated by the swagger tool.
// Editing this file might prove futile when you re-run the swagger generate command
import (
"context"
"io"
"net/http"
"github.com/go-openapi/errors"
"github.com/go-openapi/runtime"
"github.com/go-openapi/runtime/middleware"
"github.com/go-openapi/validate"
"github.com/minio/console/models"
)
// NewAddMultiBucketLifecycleParams creates a new AddMultiBucketLifecycleParams object
//
// There are no default values defined in the spec.
func NewAddMultiBucketLifecycleParams() AddMultiBucketLifecycleParams {
return AddMultiBucketLifecycleParams{}
}
// AddMultiBucketLifecycleParams contains all the bound params for the add multi bucket lifecycle operation
// typically these are obtained from a http.Request
//
// swagger:parameters AddMultiBucketLifecycle
type AddMultiBucketLifecycleParams struct {
// HTTP Request Object
HTTPRequest *http.Request `json:"-"`
/*
Required: true
In: body
*/
Body *models.AddMultiBucketLifecycle
}
// BindRequest both binds and validates a request, it assumes that complex things implement a Validatable(strfmt.Registry) error interface
// for simple values it will use straight method calls.
//
// To ensure default values, the struct must have been initialized with NewAddMultiBucketLifecycleParams() beforehand.
func (o *AddMultiBucketLifecycleParams) BindRequest(r *http.Request, route *middleware.MatchedRoute) error {
var res []error
o.HTTPRequest = r
if runtime.HasBody(r) {
defer r.Body.Close()
var body models.AddMultiBucketLifecycle
if err := route.Consumer.Consume(r.Body, &body); err != nil {
if err == io.EOF {
res = append(res, errors.Required("body", "body", ""))
} else {
res = append(res, errors.NewParseError("body", "body", "", err))
}
} else {
// validate body object
if err := body.Validate(route.Formats); err != nil {
res = append(res, err)
}
ctx := validate.WithOperationRequest(context.Background())
if err := body.ContextValidate(ctx, route.Formats); err != nil {
res = append(res, err)
}
if len(res) == 0 {
o.Body = &body
}
}
} else {
res = append(res, errors.Required("body", "body", ""))
}
if len(res) > 0 {
return errors.CompositeValidationError(res...)
}
return nil
}

View File

@@ -0,0 +1,133 @@
// Code generated by go-swagger; DO NOT EDIT.
// This file is part of MinIO Console Server
// Copyright (c) 2021 MinIO, Inc.
//
// This program is free software: you can redistribute it and/or modify
// it under the terms of the GNU Affero General Public License as published by
// the Free Software Foundation, either version 3 of the License, or
// (at your option) any later version.
//
// This program is distributed in the hope that it will be useful,
// but WITHOUT ANY WARRANTY; without even the implied warranty of
// MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
// GNU Affero General Public License for more details.
//
// You should have received a copy of the GNU Affero General Public License
// along with this program. If not, see <http://www.gnu.org/licenses/>.
//
package user_api
// This file was generated by the swagger tool.
// Editing this file might prove futile when you re-run the swagger generate command
import (
"net/http"
"github.com/go-openapi/runtime"
"github.com/minio/console/models"
)
// AddMultiBucketLifecycleOKCode is the HTTP code returned for type AddMultiBucketLifecycleOK
const AddMultiBucketLifecycleOKCode int = 200
/*AddMultiBucketLifecycleOK A successful response.
swagger:response addMultiBucketLifecycleOK
*/
type AddMultiBucketLifecycleOK struct {
/*
In: Body
*/
Payload *models.MultiLifecycleResult `json:"body,omitempty"`
}
// NewAddMultiBucketLifecycleOK creates AddMultiBucketLifecycleOK with default headers values
func NewAddMultiBucketLifecycleOK() *AddMultiBucketLifecycleOK {
return &AddMultiBucketLifecycleOK{}
}
// WithPayload adds the payload to the add multi bucket lifecycle o k response
func (o *AddMultiBucketLifecycleOK) WithPayload(payload *models.MultiLifecycleResult) *AddMultiBucketLifecycleOK {
o.Payload = payload
return o
}
// SetPayload sets the payload to the add multi bucket lifecycle o k response
func (o *AddMultiBucketLifecycleOK) SetPayload(payload *models.MultiLifecycleResult) {
o.Payload = payload
}
// WriteResponse to the client
func (o *AddMultiBucketLifecycleOK) WriteResponse(rw http.ResponseWriter, producer runtime.Producer) {
rw.WriteHeader(200)
if o.Payload != nil {
payload := o.Payload
if err := producer.Produce(rw, payload); err != nil {
panic(err) // let the recovery middleware deal with this
}
}
}
/*AddMultiBucketLifecycleDefault Generic error response.
swagger:response addMultiBucketLifecycleDefault
*/
type AddMultiBucketLifecycleDefault struct {
_statusCode int
/*
In: Body
*/
Payload *models.Error `json:"body,omitempty"`
}
// NewAddMultiBucketLifecycleDefault creates AddMultiBucketLifecycleDefault with default headers values
func NewAddMultiBucketLifecycleDefault(code int) *AddMultiBucketLifecycleDefault {
if code <= 0 {
code = 500
}
return &AddMultiBucketLifecycleDefault{
_statusCode: code,
}
}
// WithStatusCode adds the status to the add multi bucket lifecycle default response
func (o *AddMultiBucketLifecycleDefault) WithStatusCode(code int) *AddMultiBucketLifecycleDefault {
o._statusCode = code
return o
}
// SetStatusCode sets the status to the add multi bucket lifecycle default response
func (o *AddMultiBucketLifecycleDefault) SetStatusCode(code int) {
o._statusCode = code
}
// WithPayload adds the payload to the add multi bucket lifecycle default response
func (o *AddMultiBucketLifecycleDefault) WithPayload(payload *models.Error) *AddMultiBucketLifecycleDefault {
o.Payload = payload
return o
}
// SetPayload sets the payload to the add multi bucket lifecycle default response
func (o *AddMultiBucketLifecycleDefault) SetPayload(payload *models.Error) {
o.Payload = payload
}
// WriteResponse to the client
func (o *AddMultiBucketLifecycleDefault) WriteResponse(rw http.ResponseWriter, producer runtime.Producer) {
rw.WriteHeader(o._statusCode)
if o.Payload != nil {
payload := o.Payload
if err := producer.Produce(rw, payload); err != nil {
panic(err) // let the recovery middleware deal with this
}
}
}

View File

@@ -0,0 +1,104 @@
// Code generated by go-swagger; DO NOT EDIT.
// This file is part of MinIO Console Server
// Copyright (c) 2021 MinIO, Inc.
//
// This program is free software: you can redistribute it and/or modify
// it under the terms of the GNU Affero General Public License as published by
// the Free Software Foundation, either version 3 of the License, or
// (at your option) any later version.
//
// This program is distributed in the hope that it will be useful,
// but WITHOUT ANY WARRANTY; without even the implied warranty of
// MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
// GNU Affero General Public License for more details.
//
// You should have received a copy of the GNU Affero General Public License
// along with this program. If not, see <http://www.gnu.org/licenses/>.
//
package user_api
// This file was generated by the swagger tool.
// Editing this file might prove futile when you re-run the generate command
import (
"errors"
"net/url"
golangswaggerpaths "path"
)
// AddMultiBucketLifecycleURL generates an URL for the add multi bucket lifecycle operation
type AddMultiBucketLifecycleURL struct {
_basePath string
}
// WithBasePath sets the base path for this url builder, only required when it's different from the
// base path specified in the swagger spec.
// When the value of the base path is an empty string
func (o *AddMultiBucketLifecycleURL) WithBasePath(bp string) *AddMultiBucketLifecycleURL {
o.SetBasePath(bp)
return o
}
// SetBasePath sets the base path for this url builder, only required when it's different from the
// base path specified in the swagger spec.
// When the value of the base path is an empty string
func (o *AddMultiBucketLifecycleURL) SetBasePath(bp string) {
o._basePath = bp
}
// Build a url path and query string
func (o *AddMultiBucketLifecycleURL) Build() (*url.URL, error) {
var _result url.URL
var _path = "/buckets/multi-lifecycle"
_basePath := o._basePath
if _basePath == "" {
_basePath = "/api/v1"
}
_result.Path = golangswaggerpaths.Join(_basePath, _path)
return &_result, nil
}
// Must is a helper function to panic when the url builder returns an error
func (o *AddMultiBucketLifecycleURL) Must(u *url.URL, err error) *url.URL {
if err != nil {
panic(err)
}
if u == nil {
panic("url can't be nil")
}
return u
}
// String returns the string representation of the path with query string
func (o *AddMultiBucketLifecycleURL) String() string {
return o.Must(o.Build()).String()
}
// BuildFull builds a full url with scheme, host, path and query string
func (o *AddMultiBucketLifecycleURL) BuildFull(scheme, host string) (*url.URL, error) {
if scheme == "" {
return nil, errors.New("scheme is required for a full url on AddMultiBucketLifecycleURL")
}
if host == "" {
return nil, errors.New("host is required for a full url on AddMultiBucketLifecycleURL")
}
base, err := o.Build()
if err != nil {
return nil, err
}
base.Scheme = scheme
base.Host = host
return base, nil
}
// StringFull returns the string representation of a complete url
func (o *AddMultiBucketLifecycleURL) StringFull(scheme, host string) string {
return o.Must(o.BuildFull(scheme, host)).String()
}

View File

@@ -39,6 +39,11 @@ import (
"github.com/minio/console/restapi/operations/user_api"
)
type MultiLifecycleResult struct {
BucketName string
Error string
}
func registerBucketsLifecycleHandlers(api *operations.ConsoleAPI) {
api.UserAPIGetBucketLifecycleHandler = user_api.GetBucketLifecycleHandlerFunc(func(params user_api.GetBucketLifecycleParams, session *models.Principal) middleware.Responder {
listBucketLifecycleResponse, err := getBucketLifecycleResponse(session, params)
@@ -70,6 +75,14 @@ func registerBucketsLifecycleHandlers(api *operations.ConsoleAPI) {
return user_api.NewDeleteBucketLifecycleRuleNoContent()
})
api.UserAPIAddMultiBucketLifecycleHandler = user_api.AddMultiBucketLifecycleHandlerFunc(func(params user_api.AddMultiBucketLifecycleParams, session *models.Principal) middleware.Responder {
multiBucketResponse, err := getAddMultiBucketLifecycleResponse(session, params)
if err != nil {
user_api.NewAddMultiBucketLifecycleDefault(int(err.Code)).WithPayload(err)
}
return user_api.NewAddMultiBucketLifecycleOK().WithPayload(multiBucketResponse)
})
}
// getBucketLifecycle() gets lifecycle lists for a bucket from MinIO API and returns their implementations
@@ -376,3 +389,98 @@ func getDeleteBucketLifecycleRule(session *models.Principal, params user_api.Del
return nil
}
// addMultiBucketLifecycle creates multibuckets lifecycle assignments
func addMultiBucketLifecycle(ctx context.Context, client MinioClient, params user_api.AddMultiBucketLifecycleParams) []MultiLifecycleResult {
bucketsRelation := params.Body.Buckets
// Parallel Lifecycle rules set
parallelLifecycleBucket := func(bucketName string) chan MultiLifecycleResult {
remoteProc := make(chan MultiLifecycleResult)
lifecycleParams := models.AddBucketLifecycle{
Type: *params.Body.Type,
StorageClass: params.Body.StorageClass,
TransitionDays: params.Body.TransitionDays,
Prefix: params.Body.Prefix,
NoncurrentversionTransitionDays: params.Body.NoncurrentversionTransitionDays,
NoncurrentversionTransitionStorageClass: params.Body.NoncurrentversionTransitionStorageClass,
NoncurrentversionExpirationDays: params.Body.NoncurrentversionExpirationDays,
Tags: params.Body.Tags,
ExpiryDays: params.Body.ExpiryDays,
Disable: false,
ExpiredObjectDeleteMarker: params.Body.ExpiredObjectDeleteMarker,
}
go func() {
defer close(remoteProc)
lifecycleParams := user_api.AddBucketLifecycleParams{
BucketName: bucketName,
Body: &lifecycleParams,
}
// We add lifecycle rule & expect a response
err := addBucketLifecycle(ctx, client, lifecycleParams)
var errorReturn = ""
if err != nil {
errorReturn = err.Error()
}
retParams := MultiLifecycleResult{
BucketName: bucketName,
Error: errorReturn,
}
remoteProc <- retParams
}()
return remoteProc
}
var lifecycleManagement []chan MultiLifecycleResult
for _, bucketName := range bucketsRelation {
rBucket := parallelLifecycleBucket(bucketName)
lifecycleManagement = append(lifecycleManagement, rBucket)
}
var resultsList []MultiLifecycleResult
for _, result := range lifecycleManagement {
res := <-result
resultsList = append(resultsList, res)
}
return resultsList
}
// getAddMultiBucketLifecycleResponse returns the response of multibucket lifecycle assignment
func getAddMultiBucketLifecycleResponse(session *models.Principal, params user_api.AddMultiBucketLifecycleParams) (*models.MultiLifecycleResult, *models.Error) {
ctx := context.Background()
mClient, err := newMinioClient(session)
if err != nil {
return nil, prepareError(err)
}
// create a minioClient interface implementation
// defining the client to be used
minioClient := minioClient{client: mClient}
multiCycleResult := addMultiBucketLifecycle(ctx, minioClient, params)
var returnList []*models.MulticycleResultItem
for _, resultItem := range multiCycleResult {
multicycleRS := models.MulticycleResultItem{
BucketName: resultItem.BucketName,
Error: resultItem.Error,
}
returnList = append(returnList, &multicycleRS)
}
finalResult := models.MultiLifecycleResult{Results: returnList}
return &finalResult, nil
}

View File

@@ -178,7 +178,6 @@ func TestSetLifecycleRule(t *testing.T) {
Prefix: "pref1",
StorageClass: "",
Tags: "",
TransitionDate: "",
TransitionDays: 0,
},
}