Вы не можете выбрать более 25 тем Темы должны начинаться с буквы или цифры, могут содержать дефисы(-) и должны содержать не более 35 символов.

102 строки
4.2 KiB

  1. import * as React from "react";
  2. import * as HttpUtils from "utils/HttpUtils";
  3. import * as DateUtils from "utils/DateUtils";
  4. import * as UrlUtils from "utils/ApiPathConst";
  5. import {
  6. Grid, Typography, Button,
  7. Stack, Box, CircularProgress,
  8. } from '@mui/material';
  9. import { notifyActionError } from 'utils/CommonFunction';
  10. import titleBackgroundImg from 'assets/images/dashboard/gazette-bar.png'
  11. const formatLog = (responData) => {
  12. if (responData?.msg && !responData?.log) {
  13. return <>{DateUtils.datetimeStr(new Date())}<br/><span style={{ color: "red" }}>Error</span><br/>{responData.msg}</>;
  14. }
  15. const statusColor = responData?.success ? "green" : "red";
  16. const statusText = responData?.success ? "Success" : "Completed with errors";
  17. const logText = (responData?.log || []).join("\n");
  18. return (
  19. <>
  20. {DateUtils.datetimeStr(new Date())}<br/>
  21. <span style={{ color: statusColor }}>{responData?.dryRun ? "Dry-run " : ""}{statusText}</span><br/>
  22. Total: {responData?.total ?? 0}, OK: {responData?.successCount ?? 0}, Skipped: {responData?.skipped ?? 0}, Failed: {responData?.failed ?? 0}<br/>
  23. <span style={{ whiteSpace: "pre-line" }}>{logText}</span>
  24. </>
  25. );
  26. };
  27. const HkidKeyMigration = () => {
  28. const [resultStr, setResultStr] = React.useState("");
  29. const [wait, setWait] = React.useState(false);
  30. const BackgroundHead = {
  31. backgroundImage: `url(${titleBackgroundImg})`,
  32. width: 'auto',
  33. height: 'auto',
  34. backgroundSize: 'contain',
  35. backgroundRepeat: 'no-repeat',
  36. backgroundColor: '#0C489E',
  37. backgroundPosition: 'right'
  38. };
  39. const runMigration = (dryRun) => {
  40. setWait(true);
  41. HttpUtils.post({
  42. url: `${UrlUtils.HKID_REKEY_MIGRATION}?dryRun=${dryRun}&batchSize=100`,
  43. params: {},
  44. onSuccess: function (responData) {
  45. setWait(false);
  46. setResultStr(formatLog(responData));
  47. },
  48. onError: function () {
  49. setWait(false);
  50. notifyActionError("HKID re-key migration failed");
  51. }
  52. });
  53. };
  54. return (
  55. <Grid container sx={{ minHeight: '87vh', backgroundColor: "backgroundColor.default" }} direction="column">
  56. <Grid item xs={12}>
  57. <div style={BackgroundHead}>
  58. <Stack direction="row" height='70px' justifyContent="space-between" alignItems="center">
  59. <Typography ml={15} color='#FFF' variant="h4" sx={{ textShadow: "0px 0px 25px #0C489E" }}>
  60. HKID Key Migration
  61. </Typography>
  62. </Stack>
  63. </div>
  64. </Grid>
  65. <Grid item xs={12} sx={{ backgroundColor: '#ffffff', ml: 2, mt: 1 }} width="98%">
  66. <Box sx={{ borderRadius: '10px', backgroundColor: '#fff', p: 4 }}>
  67. <Typography variant="body1" sx={{ mb: 2 }}>
  68. Re-encrypt identification and checkDigit from the legacy key to the new key.
  69. Ensure Tomcat has both <code>security.hkid-secret</code> and <code>security.hkid-secret-legacy</code> configured before running.
  70. </Typography>
  71. <Stack direction="row" spacing={2}>
  72. <Button variant="outlined" size="large" disabled={wait} onClick={() => runMigration(true)}>
  73. Dry Run
  74. </Button>
  75. <Button variant="contained" size="large" disabled={wait} onClick={() => runMigration(false)}>
  76. Run Migration
  77. </Button>
  78. {wait ? <CircularProgress size={32} /> : null}
  79. </Stack>
  80. </Box>
  81. </Grid>
  82. <Grid item xs={12} sx={{ backgroundColor: '#ffffff', ml: 2, mt: 1, mb: 2 }} width="98%">
  83. <Box sx={{ borderRadius: '10px', backgroundColor: '#fff', p: 4 }}>
  84. <Typography variant="h4">Result:</Typography>
  85. <Box sx={{ pl: 2, pt: 2 }}>{resultStr}</Box>
  86. </Box>
  87. </Grid>
  88. </Grid>
  89. );
  90. };
  91. export default HkidKeyMigration;