Optional response

This commit is contained in:
Daniel Hougaard
2024-06-18 12:33:36 +02:00
parent a5cf6f40c7
commit 719d0ea30f
2 changed files with 19 additions and 7 deletions
@@ -18,7 +18,7 @@ import {
UpdateSecretCommand UpdateSecretCommand
} from "@aws-sdk/client-secrets-manager"; } from "@aws-sdk/client-secrets-manager";
import { Octokit } from "@octokit/rest"; import { Octokit } from "@octokit/rest";
import AWS from "aws-sdk"; import AWS, { AWSError } from "aws-sdk";
import { AxiosError } from "axios"; import { AxiosError } from "axios";
import sodium from "libsodium-wrappers"; import sodium from "libsodium-wrappers";
import isEqual from "lodash.isequal"; import isEqual from "lodash.isequal";
@@ -452,7 +452,9 @@ const syncSecretsAWSParameterStore = async ({
accessId: string | null; accessId: string | null;
accessToken: string; accessToken: string;
}) => { }) => {
if (!accessId) return; let response: { isSynced: boolean; syncMessage: string } | null = null;
if (!accessId) return null;
const config = new AWS.Config({ const config = new AWS.Config({
region: integration.region as string, region: integration.region as string,
@@ -556,8 +558,12 @@ const syncSecretsAWSParameterStore = async ({
logger.error( logger.error(
`AWS Parameter Store Error [integration=${integration.id}]: double check AWS account permissions (refer to the Infisical docs)` `AWS Parameter Store Error [integration=${integration.id}]: double check AWS account permissions (refer to the Infisical docs)`
); );
throw err;
} }
response = {
isSynced: false,
syncMessage: (err as AWSError)?.message || "Error syncing with AWS Parameter Store"
};
} }
} }
} }
@@ -586,6 +592,8 @@ const syncSecretsAWSParameterStore = async ({
} }
} }
} }
return response;
}; };
/** /**
@@ -3488,6 +3496,8 @@ export const syncIntegrationSecrets = async ({
accessToken: string; accessToken: string;
appendices?: { prefix: string; suffix: string }; appendices?: { prefix: string; suffix: string };
}) => { }) => {
let response: { isSynced: boolean; syncMessage: string } | null = null;
switch (integration.integration) { switch (integration.integration) {
case Integrations.GCP_SECRET_MANAGER: case Integrations.GCP_SECRET_MANAGER:
await syncSecretsGCPSecretManager({ await syncSecretsGCPSecretManager({
@@ -3504,7 +3514,7 @@ export const syncIntegrationSecrets = async ({
}); });
break; break;
case Integrations.AWS_PARAMETER_STORE: case Integrations.AWS_PARAMETER_STORE:
await syncSecretsAWSParameterStore({ response = await syncSecretsAWSParameterStore({
integration, integration,
secrets, secrets,
accessId, accessId,
@@ -3728,4 +3738,6 @@ export const syncIntegrationSecrets = async ({
default: default:
throw new BadRequestError({ message: "Invalid integration" }); throw new BadRequestError({ message: "Invalid integration" });
} }
return response;
}; };
+3 -3
View File
@@ -544,7 +544,7 @@ export const secretQueueFactory = ({
} }
try { try {
await syncIntegrationSecrets({ const response = await syncIntegrationSecrets({
createManySecretsRawFn, createManySecretsRawFn,
updateManySecretsRawFn, updateManySecretsRawFn,
integrationDAL, integrationDAL,
@@ -562,8 +562,8 @@ export const secretQueueFactory = ({
await integrationDAL.updateById(integration.id, { await integrationDAL.updateById(integration.id, {
lastSyncJobId: job.id, lastSyncJobId: job.id,
lastUsed: new Date(), lastUsed: new Date(),
syncMessage: "", syncMessage: response?.syncMessage || "",
isSynced: true isSynced: response?.isSynced || true
}); });
} catch (err) { } catch (err) {
logger.info("Secret integration sync error: %o", err); logger.info("Secret integration sync error: %o", err);