improve logs for aws ssm debug

This commit is contained in:
Maidul Islam
2024-08-13 12:40:02 -04:00
parent 943b540383
commit 2b16c19b70

View File

@@ -552,9 +552,6 @@ const syncSecretsAWSParameterStore = async ({
if (!accessId) {
throw new Error("AWS access ID is required");
}
logger.info(
`getIntegrationSecrets: [projectId=${projectId}] [environment=${integration.environment.slug}] [secretPath=${integration.secretPath}] ssm debug: started`
);
const config = new AWS.Config({
region: integration.region as string,
credentials: {
@@ -571,7 +568,9 @@ const syncSecretsAWSParameterStore = async ({
const metadata = z.record(z.any()).parse(integration.metadata || {});
const awsParameterStoreSecretsObj: Record<string, AWS.SSM.Parameter> = {};
logger.info(
`getIntegrationSecrets: integration sync triggered for ssm with [projectId=${projectId}] [environment=${integration.environment.slug}] [secretPath=${integration.secretPath}] [shouldDisableDelete=${metadata.shouldDisableDelete}]`
);
// now fetch all aws parameter store secrets
let hasNext = true;
let nextToken: string | undefined;
@@ -599,14 +598,16 @@ const syncSecretsAWSParameterStore = async ({
}
logger.info(
`getIntegrationSecrets: [projectId=${projectId}] [environment=${integration.environment.slug}] [secretPath=${
integration.secretPath
}] ssm debug: ${Object.keys(awsParameterStoreSecretsObj).join(",")}`
`getIntegrationSecrets: all fetched keys from AWS SSM [projectId=${projectId}] [environment=${
integration.environment.slug
}] [secretPath=${integration.secretPath}] [awsParameterStoreSecretsObj=${Object.keys(
awsParameterStoreSecretsObj
).join(",")}]`
);
logger.info(
`getIntegrationSecrets: [projectId=${projectId}] [environment=${integration.environment.slug}] [secretPath=${
integration.secretPath
}] ssm infisical secrets debug: ${Object.keys(secrets).join(",")}`
`getIntegrationSecrets: all secrets from Infisical to send to AWS SSM [projectId=${projectId}] [environment=${
integration.environment.slug
}] [secretPath=${integration.secretPath}] [secrets=${Object.keys(secrets).join(",")}]`
);
// Identify secrets to create
// don't use Promise.all() and promise map here
@@ -618,7 +619,7 @@ const syncSecretsAWSParameterStore = async ({
// -> create secret
if (secrets[key].value) {
logger.info(
`getIntegrationSecrets: [projectId=${projectId}] [environment=${integration.environment.slug}] [secretPath=${integration.secretPath}] ssm debug create: ${key}`
`getIntegrationSecrets: create secret in AWS SSM for [projectId=${projectId}] [environment=${integration.environment.slug}] [secretPath=${integration.secretPath}] [key=${key}]`
);
await ssm
.putParameter({
@@ -661,7 +662,7 @@ const syncSecretsAWSParameterStore = async ({
// case: secret exists in AWS parameter store
} else {
logger.info(
`getIntegrationSecrets: [projectId=${projectId}] [environment=${integration.environment.slug}] [secretPath=${integration.secretPath}] ssm debug update: ${key}`
`getIntegrationSecrets: update secret in AWS SSM for [projectId=${projectId}] [environment=${integration.environment.slug}] [secretPath=${integration.secretPath}] [key=${key}]`
);
// -> update secret
if (awsParameterStoreSecretsObj[key].Value !== secrets[key].value) {
@@ -713,16 +714,16 @@ const syncSecretsAWSParameterStore = async ({
if (!metadata.shouldDisableDelete) {
logger.info(
`getIntegrationSecrets: [projectId=${projectId}] [environment=${integration.environment.slug}] [secretPath=${integration.secretPath}] ssm debug delete started`
`getIntegrationSecrets: inside of shouldDisableDelete AWS SSM [projectId=${projectId}] [environment=${integration.environment.slug}] [secretPath=${integration.secretPath}] [step=1]`
);
for (const key in awsParameterStoreSecretsObj) {
if (Object.hasOwn(awsParameterStoreSecretsObj, key)) {
logger.info(
`getIntegrationSecrets: [projectId=${projectId}] [environment=${integration.environment.slug}] [secretPath=${integration.secretPath}] ssm debug delete in hasOwn: ${key}`
`getIntegrationSecrets: inside of shouldDisableDelete AWS SSM [projectId=${projectId}] [environment=${integration.environment.slug}] [secretPath=${integration.secretPath}] [key=${key}] [step=2]`
);
if (!(key in secrets)) {
logger.info(
`getIntegrationSecrets: [projectId=${projectId}] [environment=${integration.environment.slug}] [secretPath=${integration.secretPath}] ssm debug delete: ${key}`
`getIntegrationSecrets: inside of shouldDisableDelete AWS SSM [projectId=${projectId}] [environment=${integration.environment.slug}] [secretPath=${integration.secretPath}] [key=${key}] [step=3]`
);
// case:
// -> delete secret
@@ -732,7 +733,7 @@ const syncSecretsAWSParameterStore = async ({
})
.promise();
logger.info(
`getIntegrationSecrets: [projectId=${projectId}] [environment=${integration.environment.slug}] [secretPath=${integration.secretPath}] ssm debug delete completed: ${key}`
`getIntegrationSecrets: inside of shouldDisableDelete AWS SSM [projectId=${projectId}] [environment=${integration.environment.slug}] [secretPath=${integration.secretPath}] [key=${key}] [step=4]`
);
}
await new Promise((resolve) => {