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";
|
2021-05-25 18:16:15 -05:00
|
|
|
import { connect } 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";
|
|
|
|
|
import * as reactMoment from "react-moment";
|
2021-10-21 20:20:27 -05:00
|
|
|
import Grid from "@mui/material/Grid";
|
2021-11-02 17:34:39 -07:00
|
|
|
import { BucketInfo, 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";
|
|
|
|
|
import { setErrorSnackMessage } from "../../../../actions";
|
2021-07-28 20:09:48 -05:00
|
|
|
import { AppState } from "../../../../store";
|
|
|
|
|
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";
|
2021-11-18 08:25:01 -08:00
|
|
|
import SecureComponent, {
|
|
|
|
|
hasPermission,
|
|
|
|
|
} from "../../../../common/SecureComponent/SecureComponent";
|
|
|
|
|
import { IAM_SCOPES } from "../../../../common/SecureComponent/permissions";
|
2022-01-13 19:55:30 +00:00
|
|
|
import RBIconButton from "./SummaryItems/RBIconButton";
|
2022-02-10 17:25:59 -07:00
|
|
|
import DeleteBucketLifecycleRule from "./DeleteBucketLifecycleRule";
|
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;
|
|
|
|
|
match: any;
|
|
|
|
|
setErrorSnackMessage: typeof setErrorSnackMessage;
|
2021-08-12 09:52:28 -07:00
|
|
|
loadingBucket: boolean;
|
2021-11-02 17:34:39 -07:00
|
|
|
bucketInfo: BucketInfo | null;
|
2021-05-25 18:16:15 -05:00
|
|
|
}
|
|
|
|
|
|
|
|
|
|
const BucketLifecyclePanel = ({
|
|
|
|
|
classes,
|
|
|
|
|
match,
|
|
|
|
|
setErrorSnackMessage,
|
2021-08-12 09:52:28 -07:00
|
|
|
loadingBucket,
|
2021-11-02 17:34:39 -07:00
|
|
|
bucketInfo,
|
2021-05-25 18:16:15 -05:00
|
|
|
}: IBucketLifecyclePanelProps) => {
|
|
|
|
|
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
|
|
|
|
|
|
|
|
const bucketName = match.params["bucketName"];
|
|
|
|
|
|
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 expirationRender = (expiration: any) => {
|
|
|
|
|
if (expiration.days) {
|
|
|
|
|
return `${expiration.days} day${expiration.days > 1 ? "s" : ""}`;
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
if (expiration.date === "0001-01-01T00:00:00Z") {
|
|
|
|
|
return "";
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
return <reactMoment.default>{expiration.date}</reactMoment.default>;
|
|
|
|
|
};
|
|
|
|
|
|
|
|
|
|
const transitionRender = (transition: any) => {
|
|
|
|
|
if (transition.days) {
|
|
|
|
|
return `${transition.days} day${transition.days > 1 ? "s" : ""}`;
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
if (transition.date === "0001-01-01T00:00:00Z") {
|
|
|
|
|
return "";
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
return <reactMoment.default>{transition.date}</reactMoment.default>;
|
|
|
|
|
};
|
|
|
|
|
|
|
|
|
|
const renderStorageClass = (objectST: any) => {
|
|
|
|
|
const stClass = get(objectST, "transition.storage_class", "");
|
|
|
|
|
|
|
|
|
|
return stClass;
|
|
|
|
|
};
|
|
|
|
|
|
|
|
|
|
const lifecycleColumns = [
|
|
|
|
|
{ label: "ID", elementKey: "id" },
|
|
|
|
|
{
|
|
|
|
|
label: "Prefix",
|
|
|
|
|
elementKey: "prefix",
|
|
|
|
|
},
|
|
|
|
|
{
|
|
|
|
|
label: "Status",
|
|
|
|
|
elementKey: "status",
|
|
|
|
|
},
|
|
|
|
|
{
|
|
|
|
|
label: "Expiration",
|
|
|
|
|
elementKey: "expiration",
|
|
|
|
|
renderFunction: expirationRender,
|
|
|
|
|
},
|
|
|
|
|
{
|
|
|
|
|
label: "Transition",
|
|
|
|
|
elementKey: "transition",
|
|
|
|
|
renderFunction: transitionRender,
|
|
|
|
|
},
|
|
|
|
|
{
|
|
|
|
|
label: "Storage Class",
|
|
|
|
|
elementKey: "storage_class",
|
|
|
|
|
renderFunction: renderStorageClass,
|
|
|
|
|
renderFullObject: true,
|
|
|
|
|
},
|
|
|
|
|
];
|
|
|
|
|
|
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-02-10 10:34:56 -07:00
|
|
|
lifecycle={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-01-13 19:55:30 +00:00
|
|
|
<RBIconButton
|
|
|
|
|
tooltip={"Add Lifecycle Rule"}
|
2021-11-02 17:34:39 -07:00
|
|
|
onClick={() => {
|
|
|
|
|
setAddLifecycleOpen(true);
|
|
|
|
|
}}
|
2022-01-13 19:55:30 +00:00
|
|
|
text={"Add Lifecycle Rule"}
|
|
|
|
|
icon={<AddIcon />}
|
|
|
|
|
color="primary"
|
|
|
|
|
variant={"contained"}
|
|
|
|
|
/>
|
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}>
|
|
|
|
|
<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
|
|
|
|
|
href="https://docs.min.io/minio/baremetal/lifecycle-management/lifecycle-management-overview.html?ref=con"
|
|
|
|
|
target="_blank"
|
|
|
|
|
rel="noreferrer"
|
|
|
|
|
>
|
|
|
|
|
documentation
|
|
|
|
|
</a>
|
|
|
|
|
.
|
|
|
|
|
</Fragment>
|
|
|
|
|
}
|
|
|
|
|
/>
|
|
|
|
|
</Grid>
|
|
|
|
|
)}
|
2021-05-25 18:16:15 -05:00
|
|
|
</Grid>
|
|
|
|
|
</Fragment>
|
|
|
|
|
);
|
|
|
|
|
};
|
|
|
|
|
|
|
|
|
|
const mapState = (state: AppState) => ({
|
|
|
|
|
session: state.console.session,
|
2021-08-12 09:52:28 -07:00
|
|
|
loadingBucket: state.buckets.bucketDetails.loadingBucket,
|
2021-11-02 17:34:39 -07:00
|
|
|
bucketInfo: state.buckets.bucketDetails.bucketInfo,
|
2021-05-25 18:16:15 -05:00
|
|
|
});
|
|
|
|
|
|
|
|
|
|
const connector = connect(mapState, {
|
|
|
|
|
setErrorSnackMessage,
|
|
|
|
|
});
|
|
|
|
|
|
|
|
|
|
export default withStyles(styles)(connector(BucketLifecyclePanel));
|