Update secret-service.ts

This commit is contained in:
Daniel Hougaard
2024-05-16 03:31:01 +02:00
parent 58c1d3b0ac
commit 75b8b521b3
+23 -20
View File
@@ -981,25 +981,28 @@ export const secretServiceFactory = ({
}); });
const batchSecretsExpand = async ( const batchSecretsExpand = async (
secretBatch: { secretBatch: { secretKey: string; secretValue: string; secretComment?: string; secretPath: string }[]
secretKey: string;
secretValue: string;
secretComment?: string;
secretPath: string;
}[]
) => { ) => {
const secretRecord: Record< // Group secrets by secretPath
string, const secretsByPath: Record<string, { secretKey: string; secretValue: string; secretComment?: string }[]> = {};
{
value: string;
comment?: string;
skipMultilineEncoding?: boolean;
}
> = {};
secretBatch.forEach((decryptedSecret) => { secretBatch.forEach((secret) => {
const uniqueKey = `${decryptedSecret.secretPath}/${decryptedSecret.secretKey}`; if (!secretsByPath[secret.secretPath]) {
secretRecord[uniqueKey] = { secretsByPath[secret.secretPath] = [];
}
secretsByPath[secret.secretPath].push(secret);
});
// Expand secrets for each group
for (const secPath in secretsByPath) {
if (!Object.hasOwn(secretsByPath, path)) {
// eslint-disable-next-line no-continue
continue;
}
const secretRecord: Record<string, { value: string; comment?: string; skipMultilineEncoding?: boolean }> = {};
secretsByPath[secPath].forEach((decryptedSecret) => {
secretRecord[decryptedSecret.secretKey] = {
value: decryptedSecret.secretValue, value: decryptedSecret.secretValue,
comment: decryptedSecret.secretComment comment: decryptedSecret.secretComment
}; };
@@ -1007,11 +1010,11 @@ export const secretServiceFactory = ({
await expandSecrets(secretRecord); await expandSecrets(secretRecord);
secretBatch.forEach((decryptedSecret, index) => { secretsByPath[secPath].forEach((decryptedSecret) => {
const uniqueKey = `${decryptedSecret.secretPath}/${decryptedSecret.secretKey}`;
// eslint-disable-next-line no-param-reassign // eslint-disable-next-line no-param-reassign
secretBatch[index].secretValue = secretRecord[uniqueKey].value; decryptedSecret.secretValue = secretRecord[decryptedSecret.secretKey].value;
}); });
}
}; };
// expand secrets // expand secrets