review fixes

This commit is contained in:
x032205
2025-05-06 16:26:51 -04:00
parent 45c84d4936
commit bd7c4fc4eb
16 changed files with 147 additions and 153 deletions
@@ -10,34 +10,33 @@ import { useCreateDynamicSecret } from "@app/hooks/api";
import { DynamicSecretProviders } from "@app/hooks/api/dynamicSecret/types";
import { WorkspaceEnv } from "@app/hooks/api/types";
const formSchema = z.object({
provider: z.object({
serviceAccountEmail: z.string().email().trim().min(1, "Service account email required")
}),
defaultTTL: z.string().superRefine((val, ctx) => {
const valMs = ms(val);
if (valMs < 1000)
ctx.addIssue({ code: z.ZodIssueCode.custom, message: "TTL must be a greater than 1 second" });
if (valMs > 60 * 60 * 1000)
ctx.addIssue({ code: z.ZodIssueCode.custom, message: "TTL must be less than 1 hour" });
}),
maxTTL: z
.string()
.optional()
.superRefine((val, ctx) => {
if (!val) return;
const valMs = ms(val);
if (valMs < 1000)
ctx.addIssue({
code: z.ZodIssueCode.custom,
message: "TTL must be a greater than 1 second"
});
if (valMs > 60 * 60 * 1000)
ctx.addIssue({ code: z.ZodIssueCode.custom, message: "TTL must be less than 1 hour" });
const validateTTL = (val: string, ctx: z.RefinementCtx) => {
if (!val) return;
const valMs = ms(val);
if (valMs === undefined) {
ctx.addIssue({ code: z.ZodIssueCode.custom, message: "Invalid TTL format" });
return;
}
if (valMs < 1000)
ctx.addIssue({ code: z.ZodIssueCode.custom, message: "TTL must be a greater than 1 second" });
if (valMs > 60 * 60 * 1000)
ctx.addIssue({ code: z.ZodIssueCode.custom, message: "TTL must be less than 1 hour" });
};
const formSchema = z
.object({
provider: z.object({
serviceAccountEmail: z.string().email().trim().min(1, "Service account email required")
}),
name: z.string().refine((val) => val.toLowerCase() === val, "Must be lowercase"),
environment: z.object({ name: z.string(), slug: z.string() })
});
defaultTTL: z.string().superRefine(validateTTL),
maxTTL: z.string().optional().superRefine(validateTTL),
name: z.string().refine((val) => val.toLowerCase() === val, "Must be lowercase"),
environment: z.object({ name: z.string(), slug: z.string() })
})
.refine((d) => !d.maxTTL || ms(d.maxTTL)! >= ms(d.defaultTTL)!, {
path: ["maxTTL"],
message: "Max TTL must be greater than or equal to Default TTL"
});
type TForm = z.infer<typeof formSchema>;
type Props = {
@@ -64,7 +63,7 @@ export const GcpIamInputForm = ({
} = useForm<TForm>({
resolver: zodResolver(formSchema),
defaultValues: {
environment: isSingleEnvironmentMode ? environments[0] : undefined
environment: isSingleEnvironmentMode && environments.length > 0 ? environments[0] : undefined
}
});
@@ -77,8 +76,6 @@ export const GcpIamInputForm = ({
defaultTTL,
environment
}: TForm) => {
console.log("handleCreateDynamicSecret called");
// wait till previous request is finished
if (createDynamicSecret.isPending) return;
try {
@@ -9,33 +9,37 @@ import { Button, FormControl, Input } from "@app/components/v2";
import { useUpdateDynamicSecret } from "@app/hooks/api";
import { TDynamicSecret } from "@app/hooks/api/dynamicSecret/types";
const formSchema = z.object({
inputs: z.object({
serviceAccountEmail: z.string().email().trim().min(1, "Service account email required")
}),
defaultTTL: z.string().superRefine((val, ctx) => {
const valMs = ms(val);
if (valMs < 1000)
ctx.addIssue({ code: z.ZodIssueCode.custom, message: "TTL must be a greater than 1 second" });
if (valMs > 60 * 60 * 1000)
ctx.addIssue({ code: z.ZodIssueCode.custom, message: "TTL must be less than 1 hour" });
}),
maxTTL: z
.string()
.optional()
.superRefine((val, ctx) => {
if (!val) return;
const valMs = ms(val);
if (valMs < 1000)
ctx.addIssue({
code: z.ZodIssueCode.custom,
message: "TTL must be a greater than 1 second"
});
if (valMs > 60 * 60 * 1000)
ctx.addIssue({ code: z.ZodIssueCode.custom, message: "TTL must be less than 1 hour" });
const validateTTL = (val: string, ctx: z.RefinementCtx) => {
if (!val) return;
const valMs = ms(val);
if (valMs === undefined) {
ctx.addIssue({ code: z.ZodIssueCode.custom, message: "Invalid TTL format" });
return;
}
if (valMs < 1000)
ctx.addIssue({ code: z.ZodIssueCode.custom, message: "TTL must be a greater than 1 second" });
if (valMs > 60 * 60 * 1000)
ctx.addIssue({ code: z.ZodIssueCode.custom, message: "TTL must be less than 1 hour" });
};
const formSchema = z
.object({
inputs: z.object({
serviceAccountEmail: z.string().email().trim().min(1, "Service account email required")
}),
newName: z.string().refine((val) => val.toLowerCase() === val, "Must be lowercase")
});
defaultTTL: z.string().superRefine(validateTTL),
maxTTL: z
.string()
.optional()
.superRefine((val, ctx) => {
if (val) validateTTL(val, ctx);
}),
newName: z.string().refine((val) => val.toLowerCase() === val, "Must be lowercase")
})
.refine((d) => !d.maxTTL || ms(d.maxTTL)! >= ms(d.defaultTTL)!, {
path: ["maxTTL"],
message: "Max TTL must be greater than or equal to Default TTL"
});
type TForm = z.infer<typeof formSchema>;
type Props = {
@@ -107,7 +111,6 @@ export const EditDynamicSecretGcpIamForm = ({
<div className="flex-grow">
<Controller
control={control}
defaultValue=""
name="newName"
render={({ field, fieldState: { error } }) => (
<FormControl
@@ -124,7 +127,6 @@ export const EditDynamicSecretGcpIamForm = ({
<Controller
control={control}
name="defaultTTL"
defaultValue="1h"
render={({ field, fieldState: { error } }) => (
<FormControl
label={<TtlFormLabel label="Default TTL" />}
@@ -140,7 +142,6 @@ export const EditDynamicSecretGcpIamForm = ({
<Controller
control={control}
name="maxTTL"
defaultValue="24h"
render={({ field, fieldState: { error } }) => (
<FormControl
label={<TtlFormLabel label="Max TTL" />}
@@ -161,7 +162,6 @@ export const EditDynamicSecretGcpIamForm = ({
<Controller
control={control}
name="inputs.serviceAccountEmail"
defaultValue=""
render={({ field, fieldState: { error } }) => (
<FormControl
label="Service Account Email"
@@ -21,9 +21,6 @@ type Props = {
projectSlug: string;
environment: string;
secretPath: string;
minTtl?: string; // Optional minimum TTL, defaults to 1min
maxTtl?: string; // Optional maximum TTL, defaults to 1day
defaultTtl?: string; // Optional default TTL, defaults to 1h
};
export const RenewDynamicSecretLease = ({
@@ -41,7 +38,7 @@ export const RenewDynamicSecretLease = ({
ttl: z.string().superRefine((val, ctx) => {
if (!val) return;
const valMs = ms(val);
if (valMs < 60)
if (valMs < 1000)
ctx.addIssue({
code: z.ZodIssueCode.custom,
message: "TTL must be greater than 1 second"