From 36dd4ef3eb99944fa973a62c997b6750512181da Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?=E7=A5=9E=E6=A5=BD=E5=9D=82=E3=83=8B=E3=83=A3=E3=83=B3?= Date: Mon, 19 May 2025 14:27:35 +0800 Subject: [PATCH] update: update formSchema for jump server & fix username validate message --- .../components/access/AccessFormSSHConfig.tsx | 39 ++++++++++++++++++- 1 file changed, 38 insertions(+), 1 deletion(-) diff --git a/ui/src/components/access/AccessFormSSHConfig.tsx b/ui/src/components/access/AccessFormSSHConfig.tsx index 936988ee..cdd3c8e2 100644 --- a/ui/src/components/access/AccessFormSSHConfig.tsx +++ b/ui/src/components/access/AccessFormSSHConfig.tsx @@ -29,6 +29,42 @@ const initFormModel = (): AccessFormSSHConfigFieldValues => { const AccessFormSSHConfig = ({ form: formInst, formName, disabled, initialValues, onValuesChange }: AccessFormSSHConfigProps) => { const { t } = useTranslation(); + const jumpServerConfigItemSchema = z + .object({ + host: z.string().refine((v) => validDomainName(v) || validIPv4Address(v) || validIPv6Address(v), t("common.errmsg.host_invalid")), + port: z.preprocess( + (v) => Number(v), + z + .number() + .int(t("access.form.ssh_port.placeholder")) + .refine((v) => validPortNumber(v), t("common.errmsg.port_invalid")) + ), + username: z + .string() + .min(1, t("access.form.ssh_username.placeholder")) + .max(64, t("common.errmsg.string_max", { max: 64 })), + password: z + .string() + .max(64, t("common.errmsg.string_max", { max: 64 })) + .nullish(), + key: z + .string() + .max(20480, t("common.errmsg.string_max", { max: 20480 })) + .nullish(), + keyPassphrase: z + .string() + .max(20480, t("common.errmsg.string_max", { max: 20480 })) + .nullish(), + }) + .superRefine((data, ctx) => { + if (data.keyPassphrase && !data.key) { + ctx.addIssue({ + path: ["keyPassphrase"], + code: z.ZodIssueCode.custom, + message: t("access.form.ssh_key.placeholder"), + }); + } + }); const formSchema = z.object({ host: z.string().refine((v) => validDomainName(v) || validIPv4Address(v) || validIPv6Address(v), t("common.errmsg.host_invalid")), port: z.preprocess( @@ -40,7 +76,7 @@ const AccessFormSSHConfig = ({ form: formInst, formName, disabled, initialValues ), username: z .string() - .min(1, "access.form.ssh_username.placeholder") + .min(1, t("access.form.ssh_username.placeholder")) .max(64, t("common.errmsg.string_max", { max: 64 })), password: z .string() @@ -55,6 +91,7 @@ const AccessFormSSHConfig = ({ form: formInst, formName, disabled, initialValues .max(20480, t("common.errmsg.string_max", { max: 20480 })) .nullish() .refine((v) => !v || formInst.getFieldValue("key"), t("access.form.ssh_key.placeholder")), + jumpServerConfig: jumpServerConfigItemSchema.array().nullish(), }); const formRule = createSchemaFieldRule(formSchema);