Skip to content

Commit 8ccdb66

Browse files
committed
feat(destinations): enhance validation for additionalFlags in destination settings
- Introduced regex validation for the `additionalFlags` field to ensure proper flag formatting. - Updated error handling in the API router to provide clearer feedback on validation issues. - Refactored the database schema to align with the new validation rules for additionalFlags. - Added a new validation module for destination-related checks.
1 parent e38f07d commit 8ccdb66

5 files changed

Lines changed: 36 additions & 4 deletions

File tree

apps/dokploy/components/dashboard/settings/destination/handle-destinations.tsx

Lines changed: 17 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -35,6 +35,10 @@ import {
3535
} from "@/components/ui/select";
3636
import { cn } from "@/lib/utils";
3737
import { api } from "@/utils/api";
38+
import {
39+
ADDITIONAL_FLAG_ERROR,
40+
ADDITIONAL_FLAG_REGEX,
41+
} from "@dokploy/server/db/validations/destination";
3842
import { S3_PROVIDERS } from "./constants";
3943

4044
const addDestination = z.object({
@@ -47,7 +51,14 @@ const addDestination = z.object({
4751
endpoint: z.string().min(1, "Endpoint is required"),
4852
serverId: z.string().optional(),
4953
additionalFlags: z
50-
.array(z.object({ value: z.string().min(1, "Flag cannot be empty") }))
54+
.array(
55+
z.object({
56+
value: z
57+
.string()
58+
.min(1, "Flag cannot be empty")
59+
.regex(ADDITIONAL_FLAG_REGEX, ADDITIONAL_FLAG_ERROR),
60+
}),
61+
)
5162
.optional(),
5263
});
5364

@@ -140,9 +151,12 @@ export const HandleDestinations = ({ destinationId }: Props) => {
140151
}
141152
setOpen(false);
142153
})
143-
.catch(() => {
154+
.catch((e) => {
144155
toast.error(
145156
`Error ${destinationId ? "Updating" : "Creating"} the Destination`,
157+
{
158+
description: e.message,
159+
},
146160
);
147161
});
148162
};
@@ -154,6 +168,7 @@ export const HandleDestinations = ({ destinationId }: Props) => {
154168
"secretAccessKey",
155169
"bucket",
156170
"endpoint",
171+
"additionalFlags",
157172
]);
158173

159174
if (!result) {

apps/dokploy/server/api/routers/destination.ts

Lines changed: 8 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -169,7 +169,14 @@ export const destinationRouter = createTRPCRouter({
169169
});
170170
return result;
171171
} catch (error) {
172-
throw error;
172+
throw new TRPCError({
173+
code: "BAD_REQUEST",
174+
message:
175+
error instanceof Error
176+
? error?.message
177+
: "Error connecting to bucket",
178+
cause: error,
179+
});
173180
}
174181
}),
175182
});

packages/server/src/db/schema/destination.ts

Lines changed: 7 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -3,6 +3,10 @@ import { pgTable, text, timestamp } from "drizzle-orm/pg-core";
33
import { createInsertSchema } from "drizzle-zod";
44
import { nanoid } from "nanoid";
55
import { z } from "zod";
6+
import {
7+
ADDITIONAL_FLAG_ERROR,
8+
ADDITIONAL_FLAG_REGEX,
9+
} from "../validations/destination";
610
import { organization } from "./account";
711
import { backups } from "./backups";
812

@@ -45,7 +49,9 @@ const createSchema = createInsertSchema(destinations, {
4549
endpoint: z.string(),
4650
secretAccessKey: z.string(),
4751
region: z.string(),
48-
additionalFlags: z.array(z.string()).default([]),
52+
additionalFlags: z
53+
.array(z.string().regex(ADDITIONAL_FLAG_REGEX, ADDITIONAL_FLAG_ERROR))
54+
.default([]),
4955
});
5056

5157
export const apiCreateDestination = createSchema
Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,3 @@
1+
export const ADDITIONAL_FLAG_REGEX = /^--[a-zA-Z0-9-]+(=[a-zA-Z0-9._:/@-]+)?$/;
2+
export const ADDITIONAL_FLAG_ERROR =
3+
"Invalid flag format. Must start with -- (e.g. --s3-sign-accept-encoding=false)";

packages/server/src/index.ts

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,7 @@
11
export * from "./auth/random-password";
22
export * from "./constants/index";
33
export * from "./db/constants";
4+
export * from "./db/validations/destination";
45
export * from "./db/validations/domain";
56
export * from "./db/validations/index";
67
export * from "./lib/auth";

0 commit comments

Comments
 (0)