2021-05-10 15:27:52 -07:00
|
|
|
// This file is part of MinIO Kubernetes Cloud
|
|
|
|
|
// 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/>.
|
|
|
|
|
|
|
|
|
|
import React, { useEffect, useState } from "react";
|
|
|
|
|
import { connect } from "react-redux";
|
|
|
|
|
import Grid from "@material-ui/core/Grid";
|
|
|
|
|
import { Button, LinearProgress } from "@material-ui/core";
|
|
|
|
|
import { createStyles, Theme, withStyles } from "@material-ui/core/styles";
|
|
|
|
|
import api from "../../../../common/api";
|
|
|
|
|
import {
|
|
|
|
|
setErrorSnackMessage,
|
|
|
|
|
setModalErrorSnackMessage,
|
|
|
|
|
} from "../../../../actions";
|
|
|
|
|
import {
|
|
|
|
|
fieldBasic,
|
|
|
|
|
modalBasic,
|
|
|
|
|
} from "../../Common/FormComponents/common/styleLibrary";
|
|
|
|
|
import ModalWrapper from "../../Common/ModalWrapper/ModalWrapper";
|
|
|
|
|
import CodeMirrorWrapper from "../../Common/FormComponents/CodeMirrorWrapper/CodeMirrorWrapper";
|
|
|
|
|
|
|
|
|
|
const styles = (theme: Theme) =>
|
|
|
|
|
createStyles({
|
|
|
|
|
jsonPolicyEditor: {
|
|
|
|
|
minHeight: 400,
|
|
|
|
|
width: "100%",
|
|
|
|
|
},
|
|
|
|
|
buttonContainer: {
|
|
|
|
|
textAlign: "right",
|
|
|
|
|
},
|
|
|
|
|
...modalBasic,
|
|
|
|
|
...fieldBasic,
|
|
|
|
|
});
|
|
|
|
|
|
|
|
|
|
interface ITenantYAML {
|
|
|
|
|
yaml: string;
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
interface ITenantYAMLProps {
|
|
|
|
|
classes: any;
|
|
|
|
|
open: boolean;
|
|
|
|
|
closeModalAndRefresh: (refresh: boolean) => void;
|
|
|
|
|
tenant: string;
|
|
|
|
|
namespace: string;
|
|
|
|
|
setModalErrorSnackMessage: typeof setModalErrorSnackMessage;
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
const TenantYAML = ({
|
|
|
|
|
classes,
|
|
|
|
|
open,
|
|
|
|
|
closeModalAndRefresh,
|
|
|
|
|
tenant,
|
|
|
|
|
namespace,
|
|
|
|
|
}: ITenantYAMLProps) => {
|
|
|
|
|
const [addLoading, setAddLoading] = useState<boolean>(false);
|
|
|
|
|
const [loading, setLoading] = useState<boolean>(false);
|
|
|
|
|
const [tenantYaml, setTenantYaml] = useState<string>("");
|
|
|
|
|
|
|
|
|
|
const updateTenant = (event: React.FormEvent) => {
|
|
|
|
|
event.preventDefault();
|
|
|
|
|
if (addLoading) {
|
|
|
|
|
return;
|
|
|
|
|
}
|
|
|
|
|
setAddLoading(true);
|
|
|
|
|
api
|
|
|
|
|
.invoke("PUT", `/api/v1/namespaces/${namespace}/tenants/${tenant}/yaml`, {
|
|
|
|
|
yaml: tenantYaml,
|
|
|
|
|
})
|
|
|
|
|
.then((res) => {
|
|
|
|
|
setAddLoading(false);
|
|
|
|
|
closeModalAndRefresh(true);
|
|
|
|
|
})
|
|
|
|
|
.catch((err) => {
|
|
|
|
|
setAddLoading(false);
|
|
|
|
|
setModalErrorSnackMessage(err);
|
|
|
|
|
});
|
|
|
|
|
};
|
|
|
|
|
|
|
|
|
|
// check the permissions for creating bucket
|
|
|
|
|
useEffect(() => {
|
|
|
|
|
api
|
|
|
|
|
.invoke("GET", `/api/v1/namespaces/${namespace}/tenants/${tenant}/yaml`)
|
|
|
|
|
.then((res: ITenantYAML) => {
|
|
|
|
|
setLoading(false);
|
|
|
|
|
setTenantYaml(res.yaml);
|
|
|
|
|
})
|
|
|
|
|
.catch((err: any) => {
|
|
|
|
|
setLoading(false);
|
|
|
|
|
setErrorSnackMessage(err);
|
|
|
|
|
});
|
|
|
|
|
}, [tenant, namespace]);
|
|
|
|
|
|
|
|
|
|
useEffect(() => {}, []);
|
|
|
|
|
|
|
|
|
|
const validSave = tenantYaml.trim() !== "";
|
|
|
|
|
|
|
|
|
|
return (
|
|
|
|
|
<ModalWrapper
|
|
|
|
|
modalOpen={open}
|
|
|
|
|
onClose={() => {
|
|
|
|
|
closeModalAndRefresh(false);
|
|
|
|
|
}}
|
|
|
|
|
title={`YAML`}
|
|
|
|
|
>
|
|
|
|
|
{loading && <LinearProgress />}
|
2021-05-10 17:34:54 -07:00
|
|
|
{!loading && (
|
|
|
|
|
<form
|
|
|
|
|
noValidate
|
|
|
|
|
autoComplete="off"
|
|
|
|
|
onSubmit={(e: React.FormEvent<HTMLFormElement>) => {
|
|
|
|
|
updateTenant(e);
|
|
|
|
|
}}
|
|
|
|
|
>
|
|
|
|
|
<Grid container>
|
|
|
|
|
<Grid item xs={12} className={classes.formScrollable}>
|
|
|
|
|
<Grid item xs={12}>
|
|
|
|
|
<br />
|
|
|
|
|
</Grid>
|
|
|
|
|
<CodeMirrorWrapper
|
|
|
|
|
label={`Tenant Specification`}
|
|
|
|
|
value={tenantYaml}
|
|
|
|
|
mode={"yaml"}
|
|
|
|
|
onBeforeChange={(editor, data, value) => {
|
|
|
|
|
setTenantYaml(value);
|
|
|
|
|
}}
|
|
|
|
|
/>
|
2021-05-10 15:27:52 -07:00
|
|
|
</Grid>
|
2021-05-10 17:34:54 -07:00
|
|
|
<Grid item xs={12} className={classes.buttonContainer}>
|
|
|
|
|
<Button
|
|
|
|
|
type="submit"
|
|
|
|
|
variant="contained"
|
|
|
|
|
color="primary"
|
|
|
|
|
disabled={addLoading || !validSave}
|
|
|
|
|
>
|
|
|
|
|
Save
|
|
|
|
|
</Button>
|
2021-05-10 15:27:52 -07:00
|
|
|
</Grid>
|
2021-05-10 17:34:54 -07:00
|
|
|
{addLoading && (
|
|
|
|
|
<Grid item xs={12}>
|
|
|
|
|
<LinearProgress />
|
|
|
|
|
</Grid>
|
|
|
|
|
)}
|
|
|
|
|
</Grid>
|
|
|
|
|
</form>
|
|
|
|
|
)}
|
2021-05-10 15:27:52 -07:00
|
|
|
</ModalWrapper>
|
|
|
|
|
);
|
|
|
|
|
};
|
|
|
|
|
|
|
|
|
|
const mapDispatchToProps = {
|
|
|
|
|
setModalErrorSnackMessage,
|
|
|
|
|
};
|
|
|
|
|
|
|
|
|
|
const connector = connect(null, mapDispatchToProps);
|
|
|
|
|
|
|
|
|
|
export default withStyles(styles)(connector(TenantYAML));
|