import * as React from "react";
import * as HttpUtils from "utils/HttpUtils";
import * as DateUtils from "utils/DateUtils";
import * as UrlUtils from "utils/ApiPathConst";
import {
Grid, Typography, Button,
Stack, Box, CircularProgress,
} from '@mui/material';
import { notifyActionError } from 'utils/CommonFunction';
import titleBackgroundImg from 'assets/images/dashboard/gazette-bar.png'
const formatLog = (responData) => {
if (responData?.msg && !responData?.log) {
return <>{DateUtils.datetimeStr(new Date())}Error {responData.msg}>;
}
const statusColor = responData?.success ? "green" : "red";
const statusText = responData?.success ? "Success" : "Completed with errors";
const logText = (responData?.log || []).join("\n");
return (
<>
{DateUtils.datetimeStr(new Date())}
{responData?.dryRun ? "Dry-run " : ""}{statusText}
Total: {responData?.total ?? 0}, OK: {responData?.successCount ?? 0}, Skipped: {responData?.skipped ?? 0}, Failed: {responData?.failed ?? 0}
{logText}
>
);
};
const HkidKeyMigration = () => {
const [resultStr, setResultStr] = React.useState("");
const [wait, setWait] = React.useState(false);
const BackgroundHead = {
backgroundImage: `url(${titleBackgroundImg})`,
width: 'auto',
height: 'auto',
backgroundSize: 'contain',
backgroundRepeat: 'no-repeat',
backgroundColor: '#0C489E',
backgroundPosition: 'right'
};
const runMigration = (dryRun) => {
setWait(true);
HttpUtils.post({
url: `${UrlUtils.HKID_REKEY_MIGRATION}?dryRun=${dryRun}&batchSize=100`,
params: {},
onSuccess: function (responData) {
setWait(false);
setResultStr(formatLog(responData));
},
onError: function () {
setWait(false);
notifyActionError("HKID re-key migration failed");
}
});
};
return (
HKID Key Migration
Re-encrypt identification and checkDigit from the legacy key to the new key.
Ensure Tomcat has both security.hkid-secret and security.hkid-secret-legacy configured before running.
runMigration(true)}>
Dry Run
runMigration(false)}>
Run Migration
{wait ? : null}
Result:
{resultStr}
);
};
export default HkidKeyMigration;