Added delete all replication rules capability (#1579)

This commit is contained in:
Alex
2022-02-15 18:14:23 -07:00
committed by GitHub
parent 00c4ba430d
commit 226e8eeef2
11 changed files with 641 additions and 38 deletions

View File

@@ -109,6 +109,17 @@ func registerAdminBucketRemoteHandlers(api *operations.ConsoleAPI) {
return user_api.NewDeleteBucketReplicationRuleNoContent()
})
// delete all replication rules for a bucket
api.UserAPIDeleteAllReplicationRulesHandler = user_api.DeleteAllReplicationRulesHandlerFunc(func(params user_api.DeleteAllReplicationRulesParams, session *models.Principal) middleware.Responder {
err := deleteBucketReplicationRulesResponse(session, params)
if err != nil {
return user_api.NewDeleteAllReplicationRulesDefault(500).WithPayload(err)
}
return user_api.NewDeleteAllReplicationRulesNoContent()
})
//update local bucket replication config item
api.UserAPIUpdateMultiBucketReplicationHandler = user_api.UpdateMultiBucketReplicationHandlerFunc(func(params user_api.UpdateMultiBucketReplicationParams, session *models.Principal) middleware.Responder {
err := updateBucketReplicationResponse(session, params)
@@ -591,6 +602,26 @@ func deleteReplicationRule(ctx context.Context, session *models.Principal, bucke
return nil
}
func deleteAllReplicationRules(ctx context.Context, session *models.Principal, bucketName string) error {
s3Client, err := newS3BucketClient(session, bucketName, "")
if err != nil {
LogError("error creating S3Client: %v", err)
return err
}
// create a mc S3Client interface implementation
// defining the client to be used
mcClient := mcClient{client: s3Client}
err2 := mcClient.deleteAllReplicationRules(ctx)
if err2 != nil {
return err
}
return nil
}
func deleteReplicationRuleResponse(session *models.Principal, params user_api.DeleteBucketReplicationRuleParams) *models.Error {
ctx := context.Background()
@@ -602,6 +633,17 @@ func deleteReplicationRuleResponse(session *models.Principal, params user_api.De
return nil
}
func deleteBucketReplicationRulesResponse(session *models.Principal, params user_api.DeleteAllReplicationRulesParams) *models.Error {
ctx := context.Background()
err := deleteAllReplicationRules(ctx, session, params.BucketName)
if err != nil {
return prepareError(err)
}
return nil
}
func updateBucketReplicationResponse(session *models.Principal, params user_api.UpdateMultiBucketReplicationParams) *models.Error {
ctx := context.Background()

View File

@@ -262,6 +262,10 @@ func (c mcClient) setReplication(ctx context.Context, cfg *replication.Config, o
return c.client.SetReplication(ctx, cfg, opts)
}
func (c mcClient) deleteAllReplicationRules(ctx context.Context) *probe.Error {
return c.client.RemoveReplication(ctx)
}
func (c mcClient) setVersioning(ctx context.Context, status string) *probe.Error {
return c.client.SetVersion(ctx, status)
}

View File

@@ -776,6 +776,34 @@ func init() {
}
}
},
"/buckets/{bucket_name}/delete-all-replication-rules": {
"delete": {
"tags": [
"UserAPI"
],
"summary": "Deletes all replication rules on a bucket",
"operationId": "DeleteAllReplicationRules",
"parameters": [
{
"type": "string",
"name": "bucket_name",
"in": "path",
"required": true
}
],
"responses": {
"204": {
"description": "A successful response."
},
"default": {
"description": "Generic error response.",
"schema": {
"$ref": "#/definitions/error"
}
}
}
}
},
"/buckets/{bucket_name}/delete-objects": {
"post": {
"tags": [
@@ -7192,6 +7220,34 @@ func init() {
}
}
},
"/buckets/{bucket_name}/delete-all-replication-rules": {
"delete": {
"tags": [
"UserAPI"
],
"summary": "Deletes all replication rules on a bucket",
"operationId": "DeleteAllReplicationRules",
"parameters": [
{
"type": "string",
"name": "bucket_name",
"in": "path",
"required": true
}
],
"responses": {
"204": {
"description": "A successful response."
},
"default": {
"description": "Generic error response.",
"schema": {
"$ref": "#/definitions/error"
}
}
}
}
},
"/buckets/{bucket_name}/delete-objects": {
"post": {
"tags": [

View File

@@ -134,6 +134,9 @@ func NewConsoleAPI(spec *loads.Document) *ConsoleAPI {
AdminAPIDeleteAccessRuleWithBucketHandler: admin_api.DeleteAccessRuleWithBucketHandlerFunc(func(params admin_api.DeleteAccessRuleWithBucketParams, principal *models.Principal) middleware.Responder {
return middleware.NotImplemented("operation admin_api.DeleteAccessRuleWithBucket has not yet been implemented")
}),
UserAPIDeleteAllReplicationRulesHandler: user_api.DeleteAllReplicationRulesHandlerFunc(func(params user_api.DeleteAllReplicationRulesParams, principal *models.Principal) middleware.Responder {
return middleware.NotImplemented("operation user_api.DeleteAllReplicationRules has not yet been implemented")
}),
UserAPIDeleteBucketHandler: user_api.DeleteBucketHandlerFunc(func(params user_api.DeleteBucketParams, principal *models.Principal) middleware.Responder {
return middleware.NotImplemented("operation user_api.DeleteBucket has not yet been implemented")
}),
@@ -502,6 +505,8 @@ type ConsoleAPI struct {
AdminAPIDashboardWidgetDetailsHandler admin_api.DashboardWidgetDetailsHandler
// AdminAPIDeleteAccessRuleWithBucketHandler sets the operation handler for the delete access rule with bucket operation
AdminAPIDeleteAccessRuleWithBucketHandler admin_api.DeleteAccessRuleWithBucketHandler
// UserAPIDeleteAllReplicationRulesHandler sets the operation handler for the delete all replication rules operation
UserAPIDeleteAllReplicationRulesHandler user_api.DeleteAllReplicationRulesHandler
// UserAPIDeleteBucketHandler sets the operation handler for the delete bucket operation
UserAPIDeleteBucketHandler user_api.DeleteBucketHandler
// UserAPIDeleteBucketEventHandler sets the operation handler for the delete bucket event operation
@@ -836,6 +841,9 @@ func (o *ConsoleAPI) Validate() error {
if o.AdminAPIDeleteAccessRuleWithBucketHandler == nil {
unregistered = append(unregistered, "admin_api.DeleteAccessRuleWithBucketHandler")
}
if o.UserAPIDeleteAllReplicationRulesHandler == nil {
unregistered = append(unregistered, "user_api.DeleteAllReplicationRulesHandler")
}
if o.UserAPIDeleteBucketHandler == nil {
unregistered = append(unregistered, "user_api.DeleteBucketHandler")
}
@@ -1300,6 +1308,10 @@ func (o *ConsoleAPI) initHandlerCache() {
if o.handlers["DELETE"] == nil {
o.handlers["DELETE"] = make(map[string]http.Handler)
}
o.handlers["DELETE"]["/buckets/{bucket_name}/delete-all-replication-rules"] = user_api.NewDeleteAllReplicationRules(o.context, o.UserAPIDeleteAllReplicationRulesHandler)
if o.handlers["DELETE"] == nil {
o.handlers["DELETE"] = make(map[string]http.Handler)
}
o.handlers["DELETE"]["/buckets/{name}"] = user_api.NewDeleteBucket(o.context, o.UserAPIDeleteBucketHandler)
if o.handlers["DELETE"] == nil {
o.handlers["DELETE"] = 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"
)
// DeleteAllReplicationRulesHandlerFunc turns a function with the right signature into a delete all replication rules handler
type DeleteAllReplicationRulesHandlerFunc func(DeleteAllReplicationRulesParams, *models.Principal) middleware.Responder
// Handle executing the request and returning a response
func (fn DeleteAllReplicationRulesHandlerFunc) Handle(params DeleteAllReplicationRulesParams, principal *models.Principal) middleware.Responder {
return fn(params, principal)
}
// DeleteAllReplicationRulesHandler interface for that can handle valid delete all replication rules params
type DeleteAllReplicationRulesHandler interface {
Handle(DeleteAllReplicationRulesParams, *models.Principal) middleware.Responder
}
// NewDeleteAllReplicationRules creates a new http.Handler for the delete all replication rules operation
func NewDeleteAllReplicationRules(ctx *middleware.Context, handler DeleteAllReplicationRulesHandler) *DeleteAllReplicationRules {
return &DeleteAllReplicationRules{Context: ctx, Handler: handler}
}
/* DeleteAllReplicationRules swagger:route DELETE /buckets/{bucket_name}/delete-all-replication-rules UserAPI deleteAllReplicationRules
Deletes all replication rules on a bucket
*/
type DeleteAllReplicationRules struct {
Context *middleware.Context
Handler DeleteAllReplicationRulesHandler
}
func (o *DeleteAllReplicationRules) ServeHTTP(rw http.ResponseWriter, r *http.Request) {
route, rCtx, _ := o.Context.RouteInfo(r)
if rCtx != nil {
*r = *rCtx
}
var Params = NewDeleteAllReplicationRulesParams()
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,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 swagger generate command
import (
"net/http"
"github.com/go-openapi/errors"
"github.com/go-openapi/runtime/middleware"
"github.com/go-openapi/strfmt"
)
// NewDeleteAllReplicationRulesParams creates a new DeleteAllReplicationRulesParams object
//
// There are no default values defined in the spec.
func NewDeleteAllReplicationRulesParams() DeleteAllReplicationRulesParams {
return DeleteAllReplicationRulesParams{}
}
// DeleteAllReplicationRulesParams contains all the bound params for the delete all replication rules operation
// typically these are obtained from a http.Request
//
// swagger:parameters DeleteAllReplicationRules
type DeleteAllReplicationRulesParams struct {
// HTTP Request Object
HTTPRequest *http.Request `json:"-"`
/*
Required: true
In: path
*/
BucketName string
}
// 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 NewDeleteAllReplicationRulesParams() beforehand.
func (o *DeleteAllReplicationRulesParams) BindRequest(r *http.Request, route *middleware.MatchedRoute) error {
var res []error
o.HTTPRequest = r
rBucketName, rhkBucketName, _ := route.Params.GetOK("bucket_name")
if err := o.bindBucketName(rBucketName, rhkBucketName, route.Formats); err != nil {
res = append(res, err)
}
if len(res) > 0 {
return errors.CompositeValidationError(res...)
}
return nil
}
// bindBucketName binds and validates parameter BucketName from path.
func (o *DeleteAllReplicationRulesParams) bindBucketName(rawData []string, hasKey bool, formats strfmt.Registry) error {
var raw string
if len(rawData) > 0 {
raw = rawData[len(rawData)-1]
}
// Required: true
// Parameter is provided by construction from the route
o.BucketName = raw
return nil
}

View File

@@ -0,0 +1,113 @@
// 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"
)
// DeleteAllReplicationRulesNoContentCode is the HTTP code returned for type DeleteAllReplicationRulesNoContent
const DeleteAllReplicationRulesNoContentCode int = 204
/*DeleteAllReplicationRulesNoContent A successful response.
swagger:response deleteAllReplicationRulesNoContent
*/
type DeleteAllReplicationRulesNoContent struct {
}
// NewDeleteAllReplicationRulesNoContent creates DeleteAllReplicationRulesNoContent with default headers values
func NewDeleteAllReplicationRulesNoContent() *DeleteAllReplicationRulesNoContent {
return &DeleteAllReplicationRulesNoContent{}
}
// WriteResponse to the client
func (o *DeleteAllReplicationRulesNoContent) WriteResponse(rw http.ResponseWriter, producer runtime.Producer) {
rw.Header().Del(runtime.HeaderContentType) //Remove Content-Type on empty responses
rw.WriteHeader(204)
}
/*DeleteAllReplicationRulesDefault Generic error response.
swagger:response deleteAllReplicationRulesDefault
*/
type DeleteAllReplicationRulesDefault struct {
_statusCode int
/*
In: Body
*/
Payload *models.Error `json:"body,omitempty"`
}
// NewDeleteAllReplicationRulesDefault creates DeleteAllReplicationRulesDefault with default headers values
func NewDeleteAllReplicationRulesDefault(code int) *DeleteAllReplicationRulesDefault {
if code <= 0 {
code = 500
}
return &DeleteAllReplicationRulesDefault{
_statusCode: code,
}
}
// WithStatusCode adds the status to the delete all replication rules default response
func (o *DeleteAllReplicationRulesDefault) WithStatusCode(code int) *DeleteAllReplicationRulesDefault {
o._statusCode = code
return o
}
// SetStatusCode sets the status to the delete all replication rules default response
func (o *DeleteAllReplicationRulesDefault) SetStatusCode(code int) {
o._statusCode = code
}
// WithPayload adds the payload to the delete all replication rules default response
func (o *DeleteAllReplicationRulesDefault) WithPayload(payload *models.Error) *DeleteAllReplicationRulesDefault {
o.Payload = payload
return o
}
// SetPayload sets the payload to the delete all replication rules default response
func (o *DeleteAllReplicationRulesDefault) SetPayload(payload *models.Error) {
o.Payload = payload
}
// WriteResponse to the client
func (o *DeleteAllReplicationRulesDefault) 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,116 @@
// 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"
"strings"
)
// DeleteAllReplicationRulesURL generates an URL for the delete all replication rules operation
type DeleteAllReplicationRulesURL struct {
BucketName string
_basePath string
// avoid unkeyed usage
_ struct{}
}
// 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 *DeleteAllReplicationRulesURL) WithBasePath(bp string) *DeleteAllReplicationRulesURL {
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 *DeleteAllReplicationRulesURL) SetBasePath(bp string) {
o._basePath = bp
}
// Build a url path and query string
func (o *DeleteAllReplicationRulesURL) Build() (*url.URL, error) {
var _result url.URL
var _path = "/buckets/{bucket_name}/delete-all-replication-rules"
bucketName := o.BucketName
if bucketName != "" {
_path = strings.Replace(_path, "{bucket_name}", bucketName, -1)
} else {
return nil, errors.New("bucketName is required on DeleteAllReplicationRulesURL")
}
_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 *DeleteAllReplicationRulesURL) 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 *DeleteAllReplicationRulesURL) String() string {
return o.Must(o.Build()).String()
}
// BuildFull builds a full url with scheme, host, path and query string
func (o *DeleteAllReplicationRulesURL) BuildFull(scheme, host string) (*url.URL, error) {
if scheme == "" {
return nil, errors.New("scheme is required for a full url on DeleteAllReplicationRulesURL")
}
if host == "" {
return nil, errors.New("host is required for a full url on DeleteAllReplicationRulesURL")
}
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 *DeleteAllReplicationRulesURL) StringFull(scheme, host string) string {
return o.Must(o.BuildFull(scheme, host)).String()
}