Adding delete remote bucket functionality (#1762)

This commit is contained in:
adfost
2022-03-28 15:36:23 -07:00
committed by GitHub
parent fcd50257ee
commit d1a5e5ba57
13 changed files with 962 additions and 54 deletions

View File

@@ -2688,6 +2688,34 @@ func DeletesAllReplicationRulesOnABucket(bucketName string) (*http.Response, err
return response, err
}
func DeleteMultipleReplicationRules(bucketName string, rules []string) (*http.Response, error) {
/*
Helper function to delete multiple replication rules in a bucket
URL: /buckets/{bucket_name}/delete-multiple-replication-rules
HTTP Verb: DELETE
*/
body := map[string]interface{}{
"rules": rules,
}
requestDataJSON, _ := json.Marshal(body)
requestDataBody := bytes.NewReader(requestDataJSON)
request, err := http.NewRequest(
"DELETE",
"http://localhost:9090/api/v1/buckets/"+bucketName+"/delete-selected-replication-rules",
requestDataBody,
)
if err != nil {
log.Println(err)
}
request.Header.Add("Cookie", fmt.Sprintf("token=%s", token))
request.Header.Add("Content-Type", "application/json")
client := &http.Client{
Timeout: 2 * time.Second,
}
response, err := client.Do(request)
return response, err
}
func DeleteBucketReplicationRule(bucketName string, ruleID string) (*http.Response, error) {
/*
Helper function to delete a bucket's replication rule
@@ -2716,7 +2744,7 @@ func TestReplication(t *testing.T) {
// Vars
assert := assert.New(t)
originBucket := "testputobjectslegalholdstatus"
destinationBuckets := []string{"testgetbucketquota", "testputbucketquota"} // an array of strings to iterate over
destinationBuckets := []string{"testgetbucketquota", "testputbucketquota", "testlistbucketevents"} // an array of strings to iterate over
// 1. Set replication rules with DIFFERENT PRIORITY <------- NOT SAME BUT DIFFERENT! 1, 2, etc.
for index, destinationBucket := range destinationBuckets {
@@ -2750,7 +2778,7 @@ func TestReplication(t *testing.T) {
}
// 2. Get replication, at this point two rules are expected
// 2. Get replication, at this point four rules are expected
response, err := GetBucketReplication(originBucket)
assert.Nil(err)
if err != nil {
@@ -2775,17 +2803,17 @@ func TestReplication(t *testing.T) {
return
}
// 4. Verify rules are enabled
for index := 0; index < 2; index++ {
for index := 0; index < 3; index++ {
Status := structBucketRepl.Rules[index].Status
assert.Equal(Status, "Enabled")
}
// 5. Delete 2nd rule only with dedicated end point for single rules:
// 5. Delete 3rd and 4th rules with endpoint for multiple rules:
// /buckets/{bucket_name}/replication/{rule_id}
ruleID := structBucketRepl.Rules[1].ID // To delete 2nd rule in a single way
response, err = DeleteBucketReplicationRule(
ruleIDs := []string{structBucketRepl.Rules[2].ID} // To delete 3rd rule with the multi delete function
response, err = DeleteMultipleReplicationRules(
originBucket,
ruleID,
ruleIDs,
)
assert.Nil(err)
if err != nil {
@@ -2797,7 +2825,24 @@ func TestReplication(t *testing.T) {
assert.Equal(204, response.StatusCode, finalResponse)
}
// 6. Delete remaining Bucket Replication Rule with generic end point:
// 6. Delete 2nd rule only with dedicated end point for single rules:
// /buckets/{bucket_name}/replication/{rule_id}
ruleID := structBucketRepl.Rules[1].ID // To delete 2nd rule in a single way
response, err = DeleteBucketReplicationRule(
originBucket,
ruleID,
)
assert.Nil(err)
if err != nil {
log.Println(err)
return
}
finalResponse = inspectHTTPResponse(response)
if response != nil {
assert.Equal(204, response.StatusCode, finalResponse)
}
// 7. Delete remaining Bucket Replication Rule with generic end point:
// /buckets/{bucket_name}/delete-all-replication-rules
response, err = DeletesAllReplicationRulesOnABucket(
originBucket,
@@ -2812,6 +2857,27 @@ func TestReplication(t *testing.T) {
assert.Equal(204, response.StatusCode, finalResponse)
}
// 8. Get replication, at this point zero rules are expected
response, err = GetBucketReplication(originBucket)
assert.Nil(err)
if err != nil {
log.Println(err)
return
}
if response != nil {
assert.Equal(200, response.StatusCode, "error invalid status")
}
// 9. Get rule ID and status from response's body
bodyBytes, _ = ioutil.ReadAll(response.Body)
structBucketRepl = models.BucketReplicationResponse{}
err = json.Unmarshal(bodyBytes, &structBucketRepl)
if err != nil {
log.Println(err)
assert.Nil(err)
}
assert.Equal(len(structBucketRepl.Rules), 0, "Delete failed")
}
func GetBucketVersioning(bucketName string) (*http.Response, error) {

View File

@@ -0,0 +1,67 @@
// Code generated by go-swagger; DO NOT EDIT.
// This file is part of MinIO Console Server
// Copyright (c) 2022 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 models
// This file was generated by the swagger tool.
// Editing this file might prove futile when you re-run the swagger generate command
import (
"context"
"github.com/go-openapi/strfmt"
"github.com/go-openapi/swag"
)
// BucketReplicationRuleList bucket replication rule list
//
// swagger:model bucketReplicationRuleList
type BucketReplicationRuleList struct {
// rules
Rules []string `json:"rules"`
}
// Validate validates this bucket replication rule list
func (m *BucketReplicationRuleList) Validate(formats strfmt.Registry) error {
return nil
}
// ContextValidate validates this bucket replication rule list based on context it is used
func (m *BucketReplicationRuleList) ContextValidate(ctx context.Context, formats strfmt.Registry) error {
return nil
}
// MarshalBinary interface implementation
func (m *BucketReplicationRuleList) MarshalBinary() ([]byte, error) {
if m == nil {
return nil, nil
}
return swag.WriteJSON(m)
}
// UnmarshalBinary interface implementation
func (m *BucketReplicationRuleList) UnmarshalBinary(b []byte) error {
var res BucketReplicationRuleList
if err := swag.ReadJSON(b, &res); err != nil {
return err
}
*m = res
return nil
}

View File

@@ -87,7 +87,8 @@ const BucketReplicationPanel = ({
const [editReplicationModal, setEditReplicationModal] =
useState<boolean>(false);
const [selectedRRule, setSelectedRRule] = useState<string>("");
const [deleteAllRules, setDeleteAllRules] = useState<boolean>(false);
const [selectedRepRules, setSelectedRepRules] = useState<string[]>([]);
const [deleteSelectedRules, setDeleteSelectedRules] = useState<boolean>(false);
const bucketName = match.params["bucketName"];
@@ -156,13 +157,13 @@ const BucketReplicationPanel = ({
const confirmDeleteReplication = (replication: BucketReplicationRule) => {
setSelectedRRule(replication.id);
setDeleteAllRules(false);
setDeleteSelectedRules(false);
setDeleteReplicationModal(true);
};
const confirmDeleteAllReplicationRules = () => {
setSelectedRRule("allRules");
setDeleteAllRules(true);
const confirmDeleteSelectedReplicationRules = () => {
setSelectedRRule("selectedRules");
setDeleteSelectedRules(true);
setDeleteReplicationModal(true);
};
@@ -179,6 +180,34 @@ const BucketReplicationPanel = ({
return <Fragment>{events && events.tags !== "" ? "Yes" : "No"}</Fragment>;
};
const selectAllItems = () => {
if (selectedRepRules.length === replicationRules.length) {
setSelectedRepRules([]);
return;
}
setSelectedRepRules(replicationRules.map(x => x.id))
};
const selectRules = (
e: React.ChangeEvent<HTMLInputElement>,
) => {
const targetD = e.target;
const value = targetD.value;
const checked = targetD.checked;
let elements: string[] = [...selectedRepRules]; // We clone the selectedSAs array
if (checked) {
// If the user has checked this field we need to push this to selectedSAs
elements.push(value);
} else {
// User has unchecked this field, we need to remove it from the list
elements = elements.filter((element) => element !== value);
}
setSelectedRepRules(elements);
return elements;
};
const replicationTableActions: any = [
{
type: "delete",
@@ -212,8 +241,10 @@ const BucketReplicationPanel = ({
selectedBucket={bucketName}
closeDeleteModalAndRefresh={closeReplicationModalDelete}
ruleToDelete={selectedRRule}
rulesToDelete={selectedRepRules}
remainingRules={replicationRules.length}
deleteAllRules={deleteAllRules}
allSelected={selectedRepRules.length === replicationRules.length}
deleteSelectedRules={deleteSelectedRules}
/>
)}
@@ -236,15 +267,15 @@ const BucketReplicationPanel = ({
errorProps={{ disabled: true }}
>
<RBIconButton
tooltip={"Delete All Replication Rules"}
tooltip={"Remove Selected Replication Rules"}
onClick={() => {
confirmDeleteAllReplicationRules();
confirmDeleteSelectedReplicationRules();
}}
text={"Delete All Rules"}
text={"Remove Selected Rules"}
icon={<TrashIcon />}
color={"secondary"}
variant={"outlined"}
disabled={replicationRules.length === 0}
disabled={selectedRepRules.length === 0}
/>
</SecureComponent>
<SecureComponent
@@ -305,6 +336,9 @@ const BucketReplicationPanel = ({
idField="id"
customPaperHeight={classes.twHeight}
textSelectable
selectedItems={selectedRepRules}
onSelect={(e) => selectRules(e)}
onSelectAll={selectAllItems}
/>
</SecureComponent>
</Grid>

View File

@@ -24,14 +24,17 @@ import ConfirmDialog from "../../Common/ModalWrapper/ConfirmDialog";
import { ConfirmDeleteIcon } from "../../../../icons";
import Grid from "@mui/material/Grid";
import InputBoxWrapper from "../../Common/FormComponents/InputBoxWrapper/InputBoxWrapper";
import WarningMessage from "../../Common/WarningMessage/WarningMessage";
interface IDeleteReplicationProps {
closeDeleteModalAndRefresh: (refresh: boolean) => void;
deleteOpen: boolean;
selectedBucket: string;
ruleToDelete?: string;
rulesToDelete?: string[];
remainingRules: number;
deleteAllRules?: boolean;
allSelected: boolean;
deleteSelectedRules?: boolean;
setErrorSnackMessage: typeof setErrorSnackMessage;
}
@@ -40,9 +43,11 @@ const DeleteReplicationRule = ({
deleteOpen,
selectedBucket,
ruleToDelete,
rulesToDelete,
remainingRules,
allSelected,
setErrorSnackMessage,
deleteAllRules = false,
deleteSelectedRules = false,
}: IDeleteReplicationProps) => {
const [confirmationText, setConfirmationText] = useState<string>("");
@@ -59,18 +64,26 @@ const DeleteReplicationRule = ({
const onConfirmDelete = () => {
let url = `/api/v1/buckets/${selectedBucket}/replication/${ruleToDelete}`;
if (deleteAllRules || remainingRules === 1) {
if (deleteSelectedRules) {
if (allSelected) {
url = `/api/v1/buckets/${selectedBucket}/delete-all-replication-rules`;
} else {
url = `/api/v1/buckets/${selectedBucket}/delete-selected-replication-rules`;
invokeDeleteApi("DELETE", url, {rules: rulesToDelete});
return
}
} else if (remainingRules === 1) {
url = `/api/v1/buckets/${selectedBucket}/delete-all-replication-rules`;
}
invokeDeleteApi("DELETE", url);
invokeDeleteApi("DELETE", url)
};
return (
<ConfirmDialog
title={
deleteAllRules
? "Delete all Replication Rules"
deleteSelectedRules
? "Delete Selected Replication Rules"
: "Delete Replication Rule"
}
confirmText={"Delete"}
@@ -80,15 +93,20 @@ const DeleteReplicationRule = ({
onConfirm={onConfirmDelete}
onClose={onClose}
confirmButtonProps={{
disabled: deleteAllRules && confirmationText !== "Yes, I am sure",
disabled: deleteSelectedRules && confirmationText !== "Yes, I am sure",
}}
confirmationContent={
<DialogContentText>
{deleteAllRules ? (
{deleteSelectedRules ? (
<Fragment>
Are you sure you want to remove all replication rules for bucket{" "}
<WarningMessage
title={"Warning"}
label={"The corresponding remote buckets will also be deleted."}
/>
Are you sure you want to remove the selected replication rules for bucket{" "}
<b>{selectedBucket}</b>?<br />
<br />
To continue please type <b>Yes, I am sure</b> in the box.
<Grid item xs={12}>
<InputBoxWrapper
@@ -104,6 +122,10 @@ const DeleteReplicationRule = ({
</Fragment>
) : (
<Fragment>
<WarningMessage
title={"Warning"}
label={"The corresponding remote bucket will also be deleted."}
/>
Are you sure you want to delete replication rule{" "}
<b>{ruleToDelete}</b>?
</Fragment>

View File

@@ -120,6 +120,17 @@ func registerAdminBucketRemoteHandlers(api *operations.ConsoleAPI) {
return user_api.NewDeleteAllReplicationRulesNoContent()
})
// delete selected replication rules for a bucket
api.UserAPIDeleteSelectedReplicationRulesHandler = user_api.DeleteSelectedReplicationRulesHandlerFunc(func(params user_api.DeleteSelectedReplicationRulesParams, session *models.Principal) middleware.Responder {
err := deleteSelectedReplicationRulesResponse(session, params)
if err != nil {
return user_api.NewDeleteSelectedReplicationRulesDefault(500).WithPayload(err)
}
return user_api.NewDeleteSelectedReplicationRulesNoContent()
})
//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)
@@ -567,6 +578,29 @@ func listExternalBucketsResponse(params user_api.ListExternalBucketsParams) (*mo
return listBucketsResponse, nil
}
func getARNFromID(conf *replication.Config, rule string) string {
for i := range conf.Rules {
if conf.Rules[i].ID == rule {
return conf.Rules[i].Destination.Bucket
}
}
return ""
}
func getARNsFromIDs(conf *replication.Config, rules []string) []string {
temp := make(map[string]string)
for i := range conf.Rules {
temp[conf.Rules[i].ID] = conf.Rules[i].Destination.Bucket
}
var retval []string
for i := range rules {
if val, ok := temp[rules[i]]; ok {
retval = append(retval, val)
}
}
return retval
}
func deleteReplicationRule(ctx context.Context, session *models.Principal, bucketName, ruleID string) error {
mClient, err := newMinioClient(session)
if err != nil {
@@ -582,6 +616,103 @@ func deleteReplicationRule(ctx context.Context, session *models.Principal, bucke
LogError("error versioning bucket: %v", err)
}
s3Client, err := newS3BucketClient(session, bucketName, "")
if err != nil {
LogError("error creating S3Client: %v", err)
return err
}
mAdmin, err := NewMinioAdminClient(session)
if err != nil {
LogError("error creating Admin Client: %v", err)
return err
}
admClient := AdminClient{Client: mAdmin}
err3 := deleteRemoteBucket(ctx, admClient, bucketName, getARNFromID(&cfg, ruleID))
if err3 != nil {
return err3
}
// create a mc S3Client interface implementation
// defining the client to be used
mcClient := mcClient{client: s3Client}
opts := replication.Options{
ID: ruleID,
Op: replication.RemoveOption,
}
err2 := mcClient.setReplication(ctx, &cfg, opts)
if err2 != nil {
return err2.Cause
}
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}
mClient, err := newMinioClient(session)
if err != nil {
LogError("error creating MinIO Client: %v", err)
return err
}
// create a minioClient interface implementation
// defining the client to be used
minClient := minioClient{client: mClient}
cfg, err := minClient.getBucketReplication(ctx, bucketName)
if err != nil {
LogError("error versioning bucket: %v", err)
}
mAdmin, err := NewMinioAdminClient(session)
if err != nil {
LogError("error creating Admin Client: %v", err)
return err
}
admClient := AdminClient{Client: mAdmin}
for i := range cfg.Rules {
err3 := deleteRemoteBucket(ctx, admClient, bucketName, cfg.Rules[i].Destination.Bucket)
if err3 != nil {
return err3
}
}
err2 := mcClient.deleteAllReplicationRules(ctx)
if err2 != nil {
return err
}
return nil
}
func deleteSelectedReplicationRules(ctx context.Context, session *models.Principal, bucketName string, rules []string) error {
mClient, err := newMinioClient(session)
if err != nil {
LogError("error creating MinIO Client: %v", err)
return err
}
// create a minioClient interface implementation
// defining the client to be used
minClient := minioClient{client: mClient}
cfg, err := minClient.getBucketReplication(ctx, bucketName)
if err != nil {
LogError("error versioning bucket: %v", err)
}
s3Client, err := newS3BucketClient(session, bucketName, "")
if err != nil {
LogError("error creating S3Client: %v", err)
@@ -591,36 +722,31 @@ func deleteReplicationRule(ctx context.Context, session *models.Principal, bucke
// defining the client to be used
mcClient := mcClient{client: s3Client}
opts := replication.Options{
ID: ruleID,
Op: replication.RemoveOption,
}
err2 := mcClient.setReplication(ctx, &cfg, opts)
if err2 != nil {
return err2.Cause
}
return nil
}
func deleteAllReplicationRules(ctx context.Context, session *models.Principal, bucketName string) error {
s3Client, err := newS3BucketClient(session, bucketName, "")
mAdmin, err := NewMinioAdminClient(session)
if err != nil {
LogError("error creating S3Client: %v", err)
LogError("error creating Admin Client: %v", err)
return err
}
// create a mc S3Client interface implementation
// defining the client to be used
mcClient := mcClient{client: s3Client}
admClient := AdminClient{Client: mAdmin}
err2 := mcClient.deleteAllReplicationRules(ctx)
ARNs := getARNsFromIDs(&cfg, rules)
if err2 != nil {
return err
for i := range rules {
err3 := deleteRemoteBucket(ctx, admClient, bucketName, ARNs[i])
if err3 != nil {
return err3
}
opts := replication.Options{
ID: rules[i],
Op: replication.RemoveOption,
}
err2 := mcClient.setReplication(ctx, &cfg, opts)
if err2 != nil {
return err2.Cause
}
}
return nil
}
func deleteReplicationRuleResponse(session *models.Principal, params user_api.DeleteBucketReplicationRuleParams) *models.Error {
@@ -645,6 +771,17 @@ func deleteBucketReplicationRulesResponse(session *models.Principal, params user
return nil
}
func deleteSelectedReplicationRulesResponse(session *models.Principal, params user_api.DeleteSelectedReplicationRulesParams) *models.Error {
ctx := context.Background()
err := deleteSelectedReplicationRules(ctx, session, params.BucketName, params.Rules.Rules)
if err != nil {
return prepareError(err)
}
return nil
}
func updateBucketReplicationResponse(session *models.Principal, params user_api.UpdateMultiBucketReplicationParams) *models.Error {
ctx := context.Background()

View File

@@ -781,7 +781,7 @@ func init() {
"tags": [
"UserAPI"
],
"summary": "Deletes all replication rules on a bucket",
"summary": "Deletes all replication rules from a bucket",
"operationId": "DeleteAllReplicationRules",
"parameters": [
{
@@ -848,6 +848,42 @@ func init() {
}
}
},
"/buckets/{bucket_name}/delete-selected-replication-rules": {
"delete": {
"tags": [
"UserAPI"
],
"summary": "Deletes selected replication rules from a bucket",
"operationId": "DeleteSelectedReplicationRules",
"parameters": [
{
"type": "string",
"name": "bucket_name",
"in": "path",
"required": true
},
{
"name": "rules",
"in": "body",
"required": true,
"schema": {
"$ref": "#/definitions/bucketReplicationRuleList"
}
}
],
"responses": {
"204": {
"description": "A successful response."
},
"default": {
"description": "Generic error response.",
"schema": {
"$ref": "#/definitions/error"
}
}
}
}
},
"/buckets/{bucket_name}/encryption/disable": {
"post": {
"tags": [
@@ -4535,6 +4571,17 @@ func init() {
}
}
},
"bucketReplicationRuleList": {
"type": "object",
"properties": {
"rules": {
"type": "array",
"items": {
"type": "string"
}
}
}
},
"bucketVersioningResponse": {
"type": "object",
"properties": {
@@ -7270,7 +7317,7 @@ func init() {
"tags": [
"UserAPI"
],
"summary": "Deletes all replication rules on a bucket",
"summary": "Deletes all replication rules from a bucket",
"operationId": "DeleteAllReplicationRules",
"parameters": [
{
@@ -7337,6 +7384,42 @@ func init() {
}
}
},
"/buckets/{bucket_name}/delete-selected-replication-rules": {
"delete": {
"tags": [
"UserAPI"
],
"summary": "Deletes selected replication rules from a bucket",
"operationId": "DeleteSelectedReplicationRules",
"parameters": [
{
"type": "string",
"name": "bucket_name",
"in": "path",
"required": true
},
{
"name": "rules",
"in": "body",
"required": true,
"schema": {
"$ref": "#/definitions/bucketReplicationRuleList"
}
}
],
"responses": {
"204": {
"description": "A successful response."
},
"default": {
"description": "Generic error response.",
"schema": {
"$ref": "#/definitions/error"
}
}
}
}
},
"/buckets/{bucket_name}/encryption/disable": {
"post": {
"tags": [
@@ -11150,6 +11233,17 @@ func init() {
}
}
},
"bucketReplicationRuleList": {
"type": "object",
"properties": {
"rules": {
"type": "array",
"items": {
"type": "string"
}
}
}
},
"bucketVersioningResponse": {
"type": "object",
"properties": {

View File

@@ -171,6 +171,9 @@ func NewConsoleAPI(spec *loads.Document) *ConsoleAPI {
UserAPIDeleteRemoteBucketHandler: user_api.DeleteRemoteBucketHandlerFunc(func(params user_api.DeleteRemoteBucketParams, principal *models.Principal) middleware.Responder {
return middleware.NotImplemented("operation user_api.DeleteRemoteBucket has not yet been implemented")
}),
UserAPIDeleteSelectedReplicationRulesHandler: user_api.DeleteSelectedReplicationRulesHandlerFunc(func(params user_api.DeleteSelectedReplicationRulesParams, principal *models.Principal) middleware.Responder {
return middleware.NotImplemented("operation user_api.DeleteSelectedReplicationRules has not yet been implemented")
}),
UserAPIDeleteServiceAccountHandler: user_api.DeleteServiceAccountHandlerFunc(func(params user_api.DeleteServiceAccountParams, principal *models.Principal) middleware.Responder {
return middleware.NotImplemented("operation user_api.DeleteServiceAccount has not yet been implemented")
}),
@@ -537,6 +540,8 @@ type ConsoleAPI struct {
UserAPIDeleteObjectRetentionHandler user_api.DeleteObjectRetentionHandler
// UserAPIDeleteRemoteBucketHandler sets the operation handler for the delete remote bucket operation
UserAPIDeleteRemoteBucketHandler user_api.DeleteRemoteBucketHandler
// UserAPIDeleteSelectedReplicationRulesHandler sets the operation handler for the delete selected replication rules operation
UserAPIDeleteSelectedReplicationRulesHandler user_api.DeleteSelectedReplicationRulesHandler
// UserAPIDeleteServiceAccountHandler sets the operation handler for the delete service account operation
UserAPIDeleteServiceAccountHandler user_api.DeleteServiceAccountHandler
// UserAPIDisableBucketEncryptionHandler sets the operation handler for the disable bucket encryption operation
@@ -889,6 +894,9 @@ func (o *ConsoleAPI) Validate() error {
if o.UserAPIDeleteRemoteBucketHandler == nil {
unregistered = append(unregistered, "user_api.DeleteRemoteBucketHandler")
}
if o.UserAPIDeleteSelectedReplicationRulesHandler == nil {
unregistered = append(unregistered, "user_api.DeleteSelectedReplicationRulesHandler")
}
if o.UserAPIDeleteServiceAccountHandler == nil {
unregistered = append(unregistered, "user_api.DeleteServiceAccountHandler")
}
@@ -1372,6 +1380,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-selected-replication-rules"] = user_api.NewDeleteSelectedReplicationRules(o.context, o.UserAPIDeleteSelectedReplicationRulesHandler)
if o.handlers["DELETE"] == nil {
o.handlers["DELETE"] = make(map[string]http.Handler)
}
o.handlers["DELETE"]["/service-accounts/{access_key}"] = user_api.NewDeleteServiceAccount(o.context, o.UserAPIDeleteServiceAccountHandler)
if o.handlers["POST"] == nil {
o.handlers["POST"] = make(map[string]http.Handler)

View File

@@ -50,7 +50,7 @@ func NewDeleteAllReplicationRules(ctx *middleware.Context, handler DeleteAllRepl
/* DeleteAllReplicationRules swagger:route DELETE /buckets/{bucket_name}/delete-all-replication-rules UserAPI deleteAllReplicationRules
Deletes all replication rules on a bucket
Deletes all replication rules from a bucket
*/
type DeleteAllReplicationRules struct {

View File

@@ -0,0 +1,88 @@
// Code generated by go-swagger; DO NOT EDIT.
// This file is part of MinIO Console Server
// Copyright (c) 2022 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"
)
// DeleteSelectedReplicationRulesHandlerFunc turns a function with the right signature into a delete selected replication rules handler
type DeleteSelectedReplicationRulesHandlerFunc func(DeleteSelectedReplicationRulesParams, *models.Principal) middleware.Responder
// Handle executing the request and returning a response
func (fn DeleteSelectedReplicationRulesHandlerFunc) Handle(params DeleteSelectedReplicationRulesParams, principal *models.Principal) middleware.Responder {
return fn(params, principal)
}
// DeleteSelectedReplicationRulesHandler interface for that can handle valid delete selected replication rules params
type DeleteSelectedReplicationRulesHandler interface {
Handle(DeleteSelectedReplicationRulesParams, *models.Principal) middleware.Responder
}
// NewDeleteSelectedReplicationRules creates a new http.Handler for the delete selected replication rules operation
func NewDeleteSelectedReplicationRules(ctx *middleware.Context, handler DeleteSelectedReplicationRulesHandler) *DeleteSelectedReplicationRules {
return &DeleteSelectedReplicationRules{Context: ctx, Handler: handler}
}
/* DeleteSelectedReplicationRules swagger:route DELETE /buckets/{bucket_name}/delete-selected-replication-rules UserAPI deleteSelectedReplicationRules
Deletes selected replication rules from a bucket
*/
type DeleteSelectedReplicationRules struct {
Context *middleware.Context
Handler DeleteSelectedReplicationRulesHandler
}
func (o *DeleteSelectedReplicationRules) ServeHTTP(rw http.ResponseWriter, r *http.Request) {
route, rCtx, _ := o.Context.RouteInfo(r)
if rCtx != nil {
*r = *rCtx
}
var Params = NewDeleteSelectedReplicationRulesParams()
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,127 @@
// Code generated by go-swagger; DO NOT EDIT.
// This file is part of MinIO Console Server
// Copyright (c) 2022 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/strfmt"
"github.com/go-openapi/validate"
"github.com/minio/console/models"
)
// NewDeleteSelectedReplicationRulesParams creates a new DeleteSelectedReplicationRulesParams object
//
// There are no default values defined in the spec.
func NewDeleteSelectedReplicationRulesParams() DeleteSelectedReplicationRulesParams {
return DeleteSelectedReplicationRulesParams{}
}
// DeleteSelectedReplicationRulesParams contains all the bound params for the delete selected replication rules operation
// typically these are obtained from a http.Request
//
// swagger:parameters DeleteSelectedReplicationRules
type DeleteSelectedReplicationRulesParams struct {
// HTTP Request Object
HTTPRequest *http.Request `json:"-"`
/*
Required: true
In: path
*/
BucketName string
/*
Required: true
In: body
*/
Rules *models.BucketReplicationRuleList
}
// 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 NewDeleteSelectedReplicationRulesParams() beforehand.
func (o *DeleteSelectedReplicationRulesParams) 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 runtime.HasBody(r) {
defer r.Body.Close()
var body models.BucketReplicationRuleList
if err := route.Consumer.Consume(r.Body, &body); err != nil {
if err == io.EOF {
res = append(res, errors.Required("rules", "body", ""))
} else {
res = append(res, errors.NewParseError("rules", "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.Rules = &body
}
}
} else {
res = append(res, errors.Required("rules", "body", ""))
}
if len(res) > 0 {
return errors.CompositeValidationError(res...)
}
return nil
}
// bindBucketName binds and validates parameter BucketName from path.
func (o *DeleteSelectedReplicationRulesParams) 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) 2022 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"
)
// DeleteSelectedReplicationRulesNoContentCode is the HTTP code returned for type DeleteSelectedReplicationRulesNoContent
const DeleteSelectedReplicationRulesNoContentCode int = 204
/*DeleteSelectedReplicationRulesNoContent A successful response.
swagger:response deleteSelectedReplicationRulesNoContent
*/
type DeleteSelectedReplicationRulesNoContent struct {
}
// NewDeleteSelectedReplicationRulesNoContent creates DeleteSelectedReplicationRulesNoContent with default headers values
func NewDeleteSelectedReplicationRulesNoContent() *DeleteSelectedReplicationRulesNoContent {
return &DeleteSelectedReplicationRulesNoContent{}
}
// WriteResponse to the client
func (o *DeleteSelectedReplicationRulesNoContent) WriteResponse(rw http.ResponseWriter, producer runtime.Producer) {
rw.Header().Del(runtime.HeaderContentType) //Remove Content-Type on empty responses
rw.WriteHeader(204)
}
/*DeleteSelectedReplicationRulesDefault Generic error response.
swagger:response deleteSelectedReplicationRulesDefault
*/
type DeleteSelectedReplicationRulesDefault struct {
_statusCode int
/*
In: Body
*/
Payload *models.Error `json:"body,omitempty"`
}
// NewDeleteSelectedReplicationRulesDefault creates DeleteSelectedReplicationRulesDefault with default headers values
func NewDeleteSelectedReplicationRulesDefault(code int) *DeleteSelectedReplicationRulesDefault {
if code <= 0 {
code = 500
}
return &DeleteSelectedReplicationRulesDefault{
_statusCode: code,
}
}
// WithStatusCode adds the status to the delete selected replication rules default response
func (o *DeleteSelectedReplicationRulesDefault) WithStatusCode(code int) *DeleteSelectedReplicationRulesDefault {
o._statusCode = code
return o
}
// SetStatusCode sets the status to the delete selected replication rules default response
func (o *DeleteSelectedReplicationRulesDefault) SetStatusCode(code int) {
o._statusCode = code
}
// WithPayload adds the payload to the delete selected replication rules default response
func (o *DeleteSelectedReplicationRulesDefault) WithPayload(payload *models.Error) *DeleteSelectedReplicationRulesDefault {
o.Payload = payload
return o
}
// SetPayload sets the payload to the delete selected replication rules default response
func (o *DeleteSelectedReplicationRulesDefault) SetPayload(payload *models.Error) {
o.Payload = payload
}
// WriteResponse to the client
func (o *DeleteSelectedReplicationRulesDefault) 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) 2022 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"
)
// DeleteSelectedReplicationRulesURL generates an URL for the delete selected replication rules operation
type DeleteSelectedReplicationRulesURL 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 *DeleteSelectedReplicationRulesURL) WithBasePath(bp string) *DeleteSelectedReplicationRulesURL {
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 *DeleteSelectedReplicationRulesURL) SetBasePath(bp string) {
o._basePath = bp
}
// Build a url path and query string
func (o *DeleteSelectedReplicationRulesURL) Build() (*url.URL, error) {
var _result url.URL
var _path = "/buckets/{bucket_name}/delete-selected-replication-rules"
bucketName := o.BucketName
if bucketName != "" {
_path = strings.Replace(_path, "{bucket_name}", bucketName, -1)
} else {
return nil, errors.New("bucketName is required on DeleteSelectedReplicationRulesURL")
}
_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 *DeleteSelectedReplicationRulesURL) 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 *DeleteSelectedReplicationRulesURL) String() string {
return o.Must(o.Build()).String()
}
// BuildFull builds a full url with scheme, host, path and query string
func (o *DeleteSelectedReplicationRulesURL) BuildFull(scheme, host string) (*url.URL, error) {
if scheme == "" {
return nil, errors.New("scheme is required for a full url on DeleteSelectedReplicationRulesURL")
}
if host == "" {
return nil, errors.New("host is required for a full url on DeleteSelectedReplicationRulesURL")
}
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 *DeleteSelectedReplicationRulesURL) StringFull(scheme, host string) string {
return o.Must(o.BuildFull(scheme, host)).String()
}

View File

@@ -968,7 +968,7 @@ paths:
/buckets/{bucket_name}/delete-all-replication-rules:
delete:
summary: Deletes all replication rules on a bucket
summary: Deletes all replication rules from a bucket
operationId: DeleteAllReplicationRules
parameters:
- name: bucket_name
@@ -985,6 +985,30 @@ paths:
tags:
- UserAPI
/buckets/{bucket_name}/delete-selected-replication-rules:
delete:
summary: Deletes selected replication rules from a bucket
operationId: DeleteSelectedReplicationRules
parameters:
- name: bucket_name
in: path
required: true
type: string
- name: rules
in: body
required: true
schema:
$ref: "#/definitions/bucketReplicationRuleList"
responses:
204:
description: A successful response.
default:
description: Generic error response.
schema:
$ref: "#/definitions/error"
tags:
- UserAPI
/buckets/{bucket_name}/versioning:
get:
summary: Bucket Versioning
@@ -3212,6 +3236,14 @@ definitions:
destination:
$ref: "#/definitions/bucketReplicationDestination"
bucketReplicationRuleList:
type: object
properties:
rules:
type: array
items:
type: string
bucketReplicationResponse:
type: object
properties: