mirror of
https://github.com/Infisical/infisical.git
synced 2026-01-09 15:38:03 -05:00
feat(approval-policies): ensure proper path syntax
This commit is contained in:
@@ -22,6 +22,12 @@ export const PamAccessPolicyConditionsSchema = z
|
||||
.object({
|
||||
accountPaths: z
|
||||
.string()
|
||||
.refine((el) => el.startsWith("/"), {
|
||||
message: "Path must start with /"
|
||||
})
|
||||
.refine((el) => !el.endsWith("/"), {
|
||||
message: "Path cannot end with /"
|
||||
})
|
||||
.refine(
|
||||
(el) => {
|
||||
try {
|
||||
@@ -57,7 +63,14 @@ export const PamAccessPolicyConstraintsSchema = z.object({
|
||||
|
||||
// Request Data
|
||||
export const PamAccessPolicyRequestDataSchema = z.object({
|
||||
accountPath: z.string(),
|
||||
accountPath: z
|
||||
.string()
|
||||
.refine((el) => el.startsWith("/"), {
|
||||
message: "Path must start with /"
|
||||
})
|
||||
.refine((el) => !el.endsWith("/"), {
|
||||
message: "Path cannot end with /"
|
||||
}),
|
||||
accessDuration: DurationSchema
|
||||
});
|
||||
|
||||
|
||||
@@ -35,6 +35,12 @@ export const PolicyFormSchema = z.object({
|
||||
.refine((val) => val.every((path) => path.length > 0), {
|
||||
message: "All account paths must be non-empty"
|
||||
})
|
||||
.refine((val) => val.every((path) => path.startsWith("/")), {
|
||||
message: "All account paths must start with /"
|
||||
})
|
||||
.refine((val) => val.every((path) => !path.endsWith("/")), {
|
||||
message: "All account paths cannot end with /"
|
||||
})
|
||||
})
|
||||
.array()
|
||||
.min(1, "At least one condition is required"),
|
||||
|
||||
@@ -15,10 +15,10 @@ import {
|
||||
ModalContent,
|
||||
TextArea
|
||||
} from "@app/components/v2";
|
||||
import { UnstableAlert, UnstableAlertDescription, UnstableAlertTitle } from "@app/components/v3";
|
||||
import { useProject } from "@app/context";
|
||||
import { ApprovalPolicyType } from "@app/hooks/api/approvalPolicies";
|
||||
import { useCreateApprovalRequest } from "@app/hooks/api/approvalRequests/mutations";
|
||||
import { UnstableAlert, UnstableAlertDescription, UnstableAlertTitle } from "@app/components/v3";
|
||||
|
||||
type Props = {
|
||||
accountPath?: string;
|
||||
@@ -28,7 +28,15 @@ type Props = {
|
||||
};
|
||||
|
||||
const formSchema = z.object({
|
||||
accountPath: z.string().min(1, "Account path is required"),
|
||||
accountPath: z
|
||||
.string()
|
||||
.min(1, "Account path is required")
|
||||
.refine((el) => el.startsWith("/"), {
|
||||
message: "Path must start with /"
|
||||
})
|
||||
.refine((el) => !el.endsWith("/"), {
|
||||
message: "Path cannot end with /"
|
||||
}),
|
||||
accessDuration: z
|
||||
.string()
|
||||
.min(1, "Access duration is required")
|
||||
@@ -55,6 +63,7 @@ const Content = ({ onOpenChange, accountPath, accountAccessed }: Props) => {
|
||||
|
||||
const form = useForm<FormData>({
|
||||
resolver: zodResolver(formSchema),
|
||||
mode: "onChange",
|
||||
defaultValues: {
|
||||
accountPath,
|
||||
accessDuration: "4h",
|
||||
|
||||
Reference in New Issue
Block a user