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 (
secretBatch: {
secretKey: string;
secretValue: string;
secretComment?: string;
secretPath: string;
}[]
secretBatch: { secretKey: string; secretValue: string; secretComment?: string; secretPath: string }[]
) => {
const secretRecord: Record<
string,
{
value: string;
comment?: string;
skipMultilineEncoding?: boolean;
}
> = {};
// Group secrets by secretPath
const secretsByPath: Record<string, { secretKey: string; secretValue: string; secretComment?: string }[]> = {};
secretBatch.forEach((decryptedSecret) => {
const uniqueKey = `${decryptedSecret.secretPath}/${decryptedSecret.secretKey}`;
secretRecord[uniqueKey] = {
secretBatch.forEach((secret) => {
if (!secretsByPath[secret.secretPath]) {
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,
comment: decryptedSecret.secretComment
};
@@ -1007,11 +1010,11 @@ export const secretServiceFactory = ({
await expandSecrets(secretRecord);
secretBatch.forEach((decryptedSecret, index) => {
const uniqueKey = `${decryptedSecret.secretPath}/${decryptedSecret.secretKey}`;
secretsByPath[secPath].forEach((decryptedSecret) => {
// eslint-disable-next-line no-param-reassign
secretBatch[index].secretValue = secretRecord[uniqueKey].value;
decryptedSecret.secretValue = secretRecord[decryptedSecret.secretKey].value;
});
}
};
// expand secrets