mirror of
https://github.com/OpenMaxIO/openmaxio-object-browser
synced 2026-07-01 07:41:18 -07:00
Delete Non-current versions (#1735)
- Delete Non-current API - Delete non current modal implementation Signed-off-by: Benjamin Perez <benjamin@bexsoft.net>
This commit is contained in:
37
portal-ui/src/icons/DeleteNonCurrentIcon.tsx
Normal file
37
portal-ui/src/icons/DeleteNonCurrentIcon.tsx
Normal file
@@ -0,0 +1,37 @@
|
|||||||
|
// 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/>.
|
||||||
|
|
||||||
|
import * as React from "react";
|
||||||
|
import { SVGProps } from "react";
|
||||||
|
|
||||||
|
const DeleteNonCurrentIcon = (props: SVGProps<SVGSVGElement>) => (
|
||||||
|
<svg
|
||||||
|
xmlns="http://www.w3.org/2000/svg"
|
||||||
|
className={"min-icon"}
|
||||||
|
viewBox="0 0 256 256"
|
||||||
|
fill={"currentcolor"}
|
||||||
|
{...props}
|
||||||
|
>
|
||||||
|
<path
|
||||||
|
d="M222.83,0H114.08a5.38,5.38,0,0,0-5.38,5.37V118.1c.62.39,1.24.79,1.85,1.2a74.53,74.53,0,0,1,22.09,100.36h90.19a5.36,5.36,0,0,0,5.37-5.37V5.37A5.37,5.37,0,0,0,222.83,0Z"
|
||||||
|
/>
|
||||||
|
<path
|
||||||
|
d="M106,125.38a68,68,0,1,0,30,56.35A67.59,67.59,0,0,0,106,125.38Zm8.16,94.78-7.77,7.76L68,189.5,29.56,227.92l-7.77-7.76,38.42-38.43L21.79,143.31l7.77-7.77L68,174l38.42-38.42,7.77,7.77L75.75,181.73Z"
|
||||||
|
/>
|
||||||
|
</svg>
|
||||||
|
);
|
||||||
|
|
||||||
|
export default DeleteNonCurrentIcon;
|
||||||
@@ -180,3 +180,4 @@ export { default as ArrowRightLink } from "./ArrowRightLink";
|
|||||||
export { default as LicenseDocIcon } from "./LicenseDocIcon";
|
export { default as LicenseDocIcon } from "./LicenseDocIcon";
|
||||||
export { default as SelectAllIcon } from "./SelectAllIcon";
|
export { default as SelectAllIcon } from "./SelectAllIcon";
|
||||||
export { default as BackIcon } from "./BackIcon";
|
export { default as BackIcon } from "./BackIcon";
|
||||||
|
export { default as DeleteNonCurrentIcon } from "./DeleteNonCurrentIcon";
|
||||||
|
|||||||
@@ -0,0 +1,118 @@
|
|||||||
|
// 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/>.
|
||||||
|
|
||||||
|
import React, { useState, useEffect } from "react";
|
||||||
|
import { connect } from "react-redux";
|
||||||
|
import { DialogContentText } from "@mui/material";
|
||||||
|
import Grid from "@mui/material/Grid";
|
||||||
|
import { setErrorSnackMessage } from "../../../../../../actions";
|
||||||
|
import { ErrorResponseHandler } from "../../../../../../common/types";
|
||||||
|
import { decodeFileName } from "../../../../../../common/utils";
|
||||||
|
import { ConfirmDeleteIcon } from "../../../../../../icons";
|
||||||
|
import ConfirmDialog from "../../../../Common/ModalWrapper/ConfirmDialog";
|
||||||
|
import api from "../../../../../../common/api";
|
||||||
|
import InputBoxWrapper from "../../../../Common/FormComponents/InputBoxWrapper/InputBoxWrapper";
|
||||||
|
|
||||||
|
interface IDeleteNonCurrentProps {
|
||||||
|
closeDeleteModalAndRefresh: (refresh: boolean) => void;
|
||||||
|
deleteOpen: boolean;
|
||||||
|
selectedObject: string;
|
||||||
|
selectedBucket: string;
|
||||||
|
setErrorSnackMessage: typeof setErrorSnackMessage;
|
||||||
|
}
|
||||||
|
|
||||||
|
const DeleteNonCurrentVersions = ({
|
||||||
|
closeDeleteModalAndRefresh,
|
||||||
|
deleteOpen,
|
||||||
|
selectedBucket,
|
||||||
|
selectedObject,
|
||||||
|
setErrorSnackMessage,
|
||||||
|
}: IDeleteNonCurrentProps) => {
|
||||||
|
const [deleteLoading, setDeleteLoading] = useState<boolean>(false);
|
||||||
|
const [typeConfirm, setTypeConfirm] = useState<string>("");
|
||||||
|
|
||||||
|
useEffect(() => {
|
||||||
|
if (deleteLoading) {
|
||||||
|
api
|
||||||
|
.invoke(
|
||||||
|
"DELETE",
|
||||||
|
`/api/v1/buckets/${selectedBucket}/objects?path=${selectedObject}&non_current_versions=true`
|
||||||
|
)
|
||||||
|
.then(() => {
|
||||||
|
closeDeleteModalAndRefresh(true);
|
||||||
|
})
|
||||||
|
.catch((error: ErrorResponseHandler) => {
|
||||||
|
setErrorSnackMessage(error);
|
||||||
|
setDeleteLoading(false);
|
||||||
|
});
|
||||||
|
}
|
||||||
|
}, [
|
||||||
|
deleteLoading,
|
||||||
|
closeDeleteModalAndRefresh,
|
||||||
|
setErrorSnackMessage,
|
||||||
|
selectedObject,
|
||||||
|
selectedBucket,
|
||||||
|
]);
|
||||||
|
|
||||||
|
if (!selectedObject) {
|
||||||
|
return null;
|
||||||
|
}
|
||||||
|
const onConfirmDelete = () => {
|
||||||
|
setDeleteLoading(true);
|
||||||
|
};
|
||||||
|
|
||||||
|
return (
|
||||||
|
<ConfirmDialog
|
||||||
|
title={`Delete Non-Current versions`}
|
||||||
|
confirmText={"Delete"}
|
||||||
|
isOpen={deleteOpen}
|
||||||
|
titleIcon={<ConfirmDeleteIcon />}
|
||||||
|
isLoading={deleteLoading}
|
||||||
|
onConfirm={onConfirmDelete}
|
||||||
|
onClose={() => closeDeleteModalAndRefresh(false)}
|
||||||
|
confirmButtonProps={{
|
||||||
|
disabled: typeConfirm !== "YES, PROCEED" || deleteLoading,
|
||||||
|
}}
|
||||||
|
confirmationContent={
|
||||||
|
<DialogContentText>
|
||||||
|
Are you sure you want to delete all the non-current versions for:{" "}
|
||||||
|
<b>{decodeFileName(selectedObject)}</b>? <br />
|
||||||
|
<br />
|
||||||
|
To continue please type <b>YES, PROCEED</b> in the box.
|
||||||
|
<Grid item xs={12}>
|
||||||
|
<InputBoxWrapper
|
||||||
|
id="type-confirm"
|
||||||
|
name="retype-tenant"
|
||||||
|
onChange={(event: React.ChangeEvent<HTMLInputElement>) => {
|
||||||
|
setTypeConfirm(event.target.value);
|
||||||
|
}}
|
||||||
|
label=""
|
||||||
|
value={typeConfirm}
|
||||||
|
/>
|
||||||
|
</Grid>
|
||||||
|
</DialogContentText>
|
||||||
|
}
|
||||||
|
/>
|
||||||
|
);
|
||||||
|
};
|
||||||
|
|
||||||
|
const mapDispatchToProps = {
|
||||||
|
setErrorSnackMessage,
|
||||||
|
};
|
||||||
|
|
||||||
|
const connector = connect(null, mapDispatchToProps);
|
||||||
|
|
||||||
|
export default connector(DeleteNonCurrentVersions);
|
||||||
@@ -55,11 +55,13 @@ import {
|
|||||||
} from "../../../../ObjectBrowser/actions";
|
} from "../../../../ObjectBrowser/actions";
|
||||||
|
|
||||||
import { AppState } from "../../../../../../store";
|
import { AppState } from "../../../../../../store";
|
||||||
import { VersionsIcon } from "../../../../../../icons";
|
import { DeleteNonCurrentIcon, VersionsIcon } from "../../../../../../icons";
|
||||||
import VirtualizedList from "../../../../Common/VirtualizedList/VirtualizedList";
|
import VirtualizedList from "../../../../Common/VirtualizedList/VirtualizedList";
|
||||||
import FileVersionItem from "./FileVersionItem";
|
import FileVersionItem from "./FileVersionItem";
|
||||||
import SelectWrapper from "../../../../Common/FormComponents/SelectWrapper/SelectWrapper";
|
import SelectWrapper from "../../../../Common/FormComponents/SelectWrapper/SelectWrapper";
|
||||||
import PreviewFileModal from "../Preview/PreviewFileModal";
|
import PreviewFileModal from "../Preview/PreviewFileModal";
|
||||||
|
import RBIconButton from "../../../BucketDetails/SummaryItems/RBIconButton";
|
||||||
|
import DeleteNonCurrent from "../ListObjects/DeleteNonCurrent";
|
||||||
|
|
||||||
const styles = (theme: Theme) =>
|
const styles = (theme: Theme) =>
|
||||||
createStyles({
|
createStyles({
|
||||||
@@ -160,6 +162,8 @@ const VersionsNavigator = ({
|
|||||||
const [restoreVersion, setRestoreVersion] = useState<string>("");
|
const [restoreVersion, setRestoreVersion] = useState<string>("");
|
||||||
const [sortValue, setSortValue] = useState<string>("date");
|
const [sortValue, setSortValue] = useState<string>("date");
|
||||||
const [previewOpen, setPreviewOpen] = useState<boolean>(false);
|
const [previewOpen, setPreviewOpen] = useState<boolean>(false);
|
||||||
|
const [deleteNonCurrentOpen, setDeleteNonCurrentOpen] =
|
||||||
|
useState<boolean>(false);
|
||||||
|
|
||||||
// calculate object name to display
|
// calculate object name to display
|
||||||
let objectNameArray: string[] = [];
|
let objectNameArray: string[] = [];
|
||||||
@@ -283,6 +287,16 @@ const VersionsNavigator = ({
|
|||||||
}
|
}
|
||||||
};
|
};
|
||||||
|
|
||||||
|
const closeDeleteNonCurrent = (reloadAfterDelete: boolean) => {
|
||||||
|
setDeleteNonCurrentOpen(false);
|
||||||
|
|
||||||
|
if (reloadAfterDelete) {
|
||||||
|
setLoadingVersions(true);
|
||||||
|
setSelectedVersion("");
|
||||||
|
setLoadingObjectInfo(true);
|
||||||
|
}
|
||||||
|
};
|
||||||
|
|
||||||
const totalSpace = versions.reduce((acc: number, currValue: IFileInfo) => {
|
const totalSpace = versions.reduce((acc: number, currValue: IFileInfo) => {
|
||||||
if (currValue.size) {
|
if (currValue.size) {
|
||||||
return acc + parseInt(currValue.size);
|
return acc + parseInt(currValue.size);
|
||||||
@@ -376,6 +390,14 @@ const VersionsNavigator = ({
|
|||||||
}}
|
}}
|
||||||
/>
|
/>
|
||||||
)}
|
)}
|
||||||
|
{deleteNonCurrentOpen && (
|
||||||
|
<DeleteNonCurrent
|
||||||
|
deleteOpen={deleteNonCurrentOpen}
|
||||||
|
closeDeleteModalAndRefresh={closeDeleteNonCurrent}
|
||||||
|
selectedBucket={bucketName}
|
||||||
|
selectedObject={internalPaths}
|
||||||
|
/>
|
||||||
|
)}
|
||||||
<Grid container className={classes.versionsContainer}>
|
<Grid container className={classes.versionsContainer}>
|
||||||
{!actualInfo && (
|
{!actualInfo && (
|
||||||
<Grid item xs={12}>
|
<Grid item xs={12}>
|
||||||
@@ -417,6 +439,18 @@ const VersionsNavigator = ({
|
|||||||
}
|
}
|
||||||
actions={
|
actions={
|
||||||
<Fragment>
|
<Fragment>
|
||||||
|
<RBIconButton
|
||||||
|
id={"delete-non-current"}
|
||||||
|
tooltip={"Delete Non Current Versions"}
|
||||||
|
onClick={() => {
|
||||||
|
setDeleteNonCurrentOpen(true);
|
||||||
|
}}
|
||||||
|
text={""}
|
||||||
|
icon={<DeleteNonCurrentIcon />}
|
||||||
|
color="secondary"
|
||||||
|
style={{ marginRight: 15 }}
|
||||||
|
disabled={versions.length <= 1}
|
||||||
|
/>
|
||||||
<span className={classes.sortByLabel}>Sort by</span>
|
<span className={classes.sortByLabel}>Sort by</span>
|
||||||
<SelectWrapper
|
<SelectWrapper
|
||||||
id={"sort-by"}
|
id={"sort-by"}
|
||||||
|
|||||||
@@ -343,6 +343,12 @@ const IconsScreen = ({ classes }: IIconsScreenSimple) => {
|
|||||||
DeleteIcon
|
DeleteIcon
|
||||||
</Grid>
|
</Grid>
|
||||||
|
|
||||||
|
<Grid item xs={3} sm={2} md={1}>
|
||||||
|
<cicons.DeleteNonCurrentIcon />
|
||||||
|
<br />
|
||||||
|
DeleteNonCurrentIcon
|
||||||
|
</Grid>
|
||||||
|
|
||||||
<Grid item xs={3} sm={2} md={1}>
|
<Grid item xs={3} sm={2} md={1}>
|
||||||
<cicons.DiagnosticsFeatureIcon />
|
<cicons.DiagnosticsFeatureIcon />
|
||||||
<br />
|
<br />
|
||||||
|
|||||||
@@ -1315,6 +1315,11 @@ func init() {
|
|||||||
"type": "boolean",
|
"type": "boolean",
|
||||||
"name": "all_versions",
|
"name": "all_versions",
|
||||||
"in": "query"
|
"in": "query"
|
||||||
|
},
|
||||||
|
{
|
||||||
|
"type": "boolean",
|
||||||
|
"name": "non_current_versions",
|
||||||
|
"in": "query"
|
||||||
}
|
}
|
||||||
],
|
],
|
||||||
"responses": {
|
"responses": {
|
||||||
@@ -7799,6 +7804,11 @@ func init() {
|
|||||||
"type": "boolean",
|
"type": "boolean",
|
||||||
"name": "all_versions",
|
"name": "all_versions",
|
||||||
"in": "query"
|
"in": "query"
|
||||||
|
},
|
||||||
|
{
|
||||||
|
"type": "boolean",
|
||||||
|
"name": "non_current_versions",
|
||||||
|
"in": "query"
|
||||||
}
|
}
|
||||||
],
|
],
|
||||||
"responses": {
|
"responses": {
|
||||||
|
|||||||
@@ -59,6 +59,10 @@ type DeleteObjectParams struct {
|
|||||||
In: path
|
In: path
|
||||||
*/
|
*/
|
||||||
BucketName string
|
BucketName string
|
||||||
|
/*
|
||||||
|
In: query
|
||||||
|
*/
|
||||||
|
NonCurrentVersions *bool
|
||||||
/*
|
/*
|
||||||
Required: true
|
Required: true
|
||||||
In: query
|
In: query
|
||||||
@@ -95,6 +99,11 @@ func (o *DeleteObjectParams) BindRequest(r *http.Request, route *middleware.Matc
|
|||||||
res = append(res, err)
|
res = append(res, err)
|
||||||
}
|
}
|
||||||
|
|
||||||
|
qNonCurrentVersions, qhkNonCurrentVersions, _ := qs.GetOK("non_current_versions")
|
||||||
|
if err := o.bindNonCurrentVersions(qNonCurrentVersions, qhkNonCurrentVersions, route.Formats); err != nil {
|
||||||
|
res = append(res, err)
|
||||||
|
}
|
||||||
|
|
||||||
qPath, qhkPath, _ := qs.GetOK("path")
|
qPath, qhkPath, _ := qs.GetOK("path")
|
||||||
if err := o.bindPath(qPath, qhkPath, route.Formats); err != nil {
|
if err := o.bindPath(qPath, qhkPath, route.Formats); err != nil {
|
||||||
res = append(res, err)
|
res = append(res, err)
|
||||||
@@ -152,6 +161,29 @@ func (o *DeleteObjectParams) bindBucketName(rawData []string, hasKey bool, forma
|
|||||||
return nil
|
return nil
|
||||||
}
|
}
|
||||||
|
|
||||||
|
// bindNonCurrentVersions binds and validates parameter NonCurrentVersions from query.
|
||||||
|
func (o *DeleteObjectParams) bindNonCurrentVersions(rawData []string, hasKey bool, formats strfmt.Registry) error {
|
||||||
|
var raw string
|
||||||
|
if len(rawData) > 0 {
|
||||||
|
raw = rawData[len(rawData)-1]
|
||||||
|
}
|
||||||
|
|
||||||
|
// Required: false
|
||||||
|
// AllowEmptyValue: false
|
||||||
|
|
||||||
|
if raw == "" { // empty values pass all other validations
|
||||||
|
return nil
|
||||||
|
}
|
||||||
|
|
||||||
|
value, err := swag.ConvertBool(raw)
|
||||||
|
if err != nil {
|
||||||
|
return errors.InvalidType("non_current_versions", "query", "bool", raw)
|
||||||
|
}
|
||||||
|
o.NonCurrentVersions = &value
|
||||||
|
|
||||||
|
return nil
|
||||||
|
}
|
||||||
|
|
||||||
// bindPath binds and validates parameter Path from query.
|
// bindPath binds and validates parameter Path from query.
|
||||||
func (o *DeleteObjectParams) bindPath(rawData []string, hasKey bool, formats strfmt.Registry) error {
|
func (o *DeleteObjectParams) bindPath(rawData []string, hasKey bool, formats strfmt.Registry) error {
|
||||||
if !hasKey {
|
if !hasKey {
|
||||||
|
|||||||
@@ -35,10 +35,11 @@ import (
|
|||||||
type DeleteObjectURL struct {
|
type DeleteObjectURL struct {
|
||||||
BucketName string
|
BucketName string
|
||||||
|
|
||||||
AllVersions *bool
|
AllVersions *bool
|
||||||
Path string
|
NonCurrentVersions *bool
|
||||||
Recursive *bool
|
Path string
|
||||||
VersionID *string
|
Recursive *bool
|
||||||
|
VersionID *string
|
||||||
|
|
||||||
_basePath string
|
_basePath string
|
||||||
// avoid unkeyed usage
|
// avoid unkeyed usage
|
||||||
@@ -89,6 +90,14 @@ func (o *DeleteObjectURL) Build() (*url.URL, error) {
|
|||||||
qs.Set("all_versions", allVersionsQ)
|
qs.Set("all_versions", allVersionsQ)
|
||||||
}
|
}
|
||||||
|
|
||||||
|
var nonCurrentVersionsQ string
|
||||||
|
if o.NonCurrentVersions != nil {
|
||||||
|
nonCurrentVersionsQ = swag.FormatBool(*o.NonCurrentVersions)
|
||||||
|
}
|
||||||
|
if nonCurrentVersionsQ != "" {
|
||||||
|
qs.Set("non_current_versions", nonCurrentVersionsQ)
|
||||||
|
}
|
||||||
|
|
||||||
pathQ := o.Path
|
pathQ := o.Path
|
||||||
if pathQ != "" {
|
if pathQ != "" {
|
||||||
qs.Set("path", pathQ)
|
qs.Set("path", pathQ)
|
||||||
|
|||||||
@@ -570,6 +570,7 @@ func getDeleteObjectResponse(session *models.Principal, params user_api.DeleteOb
|
|||||||
var rec bool
|
var rec bool
|
||||||
var version string
|
var version string
|
||||||
var allVersions bool
|
var allVersions bool
|
||||||
|
var nonCurrentVersions bool
|
||||||
if params.Recursive != nil {
|
if params.Recursive != nil {
|
||||||
rec = *params.Recursive
|
rec = *params.Recursive
|
||||||
}
|
}
|
||||||
@@ -579,7 +580,16 @@ func getDeleteObjectResponse(session *models.Principal, params user_api.DeleteOb
|
|||||||
if params.AllVersions != nil {
|
if params.AllVersions != nil {
|
||||||
allVersions = *params.AllVersions
|
allVersions = *params.AllVersions
|
||||||
}
|
}
|
||||||
err = deleteObjects(ctx, mcClient, params.BucketName, prefix, version, rec, allVersions)
|
if params.NonCurrentVersions != nil {
|
||||||
|
nonCurrentVersions = *params.NonCurrentVersions
|
||||||
|
}
|
||||||
|
|
||||||
|
if allVersions && nonCurrentVersions {
|
||||||
|
err := errors.New("cannot set delete all versions and delete non-current versions flags at the same time")
|
||||||
|
return prepareError(err)
|
||||||
|
}
|
||||||
|
|
||||||
|
err = deleteObjects(ctx, mcClient, params.BucketName, prefix, version, rec, allVersions, nonCurrentVersions)
|
||||||
if err != nil {
|
if err != nil {
|
||||||
return prepareError(err)
|
return prepareError(err)
|
||||||
}
|
}
|
||||||
@@ -606,7 +616,7 @@ func getDeleteMultiplePathsResponse(session *models.Principal, params user_api.D
|
|||||||
// create a mc S3Client interface implementation
|
// create a mc S3Client interface implementation
|
||||||
// defining the client to be used
|
// defining the client to be used
|
||||||
mcClient := mcClient{client: s3Client}
|
mcClient := mcClient{client: s3Client}
|
||||||
err = deleteObjects(ctx, mcClient, params.BucketName, params.Files[i].Path, version, params.Files[i].Recursive, allVersions)
|
err = deleteObjects(ctx, mcClient, params.BucketName, params.Files[i].Path, version, params.Files[i].Recursive, allVersions, false)
|
||||||
if err != nil {
|
if err != nil {
|
||||||
return prepareError(err)
|
return prepareError(err)
|
||||||
}
|
}
|
||||||
@@ -615,7 +625,15 @@ func getDeleteMultiplePathsResponse(session *models.Principal, params user_api.D
|
|||||||
}
|
}
|
||||||
|
|
||||||
// deleteObjects deletes either a single object or multiple objects based on recursive flag
|
// deleteObjects deletes either a single object or multiple objects based on recursive flag
|
||||||
func deleteObjects(ctx context.Context, client MCClient, bucket string, path string, versionID string, recursive bool, allVersions bool) error {
|
func deleteObjects(ctx context.Context, client MCClient, bucket string, path string, versionID string, recursive bool, allVersions bool, nonCurrentVersionsOnly bool) error {
|
||||||
|
// Delete All non-Current versions only.
|
||||||
|
if nonCurrentVersionsOnly {
|
||||||
|
if err := deleteNonCurrentVersions(ctx, client, bucket, path); err != nil {
|
||||||
|
return err
|
||||||
|
}
|
||||||
|
return nil
|
||||||
|
}
|
||||||
|
|
||||||
if allVersions {
|
if allVersions {
|
||||||
if err := deleteMultipleObjects(ctx, client, recursive, true); err != nil {
|
if err := deleteMultipleObjects(ctx, client, recursive, true); err != nil {
|
||||||
return err
|
return err
|
||||||
@@ -718,6 +736,25 @@ func deleteSingleObject(ctx context.Context, client MCClient, bucket, object str
|
|||||||
return nil
|
return nil
|
||||||
}
|
}
|
||||||
|
|
||||||
|
func deleteNonCurrentVersions(ctx context.Context, client MCClient, bucket, path string) error {
|
||||||
|
// Get current object versions
|
||||||
|
for lsObj := range client.list(ctx, mc.ListOptions{WithDeleteMarkers: true, WithOlderVersions: true, Recursive: true}) {
|
||||||
|
if lsObj.Err != nil {
|
||||||
|
return errors.New(lsObj.Err.String())
|
||||||
|
}
|
||||||
|
|
||||||
|
if !lsObj.IsLatest {
|
||||||
|
err := deleteSingleObject(ctx, client, bucket, path, lsObj.VersionID)
|
||||||
|
|
||||||
|
if err != nil {
|
||||||
|
return err
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
return nil
|
||||||
|
}
|
||||||
|
|
||||||
func getUploadObjectResponse(session *models.Principal, params user_api.PostBucketsBucketNameObjectsUploadParams) *models.Error {
|
func getUploadObjectResponse(session *models.Principal, params user_api.PostBucketsBucketNameObjectsUploadParams) *models.Error {
|
||||||
ctx := context.Background()
|
ctx := context.Background()
|
||||||
mClient, err := newMinioClient(session)
|
mClient, err := newMinioClient(session)
|
||||||
|
|||||||
@@ -583,6 +583,7 @@ func Test_deleteObjects(t *testing.T) {
|
|||||||
path string
|
path string
|
||||||
versionID string
|
versionID string
|
||||||
recursive bool
|
recursive bool
|
||||||
|
nonCurrent bool
|
||||||
listFunc func(ctx context.Context, opts mc.ListOptions) <-chan *mc.ClientContent
|
listFunc func(ctx context.Context, opts mc.ListOptions) <-chan *mc.ClientContent
|
||||||
removeFunc func(ctx context.Context, isIncomplete, isRemoveBucket, isBypass bool, contentCh <-chan *mc.ClientContent) <-chan mc.RemoveResult
|
removeFunc func(ctx context.Context, isIncomplete, isRemoveBucket, isBypass bool, contentCh <-chan *mc.ClientContent) <-chan mc.RemoveResult
|
||||||
}
|
}
|
||||||
@@ -594,9 +595,10 @@ func Test_deleteObjects(t *testing.T) {
|
|||||||
{
|
{
|
||||||
test: "Remove single object",
|
test: "Remove single object",
|
||||||
args: args{
|
args: args{
|
||||||
path: "obj.txt",
|
path: "obj.txt",
|
||||||
versionID: "",
|
versionID: "",
|
||||||
recursive: false,
|
recursive: false,
|
||||||
|
nonCurrent: false,
|
||||||
removeFunc: func(ctx context.Context, isIncomplete, isRemoveBucket, isBypass bool, contentCh <-chan *mc.ClientContent) <-chan mc.RemoveResult {
|
removeFunc: func(ctx context.Context, isIncomplete, isRemoveBucket, isBypass bool, contentCh <-chan *mc.ClientContent) <-chan mc.RemoveResult {
|
||||||
resultCh := make(chan mc.RemoveResult, 1)
|
resultCh := make(chan mc.RemoveResult, 1)
|
||||||
resultCh <- mc.RemoveResult{Err: nil}
|
resultCh <- mc.RemoveResult{Err: nil}
|
||||||
@@ -609,9 +611,10 @@ func Test_deleteObjects(t *testing.T) {
|
|||||||
{
|
{
|
||||||
test: "Error on Remove single object",
|
test: "Error on Remove single object",
|
||||||
args: args{
|
args: args{
|
||||||
path: "obj.txt",
|
path: "obj.txt",
|
||||||
versionID: "",
|
versionID: "",
|
||||||
recursive: false,
|
recursive: false,
|
||||||
|
nonCurrent: false,
|
||||||
removeFunc: func(ctx context.Context, isIncomplete, isRemoveBucket, isBypass bool, contentCh <-chan *mc.ClientContent) <-chan mc.RemoveResult {
|
removeFunc: func(ctx context.Context, isIncomplete, isRemoveBucket, isBypass bool, contentCh <-chan *mc.ClientContent) <-chan mc.RemoveResult {
|
||||||
resultCh := make(chan mc.RemoveResult, 1)
|
resultCh := make(chan mc.RemoveResult, 1)
|
||||||
resultCh <- mc.RemoveResult{Err: probe.NewError(errors.New("probe error"))}
|
resultCh <- mc.RemoveResult{Err: probe.NewError(errors.New("probe error"))}
|
||||||
@@ -624,9 +627,10 @@ func Test_deleteObjects(t *testing.T) {
|
|||||||
{
|
{
|
||||||
test: "Remove multiple objects",
|
test: "Remove multiple objects",
|
||||||
args: args{
|
args: args{
|
||||||
path: "path/",
|
path: "path/",
|
||||||
versionID: "",
|
versionID: "",
|
||||||
recursive: true,
|
recursive: true,
|
||||||
|
nonCurrent: false,
|
||||||
removeFunc: func(ctx context.Context, isIncomplete, isRemoveBucket, isBypass bool, contentCh <-chan *mc.ClientContent) <-chan mc.RemoveResult {
|
removeFunc: func(ctx context.Context, isIncomplete, isRemoveBucket, isBypass bool, contentCh <-chan *mc.ClientContent) <-chan mc.RemoveResult {
|
||||||
resultCh := make(chan mc.RemoveResult, 1)
|
resultCh := make(chan mc.RemoveResult, 1)
|
||||||
resultCh <- mc.RemoveResult{Err: nil}
|
resultCh <- mc.RemoveResult{Err: nil}
|
||||||
@@ -647,9 +651,10 @@ func Test_deleteObjects(t *testing.T) {
|
|||||||
// while deleting multiple objects
|
// while deleting multiple objects
|
||||||
test: "Error on Remove multiple objects 1",
|
test: "Error on Remove multiple objects 1",
|
||||||
args: args{
|
args: args{
|
||||||
path: "path/",
|
path: "path/",
|
||||||
versionID: "",
|
versionID: "",
|
||||||
recursive: true,
|
recursive: true,
|
||||||
|
nonCurrent: false,
|
||||||
removeFunc: func(ctx context.Context, isIncomplete, isRemoveBucket, isBypass bool, contentCh <-chan *mc.ClientContent) <-chan mc.RemoveResult {
|
removeFunc: func(ctx context.Context, isIncomplete, isRemoveBucket, isBypass bool, contentCh <-chan *mc.ClientContent) <-chan mc.RemoveResult {
|
||||||
resultCh := make(chan mc.RemoveResult, 1)
|
resultCh := make(chan mc.RemoveResult, 1)
|
||||||
resultCh <- mc.RemoveResult{Err: nil}
|
resultCh <- mc.RemoveResult{Err: nil}
|
||||||
@@ -670,9 +675,58 @@ func Test_deleteObjects(t *testing.T) {
|
|||||||
// while deleting multiple objects
|
// while deleting multiple objects
|
||||||
test: "Error on Remove multiple objects 2",
|
test: "Error on Remove multiple objects 2",
|
||||||
args: args{
|
args: args{
|
||||||
path: "path/",
|
path: "path/",
|
||||||
versionID: "",
|
versionID: "",
|
||||||
recursive: true,
|
recursive: true,
|
||||||
|
nonCurrent: false,
|
||||||
|
removeFunc: func(ctx context.Context, isIncomplete, isRemoveBucket, isBypass bool, contentCh <-chan *mc.ClientContent) <-chan mc.RemoveResult {
|
||||||
|
resultCh := make(chan mc.RemoveResult, 1)
|
||||||
|
resultCh <- mc.RemoveResult{Err: probe.NewError(errors.New("probe error"))}
|
||||||
|
close(resultCh)
|
||||||
|
return resultCh
|
||||||
|
},
|
||||||
|
listFunc: func(ctx context.Context, opts mc.ListOptions) <-chan *mc.ClientContent {
|
||||||
|
ch := make(chan *mc.ClientContent, 1)
|
||||||
|
ch <- &mc.ClientContent{}
|
||||||
|
close(ch)
|
||||||
|
return ch
|
||||||
|
},
|
||||||
|
},
|
||||||
|
wantError: errors.New("probe error"),
|
||||||
|
},
|
||||||
|
{
|
||||||
|
// Description handle error when error happens on remove function
|
||||||
|
// while deleting multiple objects
|
||||||
|
test: "Remove non current objects",
|
||||||
|
args: args{
|
||||||
|
path: "path/",
|
||||||
|
versionID: "",
|
||||||
|
recursive: true,
|
||||||
|
nonCurrent: true,
|
||||||
|
removeFunc: func(ctx context.Context, isIncomplete, isRemoveBucket, isBypass bool, contentCh <-chan *mc.ClientContent) <-chan mc.RemoveResult {
|
||||||
|
resultCh := make(chan mc.RemoveResult, 1)
|
||||||
|
resultCh <- mc.RemoveResult{Err: nil}
|
||||||
|
close(resultCh)
|
||||||
|
return resultCh
|
||||||
|
},
|
||||||
|
listFunc: func(ctx context.Context, opts mc.ListOptions) <-chan *mc.ClientContent {
|
||||||
|
ch := make(chan *mc.ClientContent, 1)
|
||||||
|
ch <- &mc.ClientContent{}
|
||||||
|
close(ch)
|
||||||
|
return ch
|
||||||
|
},
|
||||||
|
},
|
||||||
|
wantError: nil,
|
||||||
|
},
|
||||||
|
{
|
||||||
|
// Description handle error when error happens on remove function
|
||||||
|
// while deleting multiple objects
|
||||||
|
test: "Error deleting non current objects",
|
||||||
|
args: args{
|
||||||
|
path: "path/",
|
||||||
|
versionID: "",
|
||||||
|
recursive: true,
|
||||||
|
nonCurrent: true,
|
||||||
removeFunc: func(ctx context.Context, isIncomplete, isRemoveBucket, isBypass bool, contentCh <-chan *mc.ClientContent) <-chan mc.RemoveResult {
|
removeFunc: func(ctx context.Context, isIncomplete, isRemoveBucket, isBypass bool, contentCh <-chan *mc.ClientContent) <-chan mc.RemoveResult {
|
||||||
resultCh := make(chan mc.RemoveResult, 1)
|
resultCh := make(chan mc.RemoveResult, 1)
|
||||||
resultCh <- mc.RemoveResult{Err: probe.NewError(errors.New("probe error"))}
|
resultCh <- mc.RemoveResult{Err: probe.NewError(errors.New("probe error"))}
|
||||||
@@ -695,7 +749,7 @@ func Test_deleteObjects(t *testing.T) {
|
|||||||
t.Run(tt.test, func(t *testing.T) {
|
t.Run(tt.test, func(t *testing.T) {
|
||||||
mcListMock = tt.args.listFunc
|
mcListMock = tt.args.listFunc
|
||||||
mcRemoveMock = tt.args.removeFunc
|
mcRemoveMock = tt.args.removeFunc
|
||||||
err := deleteObjects(ctx, s3Client1, tt.args.bucket, tt.args.path, tt.args.versionID, tt.args.recursive, false)
|
err := deleteObjects(ctx, s3Client1, tt.args.bucket, tt.args.path, tt.args.versionID, tt.args.recursive, false, tt.args.nonCurrent)
|
||||||
if err == nil && tt.wantError != nil {
|
if err == nil && tt.wantError != nil {
|
||||||
t.Errorf("deleteObjects() error: %v, wantErr: %v", err, tt.wantError)
|
t.Errorf("deleteObjects() error: %v, wantErr: %v", err, tt.wantError)
|
||||||
} else if err != nil && tt.wantError == nil {
|
} else if err != nil && tt.wantError == nil {
|
||||||
|
|||||||
@@ -341,6 +341,10 @@ paths:
|
|||||||
in: query
|
in: query
|
||||||
required: false
|
required: false
|
||||||
type: boolean
|
type: boolean
|
||||||
|
- name: non_current_versions
|
||||||
|
in: query
|
||||||
|
required: false
|
||||||
|
type: boolean
|
||||||
responses:
|
responses:
|
||||||
200:
|
200:
|
||||||
description: A successful response.
|
description: A successful response.
|
||||||
|
|||||||
Reference in New Issue
Block a user