mirror of
https://github.com/awatertrevi/infisical.git
synced 2026-10-03 07:26:00 +00:00
Fix: Redundancies
This commit is contained in:
@@ -421,94 +421,88 @@ export const secretQueueFactory = ({
|
|||||||
|
|
||||||
const folder = await folderDAL.findBySecretPath(projectId, environment, secretPath);
|
const folder = await folderDAL.findBySecretPath(projectId, environment, secretPath);
|
||||||
if (!folder) {
|
if (!folder) {
|
||||||
logger.error(new Error("Secret path not found"));
|
throw new Error("Secret path not found");
|
||||||
return;
|
|
||||||
}
|
}
|
||||||
|
|
||||||
// start syncing all linked imports also
|
// find all imports made with the given environment and secret path
|
||||||
if (depth < MAX_SYNC_SECRET_DEPTH) {
|
const linkSourceDto = {
|
||||||
// find all imports made with the given environment and secret path
|
projectId,
|
||||||
const linkSourceDto = {
|
importEnv: folder.environment.id,
|
||||||
projectId,
|
importPath: secretPath,
|
||||||
importEnv: folder.environment.id,
|
isReplication: false
|
||||||
importPath: secretPath,
|
};
|
||||||
isReplication: false
|
const imports = await secretImportDAL.find(linkSourceDto);
|
||||||
};
|
|
||||||
const imports = await secretImportDAL.find(linkSourceDto);
|
|
||||||
|
|
||||||
if (imports.length) {
|
if (imports.length) {
|
||||||
// keep calling sync secret for all the imports made
|
// keep calling sync secret for all the imports made
|
||||||
const importedFolderIds = unique(imports, (i) => i.folderId).map(({ folderId }) => folderId);
|
const importedFolderIds = unique(imports, (i) => i.folderId).map(({ folderId }) => folderId);
|
||||||
const importedFolders = await folderDAL.findSecretPathByFolderIds(projectId, importedFolderIds);
|
const importedFolders = await folderDAL.findSecretPathByFolderIds(projectId, importedFolderIds);
|
||||||
const foldersGroupedById = groupBy(importedFolders.filter(Boolean), (i) => i?.id as string);
|
const foldersGroupedById = groupBy(importedFolders.filter(Boolean), (i) => i?.id as string);
|
||||||
logger.info(
|
logger.info(
|
||||||
`getIntegrationSecrets: Syncing secret due to link change [jobId=${job.id}] [projectId=${job.data.projectId}] [environment=${job.data.environment}] [secretPath=${job.data.secretPath}] [depth=${depth}]`
|
`getIntegrationSecrets: Syncing secret due to link change [jobId=${job.id}] [projectId=${job.data.projectId}] [environment=${job.data.environment}] [secretPath=${job.data.secretPath}] [depth=${depth}]`
|
||||||
);
|
);
|
||||||
await Promise.all(
|
await Promise.all(
|
||||||
imports
|
imports
|
||||||
.filter(({ folderId }) => Boolean(foldersGroupedById[folderId][0]?.path as string))
|
.filter(({ folderId }) => Boolean(foldersGroupedById[folderId][0]?.path as string))
|
||||||
// filter out already synced ones
|
// filter out already synced ones
|
||||||
.filter(
|
.filter(
|
||||||
({ folderId }) =>
|
({ folderId }) =>
|
||||||
!deDupeQueue[
|
!deDupeQueue[
|
||||||
uniqueSecretQueueKey(
|
uniqueSecretQueueKey(
|
||||||
foldersGroupedById[folderId][0]?.environmentSlug as string,
|
foldersGroupedById[folderId][0]?.environmentSlug as string,
|
||||||
foldersGroupedById[folderId][0]?.path as string
|
foldersGroupedById[folderId][0]?.path as string
|
||||||
)
|
)
|
||||||
]
|
]
|
||||||
)
|
)
|
||||||
.map(({ folderId }) =>
|
.map(({ folderId }) =>
|
||||||
syncSecrets({
|
syncSecrets({
|
||||||
projectId,
|
projectId,
|
||||||
secretPath: foldersGroupedById[folderId][0]?.path as string,
|
secretPath: foldersGroupedById[folderId][0]?.path as string,
|
||||||
environmentSlug: foldersGroupedById[folderId][0]?.environmentSlug as string,
|
environmentSlug: foldersGroupedById[folderId][0]?.environmentSlug as string,
|
||||||
_deDupeQueue: deDupeQueue,
|
_deDupeQueue: deDupeQueue,
|
||||||
_depth: depth + 1,
|
_depth: depth + 1,
|
||||||
excludeReplication: true
|
excludeReplication: true
|
||||||
})
|
})
|
||||||
)
|
)
|
||||||
);
|
);
|
||||||
}
|
}
|
||||||
|
|
||||||
const secretReferences = await secretDAL.findReferencedSecretReferences(
|
const secretReferences = await secretDAL.findReferencedSecretReferences(
|
||||||
projectId,
|
projectId,
|
||||||
folder.environment.slug,
|
folder.environment.slug,
|
||||||
secretPath
|
secretPath
|
||||||
|
);
|
||||||
|
if (secretReferences.length) {
|
||||||
|
const referencedFolderIds = unique(secretReferences, (i) => i.folderId).map(({ folderId }) => folderId);
|
||||||
|
const referencedFolders = await folderDAL.findSecretPathByFolderIds(projectId, referencedFolderIds);
|
||||||
|
const referencedFoldersGroupedById = groupBy(referencedFolders.filter(Boolean), (i) => i?.id as string);
|
||||||
|
logger.info(
|
||||||
|
`getIntegrationSecrets: Syncing secret due to reference change [jobId=${job.id}] [projectId=${job.data.projectId}] [environment=${job.data.environment}] [secretPath=${job.data.secretPath}] [depth=${depth}]`
|
||||||
|
);
|
||||||
|
await Promise.all(
|
||||||
|
secretReferences
|
||||||
|
.filter(({ folderId }) => Boolean(referencedFoldersGroupedById[folderId][0]?.path))
|
||||||
|
// filter out already synced ones
|
||||||
|
.filter(
|
||||||
|
({ folderId }) =>
|
||||||
|
!deDupeQueue[
|
||||||
|
uniqueSecretQueueKey(
|
||||||
|
referencedFoldersGroupedById[folderId][0]?.environmentSlug as string,
|
||||||
|
referencedFoldersGroupedById[folderId][0]?.path as string
|
||||||
|
)
|
||||||
|
]
|
||||||
|
)
|
||||||
|
.map(({ folderId }) =>
|
||||||
|
syncSecrets({
|
||||||
|
projectId,
|
||||||
|
secretPath: referencedFoldersGroupedById[folderId][0]?.path as string,
|
||||||
|
environmentSlug: referencedFoldersGroupedById[folderId][0]?.environmentSlug as string,
|
||||||
|
_deDupeQueue: deDupeQueue,
|
||||||
|
_depth: depth + 1,
|
||||||
|
excludeReplication: true
|
||||||
|
})
|
||||||
|
)
|
||||||
);
|
);
|
||||||
if (secretReferences.length) {
|
|
||||||
const referencedFolderIds = unique(secretReferences, (i) => i.folderId).map(({ folderId }) => folderId);
|
|
||||||
const referencedFolders = await folderDAL.findSecretPathByFolderIds(projectId, referencedFolderIds);
|
|
||||||
const referencedFoldersGroupedById = groupBy(referencedFolders.filter(Boolean), (i) => i?.id as string);
|
|
||||||
logger.info(
|
|
||||||
`getIntegrationSecrets: Syncing secret due to reference change [jobId=${job.id}] [projectId=${job.data.projectId}] [environment=${job.data.environment}] [secretPath=${job.data.secretPath}] [depth=${depth}]`
|
|
||||||
);
|
|
||||||
await Promise.all(
|
|
||||||
secretReferences
|
|
||||||
.filter(({ folderId }) => Boolean(referencedFoldersGroupedById[folderId][0]?.path))
|
|
||||||
// filter out already synced ones
|
|
||||||
.filter(
|
|
||||||
({ folderId }) =>
|
|
||||||
!deDupeQueue[
|
|
||||||
uniqueSecretQueueKey(
|
|
||||||
referencedFoldersGroupedById[folderId][0]?.environmentSlug as string,
|
|
||||||
referencedFoldersGroupedById[folderId][0]?.path as string
|
|
||||||
)
|
|
||||||
]
|
|
||||||
)
|
|
||||||
.map(({ folderId }) =>
|
|
||||||
syncSecrets({
|
|
||||||
projectId,
|
|
||||||
secretPath: referencedFoldersGroupedById[folderId][0]?.path as string,
|
|
||||||
environmentSlug: referencedFoldersGroupedById[folderId][0]?.environmentSlug as string,
|
|
||||||
_deDupeQueue: deDupeQueue,
|
|
||||||
_depth: depth + 1,
|
|
||||||
excludeReplication: true
|
|
||||||
})
|
|
||||||
)
|
|
||||||
);
|
|
||||||
}
|
|
||||||
} else {
|
|
||||||
logger.info(`getIntegrationSecrets: Secret depth exceeded for [projectId=${projectId}] [folderId=${folder.id}]`);
|
|
||||||
}
|
}
|
||||||
|
|
||||||
const integrations = await integrationDAL.findByProjectIdV2(projectId, environment); // note: returns array of integrations + integration auths in this environment
|
const integrations = await integrationDAL.findByProjectIdV2(projectId, environment); // note: returns array of integrations + integration auths in this environment
|
||||||
@@ -571,10 +565,12 @@ export const secretQueueFactory = ({
|
|||||||
syncMessage: "",
|
syncMessage: "",
|
||||||
isSynced: true
|
isSynced: true
|
||||||
});
|
});
|
||||||
} catch (err: unknown) {
|
} catch (err) {
|
||||||
logger.info("Secret integration sync error: %o", err);
|
logger.info("Secret integration sync error: %o", err);
|
||||||
|
|
||||||
const message =
|
const message =
|
||||||
err instanceof AxiosError ? JSON.stringify((err as AxiosError)?.response?.data) : (err as Error)?.message;
|
(err instanceof AxiosError ? JSON.stringify(err?.response?.data) : (err as Error)?.message) ||
|
||||||
|
"Unknown error occurred.";
|
||||||
|
|
||||||
await integrationDAL.updateById(integration.id, {
|
await integrationDAL.updateById(integration.id, {
|
||||||
lastSyncJobId: job.id,
|
lastSyncJobId: job.id,
|
||||||
|
|||||||
Reference in New Issue
Block a user