From 62a173111afd40dfa2c5f52e0def086cf5156fc0 Mon Sep 17 00:00:00 2001 From: Anudeep <94232161+anudeeps352@users.noreply.github.com> Date: Mon, 10 Jun 2024 13:33:54 +0530 Subject: [PATCH] refactor(api): Replace for loop with array indexing while decrypting secrets during bulk fetch #265 (#266) --- apps/api/src/secret/service/secret.service.ts | 19 ++++++++----------- 1 file changed, 8 insertions(+), 11 deletions(-) diff --git a/apps/api/src/secret/service/secret.service.ts b/apps/api/src/secret/service/secret.service.ts index 9f121353..8bd1ee6d 100644 --- a/apps/api/src/secret/service/secret.service.ts +++ b/apps/api/src/secret/service/secret.service.ts @@ -504,17 +504,14 @@ export class SecretService { } = {} for (const secret of secrets) { - // Decrypt the secret value - for (let i = 0; i < secret.versions.length; i++) { - const version = secret.versions[i] - // Optionally decrypt secret value if decryptValue is true - if (decryptValue) { - const decryptedValue = await decrypt( - project.privateKey, - version.value - ) - version.value = decryptedValue - } + // Optionally decrypt secret value if decryptValue is true + if (decryptValue) { + const latestSecretVersion = secret.versions[0] + const decryptedValue = await decrypt( + project.privateKey, + latestSecretVersion.value + ) + latestSecretVersion.value = decryptedValue } const { id, name } = secret.environment