Update secret-service.ts

This commit is contained in:
Daniel Hougaard
2024-05-16 03:31:01 +02:00
parent 58c1d3b0ac
commit 75b8b521b3
+29 -26
View File
@@ -981,37 +981,40 @@ 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; secretBatch.forEach((secret) => {
comment?: string; if (!secretsByPath[secret.secretPath]) {
skipMultilineEncoding?: boolean; secretsByPath[secret.secretPath] = [];
} }
> = {}; secretsByPath[secret.secretPath].push(secret);
secretBatch.forEach((decryptedSecret) => {
const uniqueKey = `${decryptedSecret.secretPath}/${decryptedSecret.secretKey}`;
secretRecord[uniqueKey] = {
value: decryptedSecret.secretValue,
comment: decryptedSecret.secretComment
};
}); });
await expandSecrets(secretRecord); // Expand secrets for each group
for (const secPath in secretsByPath) {
if (!Object.hasOwn(secretsByPath, path)) {
// eslint-disable-next-line no-continue
continue;
}
secretBatch.forEach((decryptedSecret, index) => { const secretRecord: Record<string, { value: string; comment?: string; skipMultilineEncoding?: boolean }> = {};
const uniqueKey = `${decryptedSecret.secretPath}/${decryptedSecret.secretKey}`; secretsByPath[secPath].forEach((decryptedSecret) => {
// eslint-disable-next-line no-param-reassign secretRecord[decryptedSecret.secretKey] = {
secretBatch[index].secretValue = secretRecord[uniqueKey].value; value: decryptedSecret.secretValue,
}); comment: decryptedSecret.secretComment
};
});
await expandSecrets(secretRecord);
secretsByPath[secPath].forEach((decryptedSecret) => {
// eslint-disable-next-line no-param-reassign
decryptedSecret.secretValue = secretRecord[decryptedSecret.secretKey].value;
});
}
}; };
// expand secrets // expand secrets