mirror of
https://github.com/awatertrevi/infisical.git
synced 2026-10-03 02:25:48 +00:00
misc: addressed comments
This commit is contained in:
@@ -52,12 +52,15 @@ export const TotpProvider = (): TDynamicProviderFns => {
|
|||||||
return { entityId, data: { TOTP: authenticatorInstance.generate(secret) } };
|
return { entityId, data: { TOTP: authenticatorInstance.generate(secret) } };
|
||||||
};
|
};
|
||||||
|
|
||||||
const revoke = async (inputs: unknown, entityId: string) => {
|
const revoke = async (_inputs: unknown, entityId: string) => {
|
||||||
return { entityId };
|
return { entityId };
|
||||||
};
|
};
|
||||||
|
|
||||||
const renew = async (inputs: unknown, entityId: string) => {
|
// eslint-disable-next-line @typescript-eslint/no-unused-vars
|
||||||
return { entityId };
|
const renew = async (_inputs: unknown, _entityId: string) => {
|
||||||
|
throw new BadRequestError({
|
||||||
|
message: "Lease renewal is not supported for TOTPs"
|
||||||
|
});
|
||||||
};
|
};
|
||||||
|
|
||||||
return {
|
return {
|
||||||
|
|||||||
+3
-57
@@ -3,10 +3,8 @@ import Link from "next/link";
|
|||||||
import { faArrowUpRightFromSquare, faBookOpen } from "@fortawesome/free-solid-svg-icons";
|
import { faArrowUpRightFromSquare, faBookOpen } from "@fortawesome/free-solid-svg-icons";
|
||||||
import { FontAwesomeIcon } from "@fortawesome/react-fontawesome";
|
import { FontAwesomeIcon } from "@fortawesome/react-fontawesome";
|
||||||
import { zodResolver } from "@hookform/resolvers/zod";
|
import { zodResolver } from "@hookform/resolvers/zod";
|
||||||
import ms from "ms";
|
|
||||||
import { z } from "zod";
|
import { z } from "zod";
|
||||||
|
|
||||||
import { TtlFormLabel } from "@app/components/features";
|
|
||||||
import { createNotification } from "@app/components/notifications";
|
import { createNotification } from "@app/components/notifications";
|
||||||
import { Button, FormControl, Input } from "@app/components/v2";
|
import { Button, FormControl, Input } from "@app/components/v2";
|
||||||
import { useCreateDynamicSecret } from "@app/hooks/api";
|
import { useCreateDynamicSecret } from "@app/hooks/api";
|
||||||
@@ -16,26 +14,6 @@ const formSchema = z.object({
|
|||||||
provider: z.object({
|
provider: z.object({
|
||||||
url: z.string().url().trim().min(1)
|
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
|
name: z
|
||||||
.string()
|
.string()
|
||||||
.trim()
|
.trim()
|
||||||
@@ -69,16 +47,16 @@ export const TotpInputForm = ({
|
|||||||
|
|
||||||
const createDynamicSecret = useCreateDynamicSecret();
|
const createDynamicSecret = useCreateDynamicSecret();
|
||||||
|
|
||||||
const handleCreateDynamicSecret = async ({ name, maxTTL, provider, defaultTTL }: TForm) => {
|
const handleCreateDynamicSecret = async ({ name, provider }: TForm) => {
|
||||||
// wait till previous request is finished
|
// wait till previous request is finished
|
||||||
if (createDynamicSecret.isLoading) return;
|
if (createDynamicSecret.isLoading) return;
|
||||||
try {
|
try {
|
||||||
await createDynamicSecret.mutateAsync({
|
await createDynamicSecret.mutateAsync({
|
||||||
provider: { type: DynamicSecretProviders.Totp, inputs: provider },
|
provider: { type: DynamicSecretProviders.Totp, inputs: provider },
|
||||||
maxTTL,
|
maxTTL: "24h",
|
||||||
name,
|
name,
|
||||||
path: secretPath,
|
path: secretPath,
|
||||||
defaultTTL,
|
defaultTTL: "1m",
|
||||||
projectSlug,
|
projectSlug,
|
||||||
environmentSlug: environment
|
environmentSlug: environment
|
||||||
});
|
});
|
||||||
@@ -112,38 +90,6 @@ export const TotpInputForm = ({
|
|||||||
)}
|
)}
|
||||||
/>
|
/>
|
||||||
</div>
|
</div>
|
||||||
<div className="w-32">
|
|
||||||
<Controller
|
|
||||||
control={control}
|
|
||||||
name="defaultTTL"
|
|
||||||
defaultValue="1m"
|
|
||||||
render={({ field, fieldState: { error } }) => (
|
|
||||||
<FormControl
|
|
||||||
label={<TtlFormLabel label="Default TTL" />}
|
|
||||||
isError={Boolean(error?.message)}
|
|
||||||
errorText={error?.message}
|
|
||||||
>
|
|
||||||
<Input {...field} />
|
|
||||||
</FormControl>
|
|
||||||
)}
|
|
||||||
/>
|
|
||||||
</div>
|
|
||||||
<div className="w-32">
|
|
||||||
<Controller
|
|
||||||
control={control}
|
|
||||||
name="maxTTL"
|
|
||||||
defaultValue="24h"
|
|
||||||
render={({ field, fieldState: { error } }) => (
|
|
||||||
<FormControl
|
|
||||||
label={<TtlFormLabel label="Max TTL" />}
|
|
||||||
isError={Boolean(error?.message)}
|
|
||||||
errorText={error?.message}
|
|
||||||
>
|
|
||||||
<Input {...field} />
|
|
||||||
</FormControl>
|
|
||||||
)}
|
|
||||||
/>
|
|
||||||
</div>
|
|
||||||
</div>
|
</div>
|
||||||
<div>
|
<div>
|
||||||
<div className="mb-4 mt-4 border-b border-mineshaft-500 pb-2 pl-1 font-medium text-mineshaft-200">
|
<div className="mb-4 mt-4 border-b border-mineshaft-500 pb-2 pl-1 font-medium text-mineshaft-200">
|
||||||
|
|||||||
+10
-2
@@ -9,7 +9,15 @@ import { z } from "zod";
|
|||||||
|
|
||||||
import { TtlFormLabel } from "@app/components/features";
|
import { TtlFormLabel } from "@app/components/features";
|
||||||
import { createNotification } from "@app/components/notifications";
|
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 { useTimedReset, useToggle } from "@app/hooks";
|
||||||
import { useCreateDynamicSecretLease } from "@app/hooks/api";
|
import { useCreateDynamicSecretLease } from "@app/hooks/api";
|
||||||
import { DynamicSecretProviders } from "@app/hooks/api/dynamicSecret/types";
|
import { DynamicSecretProviders } from "@app/hooks/api/dynamicSecret/types";
|
||||||
@@ -335,7 +343,7 @@ export const CreateDynamicSecretLease = ({
|
|||||||
const isOutputMode = Boolean(createDynamicSecretLease?.data);
|
const isOutputMode = Boolean(createDynamicSecretLease?.data);
|
||||||
|
|
||||||
if (isPreloading) {
|
if (isPreloading) {
|
||||||
return <div />;
|
return <ContentLoader className="h-40" />;
|
||||||
}
|
}
|
||||||
|
|
||||||
return (
|
return (
|
||||||
|
|||||||
+1
-59
@@ -3,10 +3,8 @@ import Link from "next/link";
|
|||||||
import { faArrowUpRightFromSquare, faBookOpen } from "@fortawesome/free-solid-svg-icons";
|
import { faArrowUpRightFromSquare, faBookOpen } from "@fortawesome/free-solid-svg-icons";
|
||||||
import { FontAwesomeIcon } from "@fortawesome/react-fontawesome";
|
import { FontAwesomeIcon } from "@fortawesome/react-fontawesome";
|
||||||
import { zodResolver } from "@hookform/resolvers/zod";
|
import { zodResolver } from "@hookform/resolvers/zod";
|
||||||
import ms from "ms";
|
|
||||||
import { z } from "zod";
|
import { z } from "zod";
|
||||||
|
|
||||||
import { TtlFormLabel } from "@app/components/features";
|
|
||||||
import { createNotification } from "@app/components/notifications";
|
import { createNotification } from "@app/components/notifications";
|
||||||
import { Button, FormControl, Input } from "@app/components/v2";
|
import { Button, FormControl, Input } from "@app/components/v2";
|
||||||
import { useUpdateDynamicSecret } from "@app/hooks/api";
|
import { useUpdateDynamicSecret } from "@app/hooks/api";
|
||||||
@@ -18,26 +16,6 @@ const formSchema = z.object({
|
|||||||
url: z.string().url().trim().min(1)
|
url: z.string().url().trim().min(1)
|
||||||
})
|
})
|
||||||
.partial(),
|
.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
|
newName: z
|
||||||
.string()
|
.string()
|
||||||
.trim()
|
.trim()
|
||||||
@@ -68,8 +46,6 @@ export const EditDynamicSecretTotpForm = ({
|
|||||||
} = useForm<TForm>({
|
} = useForm<TForm>({
|
||||||
resolver: zodResolver(formSchema),
|
resolver: zodResolver(formSchema),
|
||||||
values: {
|
values: {
|
||||||
defaultTTL: dynamicSecret.defaultTTL,
|
|
||||||
maxTTL: dynamicSecret.maxTTL,
|
|
||||||
newName: dynamicSecret.name,
|
newName: dynamicSecret.name,
|
||||||
inputs: {
|
inputs: {
|
||||||
...(dynamicSecret.inputs as TForm["inputs"])
|
...(dynamicSecret.inputs as TForm["inputs"])
|
||||||
@@ -79,7 +55,7 @@ export const EditDynamicSecretTotpForm = ({
|
|||||||
|
|
||||||
const updateDynamicSecret = useUpdateDynamicSecret();
|
const updateDynamicSecret = useUpdateDynamicSecret();
|
||||||
|
|
||||||
const handleUpdateDynamicSecret = async ({ inputs, maxTTL, defaultTTL, newName }: TForm) => {
|
const handleUpdateDynamicSecret = async ({ inputs, newName }: TForm) => {
|
||||||
// wait till previous request is finished
|
// wait till previous request is finished
|
||||||
if (updateDynamicSecret.isLoading) return;
|
if (updateDynamicSecret.isLoading) return;
|
||||||
try {
|
try {
|
||||||
@@ -89,8 +65,6 @@ export const EditDynamicSecretTotpForm = ({
|
|||||||
projectSlug,
|
projectSlug,
|
||||||
environmentSlug: environment,
|
environmentSlug: environment,
|
||||||
data: {
|
data: {
|
||||||
maxTTL: maxTTL || undefined,
|
|
||||||
defaultTTL,
|
|
||||||
inputs,
|
inputs,
|
||||||
newName: newName === dynamicSecret.name ? undefined : newName
|
newName: newName === dynamicSecret.name ? undefined : newName
|
||||||
}
|
}
|
||||||
@@ -129,38 +103,6 @@ export const EditDynamicSecretTotpForm = ({
|
|||||||
)}
|
)}
|
||||||
/>
|
/>
|
||||||
</div>
|
</div>
|
||||||
<div className="w-32">
|
|
||||||
<Controller
|
|
||||||
control={control}
|
|
||||||
name="defaultTTL"
|
|
||||||
defaultValue="1m"
|
|
||||||
render={({ field, fieldState: { error } }) => (
|
|
||||||
<FormControl
|
|
||||||
label={<TtlFormLabel label="Default TTL" />}
|
|
||||||
isError={Boolean(error?.message)}
|
|
||||||
errorText={error?.message}
|
|
||||||
>
|
|
||||||
<Input {...field} />
|
|
||||||
</FormControl>
|
|
||||||
)}
|
|
||||||
/>
|
|
||||||
</div>
|
|
||||||
<div className="w-32">
|
|
||||||
<Controller
|
|
||||||
control={control}
|
|
||||||
name="maxTTL"
|
|
||||||
defaultValue="24h"
|
|
||||||
render={({ field, fieldState: { error } }) => (
|
|
||||||
<FormControl
|
|
||||||
label={<TtlFormLabel label="Max TTL" />}
|
|
||||||
isError={Boolean(error?.message)}
|
|
||||||
errorText={error?.message}
|
|
||||||
>
|
|
||||||
<Input {...field} />
|
|
||||||
</FormControl>
|
|
||||||
)}
|
|
||||||
/>
|
|
||||||
</div>
|
|
||||||
</div>
|
</div>
|
||||||
<div>
|
<div>
|
||||||
<div className="mb-4 mt-4 border-b border-mineshaft-500 pb-2 pl-1 font-medium text-mineshaft-200">
|
<div className="mb-4 mt-4 border-b border-mineshaft-500 pb-2 pl-1 font-medium text-mineshaft-200">
|
||||||
|
|||||||
Reference in New Issue
Block a user