Skip to content

Infisical is the open-source platform for securing secrets, certificates, access, and AI Agents.

pass connectionID to check duplicate endpoint

Matheus Nogueira00f9e3302124
diff --git a/backend/src/server/routes/v1/secret-sync-routers/secret-sync-endpoints.ts b/backend/src/server/routes/v1/secret-sync-routers/secret-sync-endpoints.ts
index 801bb7068a..f2661d3f62 100644
--- a/backend/src/server/routes/v1/secret-sync-routers/secret-sync-endpoints.ts
+++ b/backend/src/server/routes/v1/secret-sync-routers/secret-sync-endpoints.ts
@@ -492,6 +492,7 @@ export const registerSyncSecretsEndpoints = <T extends TSecretSync, I extends TS
tags: [ApiDocsTags.SecretSyncs],
body: z.object({
destinationConfig: z.unknown(),
+ connectionId: z.string().uuid().optional(),
excludeSyncId: z.string().uuid().optional(),
projectId: z.string().uuid()
}),
@@ -504,12 +505,13 @@ export const registerSyncSecretsEndpoints = <T extends TSecretSync, I extends TS
},
onRequest: verifyAuth([AuthMode.JWT, AuthMode.IDENTITY_ACCESS_TOKEN]),
handler: async (req) => {
- const { destinationConfig, excludeSyncId, projectId } = req.body;
+ const { destinationConfig, connectionId, excludeSyncId, projectId } = req.body;
const result = await server.services.secretSync.checkDuplicateDestination(
{
destinationConfig: destinationConfig as Record<string, unknown>,
destination,
+ connectionId,
excludeSyncId,
projectId
},
diff --git a/frontend/src/components/secret-syncs/forms/CreateSecretSyncForm.tsx b/frontend/src/components/secret-syncs/forms/CreateSecretSyncForm.tsx
index 878bd62f20..16f9467ebe 100644
--- a/frontend/src/components/secret-syncs/forms/CreateSecretSyncForm.tsx
+++ b/frontend/src/components/secret-syncs/forms/CreateSecretSyncForm.tsx
@@ -214,6 +214,7 @@ export const CreateSecretSyncForm = ({
const { hasDuplicate } = useDuplicateDestinationCheck({
destination,
projectId: currentProject?.id || "",
+ connectionId: watch("connection")?.id,
enabled: true,
destinationConfig: watch("destinationConfig")
});
diff --git a/frontend/src/components/secret-syncs/forms/EditSecretSyncForm.tsx b/frontend/src/components/secret-syncs/forms/EditSecretSyncForm.tsx
index c5cafdfbb4..c7867c4ecf 100644
--- a/frontend/src/components/secret-syncs/forms/EditSecretSyncForm.tsx
+++ b/frontend/src/components/secret-syncs/forms/EditSecretSyncForm.tsx
@@ -155,6 +155,7 @@ export const EditSecretSyncForm = ({ secretSync, onComplete, onDirtyChange, onCa
destinationConfigToCheck,
secretSync.projectId,
secretSync.id,
+ formMethods.watch("connection")?.id,
{ enabled: checkDuplicateEnabled && Boolean(destinationConfigToCheck) }
);
diff --git a/frontend/src/components/secret-syncs/forms/SecretSyncReviewFields/SecretSyncReviewFields.tsx b/frontend/src/components/secret-syncs/forms/SecretSyncReviewFields/SecretSyncReviewFields.tsx
index d7c141fd76..d4d242478b 100644
--- a/frontend/src/components/secret-syncs/forms/SecretSyncReviewFields/SecretSyncReviewFields.tsx
+++ b/frontend/src/components/secret-syncs/forms/SecretSyncReviewFields/SecretSyncReviewFields.tsx
@@ -99,6 +99,7 @@ export const SecretSyncReviewFields = () => {
const { hasDuplicate, duplicateProjectId, isChecking } = useDuplicateDestinationCheck({
destination,
projectId: currentProject?.id || "",
+ connectionId: connection?.id,
enabled: true,
destinationConfig: watch("destinationConfig")
});
diff --git a/frontend/src/hooks/api/secretSyncs/queries.tsx b/frontend/src/hooks/api/secretSyncs/queries.tsx
index 00888cd2ef..1c176613b2 100644
--- a/frontend/src/hooks/api/secretSyncs/queries.tsx
+++ b/frontend/src/hooks/api/secretSyncs/queries.tsx
@@ -15,12 +15,18 @@ export const secretSyncKeys = {
list: (projectId: string) => [...secretSyncKeys.all, "list", projectId] as const,
byId: (destination: SecretSync, syncId: string) =>
[...secretSyncKeys.all, destination, "by-id", syncId] as const,
- duplicateCheck: (destination: SecretSync, destinationConfig: unknown, excludeSyncId?: string) =>
+ duplicateCheck: (
+ destination: SecretSync,
+ destinationConfig: unknown,
+ connectionId?: string,
+ excludeSyncId?: string
+ ) =>
[
...secretSyncKeys.all,
destination,
"duplicate-check",
destinationConfig,
+ connectionId,
excludeSyncId
] as const
};
@@ -102,6 +108,7 @@ export const useCheckDuplicateDestination = (
destinationConfig: unknown,
projectId: string,
excludeSyncId?: string,
+ connectionId?: string,
options?: Omit<
UseQueryOptions<
{ hasDuplicate: boolean; duplicateProjectId?: string },
@@ -113,13 +120,14 @@ export const useCheckDuplicateDestination = (
>
) => {
return useQuery({
- queryKey: secretSyncKeys.duplicateCheck(destination, destinationConfig, excludeSyncId),
+ queryKey: secretSyncKeys.duplicateCheck(destination, destinationConfig, connectionId, excludeSyncId),
queryFn: async () => {
const { data } = await apiRequest.post<{
hasDuplicate: boolean;
duplicateProjectId?: string;
}>(`/api/v1/secret-syncs/${destination}/check-destination`, {
destinationConfig,
+ connectionId,
excludeSyncId,
projectId
});
diff --git a/frontend/src/hooks/api/secretSyncs/useDuplicateDestinationCheck.ts b/frontend/src/hooks/api/secretSyncs/useDuplicateDestinationCheck.ts
index 97985fba95..9cd1332d7d 100644
--- a/frontend/src/hooks/api/secretSyncs/useDuplicateDestinationCheck.ts
+++ b/frontend/src/hooks/api/secretSyncs/useDuplicateDestinationCheck.ts
@@ -6,6 +6,7 @@ type UseDuplicateDestinationCheckProps = {
destination: SecretSync;
projectId: string;
excludeSyncId?: string;
+ connectionId?: string;
enabled?: boolean;
destinationConfig?: unknown;
};
@@ -14,6 +15,7 @@ export const useDuplicateDestinationCheck = ({
destination,
projectId,
excludeSyncId,
+ connectionId,
enabled = true,
destinationConfig
}: UseDuplicateDestinationCheckProps) => {
@@ -34,7 +36,7 @@ export const useDuplicateDestinationCheck = ({
isLoading,
error,
refetch
- } = useCheckDuplicateDestination(destination, destinationConfig, projectId, excludeSyncId, {
+ } = useCheckDuplicateDestination(destination, destinationConfig, projectId, excludeSyncId, connectionId, {
enabled: shouldCheck,
staleTime: 0,
gcTime: 0