mirror of
https://github.com/usual2970/certimate.git
synced 2025-10-05 14:04:54 +00:00
feat: auto cleanup workflow history runs and expired certificates
This commit is contained in:
@@ -1,5 +1,5 @@
|
||||
import { useTranslation } from "react-i18next";
|
||||
import { Form, type FormInstance, Input } from "antd";
|
||||
import { AutoComplete, Form, type FormInstance, Input } from "antd";
|
||||
import { createSchemaFieldRule } from "antd-zod";
|
||||
import { z } from "zod";
|
||||
|
||||
@@ -92,7 +92,11 @@ const AccessFormAzureConfig = ({ form: formInst, formName, disabled, initialValu
|
||||
rules={[formRule]}
|
||||
tooltip={<span dangerouslySetInnerHTML={{ __html: t("access.form.azure_cloud_name.tooltip") }}></span>}
|
||||
>
|
||||
<Input placeholder={t("access.form.azure_cloud_name.placeholder")} />
|
||||
<AutoComplete
|
||||
options={["public", "azureusgovernment", "azurechina"].map((value) => ({ value }))}
|
||||
placeholder={t("access.form.azure_cloud_name.placeholder")}
|
||||
filterOption={(inputValue, option) => option!.value.toLowerCase().includes(inputValue.toLowerCase())}
|
||||
/>
|
||||
</Form.Item>
|
||||
</Form>
|
||||
);
|
||||
|
@@ -3,6 +3,7 @@ export const SETTINGS_NAMES = Object.freeze({
|
||||
NOTIFY_TEMPLATES: "notifyTemplates",
|
||||
NOTIFY_CHANNELS: "notifyChannels",
|
||||
SSL_PROVIDER: "sslProvider",
|
||||
PERSISTENCE: "persistence",
|
||||
} as const);
|
||||
|
||||
export type SettingsNames = (typeof SETTINGS_NAMES)[keyof typeof SETTINGS_NAMES];
|
||||
@@ -165,3 +166,10 @@ export type SSLProviderGoogleTrustServicesConfig = {
|
||||
eabHmacKey: string;
|
||||
};
|
||||
// #endregion
|
||||
|
||||
// #region Settings: Persistence
|
||||
export type PersistenceSettingsContent = {
|
||||
workflowRunsMaxDaysRetention?: number;
|
||||
expiredCertificatesMaxDaysRetention?: number;
|
||||
};
|
||||
// #endregion
|
||||
|
@@ -90,5 +90,15 @@
|
||||
"settings.sslprovider.form.gts_eab_kid.tooltip": "For more information, see <a href=\"https://cloud.google.com/certificate-manager/docs/public-ca-tutorial\" target=\"_blank\">https://cloud.google.com/certificate-manager/docs/public-ca-tutorial</a>",
|
||||
"settings.sslprovider.form.gts_eab_hmac_key.label": "EAB HMAC Key",
|
||||
"settings.sslprovider.form.gts_eab_hmac_key.placeholder": "Please enter EAB HMAC Key",
|
||||
"settings.sslprovider.form.gts_eab_hmac_key.tooltip": "For more information, see <a href=\"https://cloud.google.com/certificate-manager/docs/public-ca-tutorial\" target=\"_blank\">https://cloud.google.com/certificate-manager/docs/public-ca-tutorial</a>"
|
||||
"settings.sslprovider.form.gts_eab_hmac_key.tooltip": "For more information, see <a href=\"https://cloud.google.com/certificate-manager/docs/public-ca-tutorial\" target=\"_blank\">https://cloud.google.com/certificate-manager/docs/public-ca-tutorial</a>",
|
||||
|
||||
"settings.persistence.tab": "Persistence",
|
||||
"settings.persistence.form.workflow_runs_max_days.label": "Max days retention of workflow history runs",
|
||||
"settings.persistence.form.workflow_runs_max_days.placeholder": "Please enter the maximum retention days of workflow history runs",
|
||||
"settings.persistence.form.workflow_runs_max_days.unit": "days",
|
||||
"settings.persistence.form.workflow_runs_max_days.extra": "Set to <b>0</b> to disable cleanup workflow history runs. It is recommended to set it to <b>180</b> days or more.",
|
||||
"settings.persistence.form.expired_certificates_max_days.label": "Max days retention of expired certificates",
|
||||
"settings.persistence.form.expired_certificates_max_days.placeholder": "Please enter the maximum retention days of expired certificates",
|
||||
"settings.persistence.form.expired_certificates_max_days.unit": "days",
|
||||
"settings.persistence.form.expired_certificates_max_days.extra": "Set to <b>0</emb> to disable cleanup expired certificates."
|
||||
}
|
||||
|
@@ -71,7 +71,7 @@
|
||||
"settings.notification.channel.form.wecom_webhook_url.placeholder": "请输入机器人 Webhook 地址",
|
||||
"settings.notification.channel.form.wecom_webhook_url.tooltip": "这是什么?请参阅 <a href=\"https://open.work.weixin.qq.com/help2/pc/18401#%E5%85%AD%E3%80%81%E7%BE%A4%E6%9C%BA%E5%99%A8%E4%BA%BAWebhook%E5%9C%B0%E5%9D%80\" target=\"_blank\">https://open.work.weixin.qq.com/help2/pc/18401</a>",
|
||||
|
||||
"settings.sslprovider.tab": "证书颁发机构(CA)",
|
||||
"settings.sslprovider.tab": "证书颁发机构",
|
||||
"settings.sslprovider.form.provider.label": "ACME 服务商",
|
||||
"settings.sslprovider.form.provider.option.letsencrypt.label": "Let's Encrypt",
|
||||
"settings.sslprovider.form.provider.option.letsencrypt_staging.label": "Let's Encrypt 测试环境",
|
||||
@@ -90,5 +90,15 @@
|
||||
"settings.sslprovider.form.gts_eab_kid.tooltip": "这是什么?请参阅 <a href=\"https://cloud.google.com/certificate-manager/docs/public-ca-tutorial\" target=\"_blank\">https://cloud.google.com/certificate-manager/docs/public-ca-tutorial</a>",
|
||||
"settings.sslprovider.form.gts_eab_hmac_key.label": "EAB HMAC Key",
|
||||
"settings.sslprovider.form.gts_eab_hmac_key.placeholder": "请输入 EAB HMAC Key",
|
||||
"settings.sslprovider.form.gts_eab_hmac_key.tooltip": "这是什么?请参阅 <a href=\"https://cloud.google.com/certificate-manager/docs/public-ca-tutorial\" target=\"_blank\">https://cloud.google.com/certificate-manager/docs/public-ca-tutorial</a>"
|
||||
"settings.sslprovider.form.gts_eab_hmac_key.tooltip": "这是什么?请参阅 <a href=\"https://cloud.google.com/certificate-manager/docs/public-ca-tutorial\" target=\"_blank\">https://cloud.google.com/certificate-manager/docs/public-ca-tutorial</a>",
|
||||
|
||||
"settings.persistence.tab": "数据持久化",
|
||||
"settings.persistence.form.workflow_runs_max_days.label": "工作流执行历史保留天数",
|
||||
"settings.persistence.form.workflow_runs_max_days.placeholder": "请输入执行历史保留天数",
|
||||
"settings.persistence.form.workflow_runs_max_days.unit": "天",
|
||||
"settings.persistence.form.workflow_runs_max_days.extra": "设置为 <b>0</b> 表示永久保留,不会自动清理。建议设置为 <b>180</b> 天以上。",
|
||||
"settings.persistence.form.expired_certificates_max_days.label": "证书过期后保留天数",
|
||||
"settings.persistence.form.expired_certificates_max_days.placeholder": "请输入过期证书保留天数",
|
||||
"settings.persistence.form.expired_certificates_max_days.unit": "天",
|
||||
"settings.persistence.form.expired_certificates_max_days.extra": "设置为 <b>0</b> 表示永久保留,不会自动清理。"
|
||||
}
|
||||
|
@@ -85,7 +85,7 @@
|
||||
"workflow_node.deploy.form.provider_access.placeholder": "请选择主机提供商授权",
|
||||
"workflow_node.deploy.form.provider_access.tooltip": "用于部署证书,注意与申请阶段所需的 DNS 提供商相区分。",
|
||||
"workflow_node.deploy.form.provider_access.button": "新建",
|
||||
"workflow_node.deploy.form.provider_access.guide_for_local": "小贴士:由于表单限制,你同样需要为本地部署选择一个授权 —— 即使它是空白的。<br>请注意:如果你使用 Docker 安装 Certimate,“本地部署”将会部署到容器内而非宿主机上。",
|
||||
"workflow_node.deploy.form.provider_access.guide_for_local": "小贴士:由于表单限制,你同样需要为本地部署选择一个授权 —— 即使它是空白的。<br>请注意,如果你使用 Docker 安装 Certimate,“本地部署”将会部署到容器内而非宿主机上。",
|
||||
"workflow_node.deploy.form.certificate.label": "待部署证书",
|
||||
"workflow_node.deploy.form.certificate.placeholder": "请选择待部署证书",
|
||||
"workflow_node.deploy.form.certificate.tooltip": "待部署证书来自之前的申请阶段。如果选项为空请先确保前序节点配置正确。",
|
||||
|
@@ -3,6 +3,7 @@ import { useTranslation } from "react-i18next";
|
||||
import { Outlet, useLocation, useNavigate } from "react-router-dom";
|
||||
import {
|
||||
ApiOutlined as ApiOutlinedIcon,
|
||||
DatabaseOutlined as DatabaseOutlinedIcon,
|
||||
LockOutlined as LockOutlinedIcon,
|
||||
SendOutlined as SendOutlinedIcon,
|
||||
UserOutlined as UserOutlinedIcon,
|
||||
@@ -69,6 +70,15 @@ const Settings = () => {
|
||||
</Space>
|
||||
),
|
||||
},
|
||||
{
|
||||
key: "persistence",
|
||||
label: (
|
||||
<Space>
|
||||
<DatabaseOutlinedIcon />
|
||||
<label>{t("settings.persistence.tab")}</label>
|
||||
</Space>
|
||||
),
|
||||
},
|
||||
]}
|
||||
activeTabKey={tabValue}
|
||||
onTabChange={(key) => {
|
||||
|
@@ -18,7 +18,7 @@ const SettingsAccount = () => {
|
||||
const [notificationApi, NotificationContextHolder] = notification.useNotification();
|
||||
|
||||
const formSchema = z.object({
|
||||
username: z.string({ message: "settings.account.form.email.placeholder" }).email({ message: t("common.errmsg.email_invalid") }),
|
||||
username: z.string({ message: t("settings.account.form.email.placeholder") }).email({ message: t("common.errmsg.email_invalid") }),
|
||||
});
|
||||
const formRule = createSchemaFieldRule(formSchema);
|
||||
const {
|
||||
|
132
ui/src/pages/settings/SettingsPersistence.tsx
Normal file
132
ui/src/pages/settings/SettingsPersistence.tsx
Normal file
@@ -0,0 +1,132 @@
|
||||
import { useEffect, useState } from "react";
|
||||
import { useTranslation } from "react-i18next";
|
||||
import { Button, Form, InputNumber, Skeleton, message, notification } from "antd";
|
||||
import { createSchemaFieldRule } from "antd-zod";
|
||||
import { produce } from "immer";
|
||||
import { z } from "zod";
|
||||
|
||||
import Show from "@/components/Show";
|
||||
import { type PersistenceSettingsContent, SETTINGS_NAMES, type SettingsModel } from "@/domain/settings";
|
||||
import { useAntdForm } from "@/hooks";
|
||||
import { get as getSettings, save as saveSettings } from "@/repository/settings";
|
||||
import { getErrMsg } from "@/utils/error";
|
||||
|
||||
const SettingsPersistence = () => {
|
||||
const { t } = useTranslation();
|
||||
|
||||
const [messageApi, MessageContextHolder] = message.useMessage();
|
||||
const [notificationApi, NotificationContextHolder] = notification.useNotification();
|
||||
|
||||
const [settings, setSettings] = useState<SettingsModel<PersistenceSettingsContent>>();
|
||||
const [loading, setLoading] = useState(true);
|
||||
useEffect(() => {
|
||||
const fetchData = async () => {
|
||||
setLoading(true);
|
||||
|
||||
const settings = await getSettings<PersistenceSettingsContent>(SETTINGS_NAMES.PERSISTENCE);
|
||||
setSettings(settings);
|
||||
|
||||
setLoading(false);
|
||||
};
|
||||
|
||||
fetchData();
|
||||
}, []);
|
||||
|
||||
const formSchema = z.object({
|
||||
workflowRunsMaxDaysRetention: z
|
||||
.number({ message: t("settings.persistence.form.workflow_runs_max_days.placeholder") })
|
||||
.gte(0, t("settings.persistence.form.workflow_runs_max_days.placeholder")),
|
||||
expiredCertificatesMaxDaysRetention: z
|
||||
.number({ message: t("settings.persistence.form.expired_certificates_max_days.placeholder") })
|
||||
.gte(0, t("settings.persistence.form.expired_certificates_max_days.placeholder")),
|
||||
});
|
||||
const formRule = createSchemaFieldRule(formSchema);
|
||||
const {
|
||||
form: formInst,
|
||||
formPending,
|
||||
formProps,
|
||||
} = useAntdForm<z.infer<typeof formSchema>>({
|
||||
initialValues: {
|
||||
workflowRunsMaxDaysRetention: settings?.content?.workflowRunsMaxDaysRetention ?? 0,
|
||||
expiredCertificatesMaxDaysRetention: settings?.content?.expiredCertificatesMaxDaysRetention ?? 0,
|
||||
},
|
||||
onSubmit: async (values) => {
|
||||
try {
|
||||
await saveSettings(
|
||||
produce(settings!, (draft) => {
|
||||
draft.content ??= {} as PersistenceSettingsContent;
|
||||
draft.content.workflowRunsMaxDaysRetention = values.workflowRunsMaxDaysRetention;
|
||||
draft.content.expiredCertificatesMaxDaysRetention = values.expiredCertificatesMaxDaysRetention;
|
||||
})
|
||||
);
|
||||
|
||||
messageApi.success(t("common.text.operation_succeeded"));
|
||||
} catch (err) {
|
||||
notificationApi.error({ message: t("common.text.request_error"), description: getErrMsg(err) });
|
||||
|
||||
throw err;
|
||||
}
|
||||
},
|
||||
});
|
||||
const [formChanged, setFormChanged] = useState(false);
|
||||
|
||||
const handleInputChange = () => {
|
||||
const changed =
|
||||
formInst.getFieldValue("workflowRunsMaxDaysRetention") !== formProps.initialValues?.workflowRunsMaxDaysRetention ||
|
||||
formInst.getFieldValue("expiredCertificatesMaxDaysRetention") !== formProps.initialValues?.workflowRunsMaxDaysRetention;
|
||||
setFormChanged(changed);
|
||||
};
|
||||
|
||||
return (
|
||||
<>
|
||||
{MessageContextHolder}
|
||||
{NotificationContextHolder}
|
||||
|
||||
<Show when={!loading} fallback={<Skeleton active />}>
|
||||
<div className="md:max-w-[40rem]">
|
||||
<Form {...formProps} form={formInst} disabled={formPending} layout="vertical">
|
||||
<Form.Item
|
||||
name="workflowRunsMaxDaysRetention"
|
||||
label={t("settings.persistence.form.workflow_runs_max_days.label")}
|
||||
extra={<span dangerouslySetInnerHTML={{ __html: t("settings.persistence.form.workflow_runs_max_days.extra") }}></span>}
|
||||
rules={[formRule]}
|
||||
>
|
||||
<InputNumber
|
||||
className="w-full"
|
||||
min={0}
|
||||
max={36500}
|
||||
placeholder={t("settings.persistence.form.workflow_runs_max_days.placeholder")}
|
||||
addonAfter={t("settings.persistence.form.workflow_runs_max_days.unit")}
|
||||
onChange={handleInputChange}
|
||||
/>
|
||||
</Form.Item>
|
||||
|
||||
<Form.Item
|
||||
name="expiredCertificatesMaxDaysRetention"
|
||||
label={t("settings.persistence.form.expired_certificates_max_days.label")}
|
||||
extra={<span dangerouslySetInnerHTML={{ __html: t("settings.persistence.form.expired_certificates_max_days.extra") }}></span>}
|
||||
rules={[formRule]}
|
||||
>
|
||||
<InputNumber
|
||||
className="w-full"
|
||||
min={0}
|
||||
max={36500}
|
||||
placeholder={t("settings.persistence.form.expired_certificates_max_days.placeholder")}
|
||||
addonAfter={t("settings.persistence.form.expired_certificates_max_days.unit")}
|
||||
onChange={handleInputChange}
|
||||
/>
|
||||
</Form.Item>
|
||||
|
||||
<Form.Item>
|
||||
<Button type="primary" htmlType="submit" disabled={!formChanged} loading={formPending}>
|
||||
{t("common.button.save")}
|
||||
</Button>
|
||||
</Form.Item>
|
||||
</Form>
|
||||
</div>
|
||||
</Show>
|
||||
</>
|
||||
);
|
||||
};
|
||||
|
||||
export default SettingsPersistence;
|
@@ -10,6 +10,7 @@ import Settings from "./pages/settings/Settings";
|
||||
import SettingsAccount from "./pages/settings/SettingsAccount";
|
||||
import SettingsNotification from "./pages/settings/SettingsNotification";
|
||||
import SettingsPassword from "./pages/settings/SettingsPassword";
|
||||
import SettingsPersistence from "./pages/settings/SettingsPersistence";
|
||||
import SettingsSSLProvider from "./pages/settings/SettingsSSLProvider";
|
||||
import WorkflowDetail from "./pages/workflows/WorkflowDetail";
|
||||
import WorkflowList from "./pages/workflows/WorkflowList";
|
||||
@@ -64,6 +65,10 @@ export const router = createHashRouter([
|
||||
path: "/settings/ssl-provider",
|
||||
element: <SettingsSSLProvider />,
|
||||
},
|
||||
{
|
||||
path: "/settings/persistence",
|
||||
element: <SettingsPersistence />,
|
||||
},
|
||||
],
|
||||
},
|
||||
],
|
||||
|
Reference in New Issue
Block a user