mirror of
https://github.com/awatertrevi/infisical.git
synced 2026-10-08 20:28:16 +00:00
Address PR comments
This commit is contained in:
@@ -84,3 +84,22 @@ export const deepEqual = (obj1: unknown, obj2: unknown): boolean => {
|
|||||||
deepEqual((obj1 as Record<string, unknown>)[key], (obj2 as Record<string, unknown>)[key])
|
deepEqual((obj1 as Record<string, unknown>)[key], (obj2 as Record<string, unknown>)[key])
|
||||||
);
|
);
|
||||||
};
|
};
|
||||||
|
|
||||||
|
export const deepEqualSkipFields = (obj1: unknown, obj2: unknown, skipFields: string[] = []): boolean => {
|
||||||
|
if (skipFields.length === 0) {
|
||||||
|
return deepEqual(obj1, obj2);
|
||||||
|
}
|
||||||
|
|
||||||
|
if (typeof obj1 !== "object" || typeof obj2 !== "object" || obj1 === null || obj2 === null) {
|
||||||
|
return deepEqual(obj1, obj2);
|
||||||
|
}
|
||||||
|
|
||||||
|
const filtered1 = Object.fromEntries(
|
||||||
|
Object.entries(obj1 as Record<string, unknown>).filter(([key]) => !skipFields.includes(key))
|
||||||
|
);
|
||||||
|
const filtered2 = Object.fromEntries(
|
||||||
|
Object.entries(obj2 as Record<string, unknown>).filter(([key]) => !skipFields.includes(key))
|
||||||
|
);
|
||||||
|
|
||||||
|
return deepEqual(filtered1, filtered2);
|
||||||
|
};
|
||||||
|
|||||||
@@ -449,7 +449,7 @@ export const registerSyncSecretsEndpoints = <T extends TSecretSync, I extends TS
|
|||||||
|
|
||||||
const result = await server.services.secretSync.checkDuplicateDestination(
|
const result = await server.services.secretSync.checkDuplicateDestination(
|
||||||
{
|
{
|
||||||
destinationConfig,
|
destinationConfig: destinationConfig as Record<string, unknown>,
|
||||||
destination,
|
destination,
|
||||||
excludeSyncId,
|
excludeSyncId,
|
||||||
projectId
|
projectId
|
||||||
|
|||||||
@@ -204,5 +204,19 @@ export const secretSyncDALFactory = (
|
|||||||
}
|
}
|
||||||
};
|
};
|
||||||
|
|
||||||
return { ...secretSyncOrm, findById, findOne, find, create, updateById };
|
const findByDestinationAndOrgId = async (destination: string, orgId: string, tx?: Knex) => {
|
||||||
|
try {
|
||||||
|
const response = await (tx || db.replicaNode())(TableName.SecretSync)
|
||||||
|
.join(TableName.Project, `${TableName.SecretSync}.projectId`, `${TableName.Project}.id`)
|
||||||
|
.where(`${TableName.SecretSync}.destination`, destination)
|
||||||
|
.where(`${TableName.Project}.orgId`, orgId)
|
||||||
|
.select(selectAllTableCols(TableName.SecretSync));
|
||||||
|
|
||||||
|
return response;
|
||||||
|
} catch (error) {
|
||||||
|
throw new DatabaseError({ error, name: "Find By Destination And Org ID - Secret Sync" });
|
||||||
|
}
|
||||||
|
};
|
||||||
|
|
||||||
|
return { ...secretSyncOrm, findById, findOne, find, create, updateById, findByDestinationAndOrgId };
|
||||||
};
|
};
|
||||||
|
|||||||
@@ -12,7 +12,7 @@ import {
|
|||||||
import { KeyStorePrefixes, TKeyStoreFactory } from "@app/keystore/keystore";
|
import { KeyStorePrefixes, TKeyStoreFactory } from "@app/keystore/keystore";
|
||||||
import { DatabaseErrorCode } from "@app/lib/error-codes";
|
import { DatabaseErrorCode } from "@app/lib/error-codes";
|
||||||
import { BadRequestError, DatabaseError, NotFoundError } from "@app/lib/errors";
|
import { BadRequestError, DatabaseError, NotFoundError } from "@app/lib/errors";
|
||||||
import { deepEqual } from "@app/lib/fn/object";
|
import { deepEqualSkipFields } from "@app/lib/fn/object";
|
||||||
import { OrgServiceActor } from "@app/lib/types";
|
import { OrgServiceActor } from "@app/lib/types";
|
||||||
import { TAppConnectionServiceFactory } from "@app/services/app-connection/app-connection-service";
|
import { TAppConnectionServiceFactory } from "@app/services/app-connection/app-connection-service";
|
||||||
import { TProjectBotServiceFactory } from "@app/services/project-bot/project-bot-service";
|
import { TProjectBotServiceFactory } from "@app/services/project-bot/project-bot-service";
|
||||||
@@ -698,10 +698,46 @@ export const secretSyncServiceFactory = ({
|
|||||||
return updatedSecretSync as TSecretSync;
|
return updatedSecretSync as TSecretSync;
|
||||||
};
|
};
|
||||||
|
|
||||||
|
const getSkipFieldsForDestination = (destination: SecretSync): string[] => {
|
||||||
|
switch (destination) {
|
||||||
|
case SecretSync.AWSSecretsManager:
|
||||||
|
return ["mappingBehavior", "secretName"];
|
||||||
|
case SecretSync.OnePass:
|
||||||
|
return ["valueLabel"];
|
||||||
|
case SecretSync.AzureAppConfiguration:
|
||||||
|
return ["label"];
|
||||||
|
case SecretSync.AzureDevOps:
|
||||||
|
return ["devopsProjectName"];
|
||||||
|
case SecretSync.Checkly:
|
||||||
|
return ["groupName", "accountName"];
|
||||||
|
case SecretSync.DigitalOceanAppPlatform:
|
||||||
|
return ["appName"];
|
||||||
|
case SecretSync.GitLab:
|
||||||
|
return ["projectName", "shouldProtectSecrets", "shouldMaskSecrets", "shouldHideSecrets"];
|
||||||
|
case SecretSync.Heroku:
|
||||||
|
return ["appName"];
|
||||||
|
case SecretSync.Netlify:
|
||||||
|
return ["accountName", "siteName"];
|
||||||
|
case SecretSync.Railway:
|
||||||
|
return ["projectName", "environmentName", "serviceName"];
|
||||||
|
case SecretSync.Supabase:
|
||||||
|
return ["projectName"];
|
||||||
|
case SecretSync.TerraformCloud:
|
||||||
|
return ["variableSetName", "workspaceName"];
|
||||||
|
case SecretSync.Vercel:
|
||||||
|
return ["appName"];
|
||||||
|
case SecretSync.Zabbix:
|
||||||
|
return ["hostName", "macroType"];
|
||||||
|
default:
|
||||||
|
return [];
|
||||||
|
}
|
||||||
|
};
|
||||||
|
|
||||||
const checkDuplicateDestination = async (
|
const checkDuplicateDestination = async (
|
||||||
{ destination, destinationConfig, excludeSyncId, projectId }: TCheckDuplicateDestinationDTO,
|
{ destination, destinationConfig, excludeSyncId, projectId }: TCheckDuplicateDestinationDTO,
|
||||||
actor: OrgServiceActor
|
actor: OrgServiceActor
|
||||||
) => {
|
) => {
|
||||||
|
const skipFields = getSkipFieldsForDestination(destination);
|
||||||
const { permission } = await permissionService.getProjectPermission({
|
const { permission } = await permissionService.getProjectPermission({
|
||||||
actor: actor.type,
|
actor: actor.type,
|
||||||
actorId: actor.id,
|
actorId: actor.id,
|
||||||
@@ -716,14 +752,12 @@ export const secretSyncServiceFactory = ({
|
|||||||
ProjectPermissionSub.SecretSyncs
|
ProjectPermissionSub.SecretSyncs
|
||||||
);
|
);
|
||||||
|
|
||||||
if (!destinationConfig || typeof destinationConfig !== "object") {
|
if (!destinationConfig || Object.keys(destinationConfig).length === 0) {
|
||||||
return { hasDuplicate: false };
|
return { hasDuplicate: false };
|
||||||
}
|
}
|
||||||
|
|
||||||
try {
|
try {
|
||||||
const existingSyncs = await secretSyncDAL.find({
|
const existingSyncs = await secretSyncDAL.findByDestinationAndOrgId(destination, actor.orgId);
|
||||||
destination
|
|
||||||
});
|
|
||||||
|
|
||||||
const duplicates = existingSyncs.filter((sync) => {
|
const duplicates = existingSyncs.filter((sync) => {
|
||||||
if (sync.id === excludeSyncId) {
|
if (sync.id === excludeSyncId) {
|
||||||
@@ -731,7 +765,7 @@ export const secretSyncServiceFactory = ({
|
|||||||
}
|
}
|
||||||
|
|
||||||
try {
|
try {
|
||||||
return deepEqual(sync.destinationConfig, destinationConfig);
|
return deepEqualSkipFields(sync.destinationConfig, destinationConfig, skipFields);
|
||||||
} catch {
|
} catch {
|
||||||
return false;
|
return false;
|
||||||
}
|
}
|
||||||
|
|||||||
@@ -326,7 +326,7 @@ export type TDeleteSecretSyncDTO = {
|
|||||||
|
|
||||||
export type TCheckDuplicateDestinationDTO = {
|
export type TCheckDuplicateDestinationDTO = {
|
||||||
destination: SecretSync;
|
destination: SecretSync;
|
||||||
destinationConfig: unknown;
|
destinationConfig: Record<string, unknown>;
|
||||||
excludeSyncId?: string;
|
excludeSyncId?: string;
|
||||||
projectId: string;
|
projectId: string;
|
||||||
};
|
};
|
||||||
|
|||||||
@@ -1,4 +1,4 @@
|
|||||||
import { ReactNode, useEffect, useState } from "react";
|
import { ReactNode, useCallback, useEffect, useState } from "react";
|
||||||
import { FormProvider, useForm } from "react-hook-form";
|
import { FormProvider, useForm } from "react-hook-form";
|
||||||
import { zodResolver } from "@hookform/resolvers/zod";
|
import { zodResolver } from "@hookform/resolvers/zod";
|
||||||
|
|
||||||
@@ -53,31 +53,34 @@ export const EditSecretSyncForm = ({ secretSync, fields, onComplete }: Props) =>
|
|||||||
{ enabled: checkDuplicateEnabled && Boolean(destinationConfigToCheck) }
|
{ enabled: checkDuplicateEnabled && Boolean(destinationConfigToCheck) }
|
||||||
);
|
);
|
||||||
|
|
||||||
const performUpdate = async (formData: TSecretSyncForm) => {
|
const performUpdate = useCallback(
|
||||||
try {
|
async (formData: TSecretSyncForm) => {
|
||||||
const { environment, connection, ...updateData } = formData;
|
try {
|
||||||
const updatedSecretSync = await updateSecretSync.mutateAsync({
|
const { environment, connection, ...updateData } = formData;
|
||||||
syncId: secretSync.id,
|
const updatedSecretSync = await updateSecretSync.mutateAsync({
|
||||||
...updateData,
|
syncId: secretSync.id,
|
||||||
environment: environment?.slug,
|
...updateData,
|
||||||
connectionId: connection.id,
|
environment: environment?.slug,
|
||||||
projectId: secretSync.projectId
|
connectionId: connection.id,
|
||||||
});
|
projectId: secretSync.projectId
|
||||||
|
});
|
||||||
|
|
||||||
createNotification({
|
createNotification({
|
||||||
text: `Successfully updated ${destinationName} Sync`,
|
text: `Successfully updated ${destinationName} Sync`,
|
||||||
type: "success"
|
type: "success"
|
||||||
});
|
});
|
||||||
onComplete(updatedSecretSync);
|
onComplete(updatedSecretSync);
|
||||||
} catch (err: any) {
|
} catch (err: any) {
|
||||||
console.error(err);
|
console.error(err);
|
||||||
createNotification({
|
createNotification({
|
||||||
title: `Failed to update ${destinationName} Sync`,
|
title: `Failed to update ${destinationName} Sync`,
|
||||||
text: err.message,
|
text: err.message,
|
||||||
type: "error"
|
type: "error"
|
||||||
});
|
});
|
||||||
}
|
}
|
||||||
};
|
},
|
||||||
|
[updateSecretSync, secretSync.id, secretSync.projectId, destinationName, onComplete]
|
||||||
|
);
|
||||||
|
|
||||||
useEffect(() => {
|
useEffect(() => {
|
||||||
if (checkDuplicateEnabled && !isCheckingDuplicate && destinationConfigToCheck) {
|
if (checkDuplicateEnabled && !isCheckingDuplicate && destinationConfigToCheck) {
|
||||||
|
|||||||
Reference in New Issue
Block a user