diff --git a/backend/src/ee/services/dynamic-secret/providers/totp.ts b/backend/src/ee/services/dynamic-secret/providers/totp.ts index 2565fc30d..d985d2125 100644 --- a/backend/src/ee/services/dynamic-secret/providers/totp.ts +++ b/backend/src/ee/services/dynamic-secret/providers/totp.ts @@ -52,12 +52,15 @@ export const TotpProvider = (): TDynamicProviderFns => { return { entityId, data: { TOTP: authenticatorInstance.generate(secret) } }; }; - const revoke = async (inputs: unknown, entityId: string) => { + const revoke = async (_inputs: unknown, entityId: string) => { return { entityId }; }; - const renew = async (inputs: unknown, entityId: string) => { - return { entityId }; + // eslint-disable-next-line @typescript-eslint/no-unused-vars + const renew = async (_inputs: unknown, _entityId: string) => { + throw new BadRequestError({ + message: "Lease renewal is not supported for TOTPs" + }); }; return { diff --git a/frontend/src/views/SecretMainPage/components/ActionBar/CreateDynamicSecretForm/TotpInputForm.tsx b/frontend/src/views/SecretMainPage/components/ActionBar/CreateDynamicSecretForm/TotpInputForm.tsx index 22da00842..fc3d841a0 100644 --- a/frontend/src/views/SecretMainPage/components/ActionBar/CreateDynamicSecretForm/TotpInputForm.tsx +++ b/frontend/src/views/SecretMainPage/components/ActionBar/CreateDynamicSecretForm/TotpInputForm.tsx @@ -3,10 +3,8 @@ import Link from "next/link"; import { faArrowUpRightFromSquare, faBookOpen } from "@fortawesome/free-solid-svg-icons"; import { FontAwesomeIcon } from "@fortawesome/react-fontawesome"; import { zodResolver } from "@hookform/resolvers/zod"; -import ms from "ms"; import { z } from "zod"; -import { TtlFormLabel } from "@app/components/features"; import { createNotification } from "@app/components/notifications"; import { Button, FormControl, Input } from "@app/components/v2"; import { useCreateDynamicSecret } from "@app/hooks/api"; @@ -16,26 +14,6 @@ const formSchema = z.object({ provider: z.object({ url: z.string().url().trim().min(1) }), - defaultTTL: z.string().superRefine((val, ctx) => { - const valMs = ms(val); - if (valMs < 60 * 1000) - ctx.addIssue({ code: z.ZodIssueCode.custom, message: "TTL must be a greater than 1min" }); - // a day - if (valMs > 24 * 60 * 60 * 1000) - ctx.addIssue({ code: z.ZodIssueCode.custom, message: "TTL must be less than a day" }); - }), - maxTTL: z - .string() - .optional() - .superRefine((val, ctx) => { - if (!val) return; - const valMs = ms(val); - if (valMs < 60 * 1000) - ctx.addIssue({ code: z.ZodIssueCode.custom, message: "TTL must be a greater than 1min" }); - // a day - if (valMs > 24 * 60 * 60 * 1000) - ctx.addIssue({ code: z.ZodIssueCode.custom, message: "TTL must be less than a day" }); - }), name: z .string() .trim() @@ -69,16 +47,16 @@ export const TotpInputForm = ({ const createDynamicSecret = useCreateDynamicSecret(); - const handleCreateDynamicSecret = async ({ name, maxTTL, provider, defaultTTL }: TForm) => { + const handleCreateDynamicSecret = async ({ name, provider }: TForm) => { // wait till previous request is finished if (createDynamicSecret.isLoading) return; try { await createDynamicSecret.mutateAsync({ provider: { type: DynamicSecretProviders.Totp, inputs: provider }, - maxTTL, + maxTTL: "24h", name, path: secretPath, - defaultTTL, + defaultTTL: "1m", projectSlug, environmentSlug: environment }); @@ -112,38 +90,6 @@ export const TotpInputForm = ({ )} /> -
- ( - } - isError={Boolean(error?.message)} - errorText={error?.message} - > - - - )} - /> -
-
- ( - } - isError={Boolean(error?.message)} - errorText={error?.message} - > - - - )} - /> -
diff --git a/frontend/src/views/SecretMainPage/components/DynamicSecretListView/CreateDynamicSecretLease.tsx b/frontend/src/views/SecretMainPage/components/DynamicSecretListView/CreateDynamicSecretLease.tsx index 4f024eb7c..69064d03a 100644 --- a/frontend/src/views/SecretMainPage/components/DynamicSecretListView/CreateDynamicSecretLease.tsx +++ b/frontend/src/views/SecretMainPage/components/DynamicSecretListView/CreateDynamicSecretLease.tsx @@ -9,7 +9,15 @@ import { z } from "zod"; import { TtlFormLabel } from "@app/components/features"; import { createNotification } from "@app/components/notifications"; -import { Button, FormControl, IconButton, Input, SecretInput, Tooltip } from "@app/components/v2"; +import { + Button, + ContentLoader, + FormControl, + IconButton, + Input, + SecretInput, + Tooltip +} from "@app/components/v2"; import { useTimedReset, useToggle } from "@app/hooks"; import { useCreateDynamicSecretLease } from "@app/hooks/api"; import { DynamicSecretProviders } from "@app/hooks/api/dynamicSecret/types"; @@ -335,7 +343,7 @@ export const CreateDynamicSecretLease = ({ const isOutputMode = Boolean(createDynamicSecretLease?.data); if (isPreloading) { - return
; + return ; } return ( diff --git a/frontend/src/views/SecretMainPage/components/DynamicSecretListView/EditDynamicSecretForm/EditDynamicSecretTotpForm.tsx b/frontend/src/views/SecretMainPage/components/DynamicSecretListView/EditDynamicSecretForm/EditDynamicSecretTotpForm.tsx index ec31767c4..054f66c3b 100644 --- a/frontend/src/views/SecretMainPage/components/DynamicSecretListView/EditDynamicSecretForm/EditDynamicSecretTotpForm.tsx +++ b/frontend/src/views/SecretMainPage/components/DynamicSecretListView/EditDynamicSecretForm/EditDynamicSecretTotpForm.tsx @@ -3,10 +3,8 @@ import Link from "next/link"; import { faArrowUpRightFromSquare, faBookOpen } from "@fortawesome/free-solid-svg-icons"; import { FontAwesomeIcon } from "@fortawesome/react-fontawesome"; import { zodResolver } from "@hookform/resolvers/zod"; -import ms from "ms"; import { z } from "zod"; -import { TtlFormLabel } from "@app/components/features"; import { createNotification } from "@app/components/notifications"; import { Button, FormControl, Input } from "@app/components/v2"; import { useUpdateDynamicSecret } from "@app/hooks/api"; @@ -18,26 +16,6 @@ const formSchema = z.object({ url: z.string().url().trim().min(1) }) .partial(), - defaultTTL: z.string().superRefine((val, ctx) => { - const valMs = ms(val); - if (valMs < 60 * 1000) - ctx.addIssue({ code: z.ZodIssueCode.custom, message: "TTL must be a greater than 1min" }); - // a day - if (valMs > 24 * 60 * 60 * 1000) - ctx.addIssue({ code: z.ZodIssueCode.custom, message: "TTL must be less than a day" }); - }), - maxTTL: z - .string() - .optional() - .superRefine((val, ctx) => { - if (!val) return; - const valMs = ms(val); - if (valMs < 60 * 1000) - ctx.addIssue({ code: z.ZodIssueCode.custom, message: "TTL must be a greater than 1min" }); - // a day - if (valMs > 24 * 60 * 60 * 1000) - ctx.addIssue({ code: z.ZodIssueCode.custom, message: "TTL must be less than a day" }); - }), newName: z .string() .trim() @@ -68,8 +46,6 @@ export const EditDynamicSecretTotpForm = ({ } = useForm({ resolver: zodResolver(formSchema), values: { - defaultTTL: dynamicSecret.defaultTTL, - maxTTL: dynamicSecret.maxTTL, newName: dynamicSecret.name, inputs: { ...(dynamicSecret.inputs as TForm["inputs"]) @@ -79,7 +55,7 @@ export const EditDynamicSecretTotpForm = ({ const updateDynamicSecret = useUpdateDynamicSecret(); - const handleUpdateDynamicSecret = async ({ inputs, maxTTL, defaultTTL, newName }: TForm) => { + const handleUpdateDynamicSecret = async ({ inputs, newName }: TForm) => { // wait till previous request is finished if (updateDynamicSecret.isLoading) return; try { @@ -89,8 +65,6 @@ export const EditDynamicSecretTotpForm = ({ projectSlug, environmentSlug: environment, data: { - maxTTL: maxTTL || undefined, - defaultTTL, inputs, newName: newName === dynamicSecret.name ? undefined : newName } @@ -129,38 +103,6 @@ export const EditDynamicSecretTotpForm = ({ )} />
-
- ( - } - isError={Boolean(error?.message)} - errorText={error?.message} - > - - - )} - /> -
-
- ( - } - isError={Boolean(error?.message)} - errorText={error?.message} - > - - - )} - /> -