2021-05-25 18:16:15 -05:00
|
|
|
// 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/>.
|
|
|
|
|
|
2021-07-28 15:53:53 -07:00
|
|
|
import React, { Fragment, useEffect, useState } from "react";
|
2022-05-18 17:02:26 -05:00
|
|
|
import { useSelector } from "react-redux";
|
2021-10-21 20:20:27 -05:00
|
|
|
import { Theme } from "@mui/material/styles";
|
|
|
|
|
import createStyles from "@mui/styles/createStyles";
|
|
|
|
|
import withStyles from "@mui/styles/withStyles";
|
2021-05-25 18:16:15 -05:00
|
|
|
import get from "lodash/get";
|
2021-10-21 20:20:27 -05:00
|
|
|
import Grid from "@mui/material/Grid";
|
2022-05-18 17:02:26 -05:00
|
|
|
import { LifeCycleItem } from "../types";
|
2021-10-19 19:15:58 -07:00
|
|
|
import { AddIcon, TiersIcon } from "../../../../icons";
|
2021-05-25 18:16:15 -05:00
|
|
|
import {
|
|
|
|
|
actionsTray,
|
|
|
|
|
searchField,
|
|
|
|
|
} from "../../Common/FormComponents/common/styleLibrary";
|
2021-07-28 20:09:48 -05:00
|
|
|
import { ErrorResponseHandler } from "../../../../common/types";
|
2021-05-25 18:16:15 -05:00
|
|
|
import api from "../../../../common/api";
|
|
|
|
|
import EditLifecycleConfiguration from "./EditLifecycleConfiguration";
|
|
|
|
|
import AddLifecycleModal from "./AddLifecycleModal";
|
|
|
|
|
import TableWrapper from "../../Common/TableWrapper/TableWrapper";
|
2021-10-19 19:15:58 -07:00
|
|
|
import HelpBox from "../../../../common/HelpBox";
|
2021-11-11 18:04:18 -06:00
|
|
|
import PanelTitle from "../../Common/PanelTitle/PanelTitle";
|
2022-02-15 13:29:09 -08:00
|
|
|
import {
|
2021-11-18 08:25:01 -08:00
|
|
|
hasPermission,
|
2022-04-04 19:13:59 -07:00
|
|
|
SecureComponent,
|
2022-02-15 13:29:09 -08:00
|
|
|
} from "../../../../common/SecureComponent";
|
2021-11-18 08:25:01 -08:00
|
|
|
import { IAM_SCOPES } from "../../../../common/SecureComponent/permissions";
|
2022-02-10 17:25:59 -07:00
|
|
|
import DeleteBucketLifecycleRule from "./DeleteBucketLifecycleRule";
|
2022-05-25 19:12:07 -05:00
|
|
|
import { selBucketDetailsLoading } from "./bucketDetailsSlice";
|
2022-06-09 17:37:21 -05:00
|
|
|
import { useParams } from "react-router-dom";
|
2022-09-09 17:42:30 -05:00
|
|
|
import TooltipWrapper from "../../Common/TooltipWrapper/TooltipWrapper";
|
|
|
|
|
import { Button } from "mds";
|
2021-05-25 18:16:15 -05:00
|
|
|
|
|
|
|
|
const styles = (theme: Theme) =>
|
|
|
|
|
createStyles({
|
|
|
|
|
...searchField,
|
|
|
|
|
...actionsTray,
|
2021-10-19 19:15:58 -07:00
|
|
|
twHeight: {
|
|
|
|
|
minHeight: 400,
|
|
|
|
|
},
|
2021-05-25 18:16:15 -05:00
|
|
|
});
|
|
|
|
|
|
|
|
|
|
interface IBucketLifecyclePanelProps {
|
|
|
|
|
classes: any;
|
|
|
|
|
}
|
|
|
|
|
|
2022-06-09 17:37:21 -05:00
|
|
|
const BucketLifecyclePanel = ({ classes }: IBucketLifecyclePanelProps) => {
|
2022-05-25 19:12:07 -05:00
|
|
|
const loadingBucket = useSelector(selBucketDetailsLoading);
|
2022-06-09 17:37:21 -05:00
|
|
|
const params = useParams();
|
2022-05-18 17:02:26 -05:00
|
|
|
|
2021-05-25 18:16:15 -05:00
|
|
|
const [loadingLifecycle, setLoadingLifecycle] = useState<boolean>(true);
|
|
|
|
|
const [lifecycleRecords, setLifecycleRecords] = useState<LifeCycleItem[]>([]);
|
|
|
|
|
const [addLifecycleOpen, setAddLifecycleOpen] = useState<boolean>(false);
|
|
|
|
|
const [editLifecycleOpen, setEditLifecycleOpen] = useState<boolean>(false);
|
2022-02-10 10:34:56 -07:00
|
|
|
const [selectedLifecycleRule, setSelectedLifecycleRule] =
|
|
|
|
|
useState<LifeCycleItem | null>(null);
|
2022-02-10 17:25:59 -07:00
|
|
|
const [deleteLifecycleOpen, setDeleteLifecycleOpen] =
|
|
|
|
|
useState<boolean>(false);
|
|
|
|
|
const [selectedID, setSelectedID] = useState<string | null>(null);
|
2021-05-25 18:16:15 -05:00
|
|
|
|
2022-06-09 17:37:21 -05:00
|
|
|
const bucketName = params.bucketName || "";
|
2021-05-25 18:16:15 -05:00
|
|
|
|
2021-11-18 08:25:01 -08:00
|
|
|
const displayLifeCycleRules = hasPermission(bucketName, [
|
|
|
|
|
IAM_SCOPES.S3_GET_LIFECYCLE_CONFIGURATION,
|
2021-11-02 17:34:39 -07:00
|
|
|
]);
|
|
|
|
|
|
2021-08-12 09:52:28 -07:00
|
|
|
useEffect(() => {
|
|
|
|
|
if (loadingBucket) {
|
|
|
|
|
setLoadingLifecycle(true);
|
|
|
|
|
}
|
|
|
|
|
}, [loadingBucket, setLoadingLifecycle]);
|
|
|
|
|
|
2021-05-25 18:16:15 -05:00
|
|
|
useEffect(() => {
|
|
|
|
|
if (loadingLifecycle) {
|
2021-11-02 17:34:39 -07:00
|
|
|
if (displayLifeCycleRules) {
|
|
|
|
|
api
|
|
|
|
|
.invoke("GET", `/api/v1/buckets/${bucketName}/lifecycle`)
|
|
|
|
|
.then((res: any) => {
|
|
|
|
|
const records = get(res, "lifecycle", []);
|
|
|
|
|
|
|
|
|
|
setLifecycleRecords(records || []);
|
|
|
|
|
setLoadingLifecycle(false);
|
|
|
|
|
})
|
|
|
|
|
.catch((err: ErrorResponseHandler) => {
|
|
|
|
|
console.error(err);
|
2022-02-10 17:25:59 -07:00
|
|
|
setLifecycleRecords([]);
|
2021-11-02 17:34:39 -07:00
|
|
|
setLoadingLifecycle(false);
|
|
|
|
|
});
|
|
|
|
|
} else {
|
|
|
|
|
setLoadingLifecycle(false);
|
|
|
|
|
}
|
2021-05-25 18:16:15 -05:00
|
|
|
}
|
2021-11-10 09:47:47 -08:00
|
|
|
}, [
|
|
|
|
|
loadingLifecycle,
|
|
|
|
|
setLoadingLifecycle,
|
|
|
|
|
bucketName,
|
|
|
|
|
displayLifeCycleRules,
|
|
|
|
|
]);
|
2021-05-25 18:16:15 -05:00
|
|
|
|
|
|
|
|
const closeEditLCAndRefresh = (refresh: boolean) => {
|
|
|
|
|
setEditLifecycleOpen(false);
|
2022-02-10 10:34:56 -07:00
|
|
|
setSelectedLifecycleRule(null);
|
2021-05-25 18:16:15 -05:00
|
|
|
if (refresh) {
|
|
|
|
|
setLoadingLifecycle(true);
|
|
|
|
|
}
|
|
|
|
|
};
|
|
|
|
|
|
|
|
|
|
const closeAddLCAndRefresh = (refresh: boolean) => {
|
|
|
|
|
setAddLifecycleOpen(false);
|
|
|
|
|
if (refresh) {
|
|
|
|
|
setLoadingLifecycle(true);
|
|
|
|
|
}
|
|
|
|
|
};
|
|
|
|
|
|
2022-02-10 17:25:59 -07:00
|
|
|
const closeDelLCRefresh = (refresh: boolean) => {
|
|
|
|
|
setDeleteLifecycleOpen(false);
|
|
|
|
|
setSelectedID(null);
|
|
|
|
|
|
|
|
|
|
if (refresh) {
|
|
|
|
|
setLoadingLifecycle(true);
|
|
|
|
|
}
|
|
|
|
|
};
|
|
|
|
|
|
2021-05-25 18:16:15 -05:00
|
|
|
const renderStorageClass = (objectST: any) => {
|
2022-04-04 19:13:59 -07:00
|
|
|
let stClass = get(objectST, "transition.storage_class", "");
|
|
|
|
|
stClass = get(objectST, "transition.noncurrent_storage_class", stClass);
|
2021-05-25 18:16:15 -05:00
|
|
|
|
|
|
|
|
return stClass;
|
|
|
|
|
};
|
|
|
|
|
|
|
|
|
|
const lifecycleColumns = [
|
|
|
|
|
{
|
2022-04-04 19:13:59 -07:00
|
|
|
label: "Type",
|
|
|
|
|
renderFullObject: true,
|
|
|
|
|
renderFunction: (el: LifeCycleItem) => {
|
|
|
|
|
if (!el) {
|
|
|
|
|
return <Fragment />;
|
|
|
|
|
}
|
|
|
|
|
if (
|
|
|
|
|
el.expiration &&
|
|
|
|
|
(el.expiration.days > 0 || el.expiration.noncurrent_expiration_days)
|
|
|
|
|
) {
|
|
|
|
|
return <span>Expiry</span>;
|
|
|
|
|
}
|
|
|
|
|
if (
|
|
|
|
|
el.transition &&
|
|
|
|
|
(el.transition.days > 0 || el.transition.noncurrent_transition_days)
|
|
|
|
|
) {
|
|
|
|
|
return <span>Transition</span>;
|
|
|
|
|
}
|
|
|
|
|
return <Fragment />;
|
|
|
|
|
},
|
2021-05-25 18:16:15 -05:00
|
|
|
},
|
|
|
|
|
{
|
2022-04-04 19:13:59 -07:00
|
|
|
label: "Version",
|
|
|
|
|
renderFullObject: true,
|
|
|
|
|
renderFunction: (el: LifeCycleItem) => {
|
|
|
|
|
if (!el) {
|
|
|
|
|
return <Fragment />;
|
|
|
|
|
}
|
|
|
|
|
if (el.expiration) {
|
|
|
|
|
if (el.expiration.days > 0) {
|
|
|
|
|
return <span>Current</span>;
|
|
|
|
|
} else if (el.expiration.noncurrent_expiration_days) {
|
|
|
|
|
return <span>Non-Current</span>;
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
if (el.transition) {
|
|
|
|
|
if (el.transition.days > 0) {
|
|
|
|
|
return <span>Current</span>;
|
|
|
|
|
} else if (el.transition.noncurrent_transition_days) {
|
|
|
|
|
return <span>Non-Current</span>;
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
},
|
2021-05-25 18:16:15 -05:00
|
|
|
},
|
|
|
|
|
{
|
2022-04-04 19:13:59 -07:00
|
|
|
label: "Tier",
|
|
|
|
|
elementKey: "storage_class",
|
|
|
|
|
renderFunction: renderStorageClass,
|
|
|
|
|
renderFullObject: true,
|
2021-05-25 18:16:15 -05:00
|
|
|
},
|
|
|
|
|
{
|
2022-04-04 19:13:59 -07:00
|
|
|
label: "Prefix",
|
|
|
|
|
elementKey: "prefix",
|
2021-05-25 18:16:15 -05:00
|
|
|
},
|
|
|
|
|
{
|
2022-04-04 19:13:59 -07:00
|
|
|
label: "After",
|
2021-05-25 18:16:15 -05:00
|
|
|
renderFullObject: true,
|
2022-04-04 19:13:59 -07:00
|
|
|
renderFunction: (el: LifeCycleItem) => {
|
|
|
|
|
if (!el) {
|
|
|
|
|
return <Fragment />;
|
|
|
|
|
}
|
|
|
|
|
if (el.expiration) {
|
|
|
|
|
if (el.expiration.days > 0) {
|
|
|
|
|
return <span>{el.expiration.days} days</span>;
|
|
|
|
|
} else if (el.expiration.noncurrent_expiration_days) {
|
|
|
|
|
return <span>{el.expiration.noncurrent_expiration_days} days</span>;
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
if (el.transition) {
|
|
|
|
|
if (el.transition.days > 0) {
|
|
|
|
|
return <span>{el.transition.days} days</span>;
|
|
|
|
|
} else if (el.transition.noncurrent_transition_days) {
|
|
|
|
|
return <span>{el.transition.noncurrent_transition_days} days</span>;
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
},
|
|
|
|
|
},
|
|
|
|
|
{
|
|
|
|
|
label: "Status",
|
|
|
|
|
elementKey: "status",
|
2021-05-25 18:16:15 -05:00
|
|
|
},
|
|
|
|
|
];
|
|
|
|
|
|
2022-02-10 10:34:56 -07:00
|
|
|
const lifecycleActions = [
|
|
|
|
|
{
|
|
|
|
|
type: "view",
|
|
|
|
|
|
|
|
|
|
onClick(valueToSend: any): any {
|
|
|
|
|
setSelectedLifecycleRule(valueToSend);
|
|
|
|
|
setEditLifecycleOpen(true);
|
|
|
|
|
},
|
|
|
|
|
},
|
2022-02-10 17:25:59 -07:00
|
|
|
{
|
|
|
|
|
type: "delete",
|
|
|
|
|
onClick(valueToDelete: string): any {
|
|
|
|
|
setSelectedID(valueToDelete);
|
|
|
|
|
setDeleteLifecycleOpen(true);
|
|
|
|
|
},
|
|
|
|
|
sendOnlyId: true,
|
|
|
|
|
},
|
2022-02-10 10:34:56 -07:00
|
|
|
];
|
|
|
|
|
|
2021-05-25 18:16:15 -05:00
|
|
|
return (
|
|
|
|
|
<Fragment>
|
2022-02-10 10:34:56 -07:00
|
|
|
{editLifecycleOpen && selectedLifecycleRule && (
|
2021-05-25 18:16:15 -05:00
|
|
|
<EditLifecycleConfiguration
|
|
|
|
|
open={editLifecycleOpen}
|
|
|
|
|
closeModalAndRefresh={closeEditLCAndRefresh}
|
|
|
|
|
selectedBucket={bucketName}
|
2022-04-04 19:13:59 -07:00
|
|
|
lifecycleRule={selectedLifecycleRule}
|
2021-05-25 18:16:15 -05:00
|
|
|
/>
|
|
|
|
|
)}
|
|
|
|
|
{addLifecycleOpen && (
|
|
|
|
|
<AddLifecycleModal
|
|
|
|
|
open={addLifecycleOpen}
|
|
|
|
|
bucketName={bucketName}
|
|
|
|
|
closeModalAndRefresh={closeAddLCAndRefresh}
|
|
|
|
|
/>
|
|
|
|
|
)}
|
2022-02-10 17:25:59 -07:00
|
|
|
{deleteLifecycleOpen && selectedID && (
|
|
|
|
|
<DeleteBucketLifecycleRule
|
|
|
|
|
id={selectedID}
|
|
|
|
|
bucket={bucketName}
|
|
|
|
|
deleteOpen={deleteLifecycleOpen}
|
|
|
|
|
onCloseAndRefresh={closeDelLCRefresh}
|
|
|
|
|
/>
|
|
|
|
|
)}
|
2021-05-25 18:16:15 -05:00
|
|
|
<Grid container>
|
|
|
|
|
<Grid item xs={12} className={classes.actionsTray}>
|
2021-11-04 15:29:31 -07:00
|
|
|
<PanelTitle>Lifecycle Rules</PanelTitle>
|
2021-11-18 08:25:01 -08:00
|
|
|
<SecureComponent
|
|
|
|
|
scopes={[
|
|
|
|
|
IAM_SCOPES.S3_PUT_LIFECYCLE_CONFIGURATION,
|
|
|
|
|
IAM_SCOPES.ADMIN_LIST_TIERS,
|
|
|
|
|
]}
|
|
|
|
|
resource={bucketName}
|
|
|
|
|
matchAll
|
2021-12-13 22:37:22 -08:00
|
|
|
errorProps={{ disabled: true }}
|
2021-11-18 08:25:01 -08:00
|
|
|
>
|
2022-09-09 17:42:30 -05:00
|
|
|
<TooltipWrapper tooltip={"Add Lifecycle Rule"}>
|
|
|
|
|
<Button
|
|
|
|
|
id={"add-bucket-lifecycle-rule"}
|
|
|
|
|
onClick={() => {
|
|
|
|
|
setAddLifecycleOpen(true);
|
|
|
|
|
}}
|
|
|
|
|
label={"Add Lifecycle Rule"}
|
|
|
|
|
icon={<AddIcon />}
|
|
|
|
|
variant={"callAction"}
|
|
|
|
|
/>
|
|
|
|
|
</TooltipWrapper>
|
2021-11-18 08:25:01 -08:00
|
|
|
</SecureComponent>
|
2021-05-25 18:16:15 -05:00
|
|
|
</Grid>
|
|
|
|
|
<Grid item xs={12}>
|
2021-11-18 08:25:01 -08:00
|
|
|
<SecureComponent
|
|
|
|
|
scopes={[IAM_SCOPES.S3_GET_LIFECYCLE_CONFIGURATION]}
|
|
|
|
|
resource={bucketName}
|
|
|
|
|
errorProps={{ disabled: true }}
|
|
|
|
|
>
|
|
|
|
|
<TableWrapper
|
2022-02-10 10:34:56 -07:00
|
|
|
itemActions={lifecycleActions}
|
2021-11-18 08:25:01 -08:00
|
|
|
columns={lifecycleColumns}
|
|
|
|
|
isLoading={loadingLifecycle}
|
|
|
|
|
records={lifecycleRecords}
|
|
|
|
|
entityName="Lifecycle"
|
|
|
|
|
customEmptyMessage="There are no Lifecycle rules yet"
|
|
|
|
|
idField="id"
|
|
|
|
|
customPaperHeight={classes.twHeight}
|
|
|
|
|
/>
|
|
|
|
|
</SecureComponent>
|
2021-10-19 19:15:58 -07:00
|
|
|
</Grid>
|
2021-11-01 21:46:45 -06:00
|
|
|
{!loadingLifecycle && (
|
|
|
|
|
<Grid item xs={12}>
|
2022-02-15 10:47:28 -07:00
|
|
|
<br />
|
2021-11-01 21:46:45 -06:00
|
|
|
<HelpBox
|
|
|
|
|
title={"Lifecycle Rules"}
|
|
|
|
|
iconComponent={<TiersIcon />}
|
|
|
|
|
help={
|
|
|
|
|
<Fragment>
|
|
|
|
|
MinIO Object Lifecycle Management allows creating rules for
|
|
|
|
|
time or date based automatic transition or expiry of objects.
|
|
|
|
|
For object transition, MinIO automatically moves the object to
|
|
|
|
|
a configured remote storage tier.
|
|
|
|
|
<br />
|
|
|
|
|
<br />
|
|
|
|
|
You can learn more at our{" "}
|
|
|
|
|
<a
|
2022-09-23 00:37:32 -05:00
|
|
|
href="https://min.io/docs/minio/linux/administration/object-management/object-lifecycle-management.html?ref=con"
|
2021-11-01 21:46:45 -06:00
|
|
|
target="_blank"
|
|
|
|
|
rel="noreferrer"
|
|
|
|
|
>
|
|
|
|
|
documentation
|
|
|
|
|
</a>
|
|
|
|
|
.
|
|
|
|
|
</Fragment>
|
|
|
|
|
}
|
|
|
|
|
/>
|
|
|
|
|
</Grid>
|
|
|
|
|
)}
|
2021-05-25 18:16:15 -05:00
|
|
|
</Grid>
|
|
|
|
|
</Fragment>
|
|
|
|
|
);
|
|
|
|
|
};
|
|
|
|
|
|
2022-05-18 17:02:26 -05:00
|
|
|
export default withStyles(styles)(BucketLifecyclePanel);
|