avoid syncing disabled azure keys

This commit is contained in:
McPizza0
2024-11-27 00:15:10 +01:00
parent 728f023263
commit 33411335ed
@@ -473,7 +473,7 @@ const syncSecretsAzureKeyVault = async ({
id: string; // secret URI id: string; // secret URI
value: string; value: string;
attributes: { attributes: {
enabled: true; enabled: boolean;
created: number; created: number;
updated: number; updated: number;
recoveryLevel: string; recoveryLevel: string;
@@ -507,14 +507,21 @@ const syncSecretsAzureKeyVault = async ({
return result; return result;
}; };
const getAzureKeyVaultSecrets = ( const getAzureKeyVaultSecrets = await paginateAzureKeyVaultSecrets(`${integration.app}/secrets?api-version=7.3`);
await paginateAzureKeyVaultSecrets(`${integration.app}/secrets?api-version=7.3`)
).filter((secret) => secret.attributes.enabled); const enabledAzureKeyVaultSecrets = getAzureKeyVaultSecrets.filter((secret) => secret.attributes.enabled);
// disabled keys to skip sending updates to
const disabledAzureKeyVaultSecretKeys = getAzureKeyVaultSecrets
.filter(({ attributes }) => !attributes.enabled)
.map((getAzureKeyVaultSecret) => {
return getAzureKeyVaultSecret.id.substring(getAzureKeyVaultSecret.id.lastIndexOf("/") + 1);
});
let lastSlashIndex: number; let lastSlashIndex: number;
const res = ( const res = (
await Promise.all( await Promise.all(
getAzureKeyVaultSecrets.map(async (getAzureKeyVaultSecret) => { enabledAzureKeyVaultSecrets.map(async (getAzureKeyVaultSecret) => {
if (!lastSlashIndex) { if (!lastSlashIndex) {
lastSlashIndex = getAzureKeyVaultSecret.id.lastIndexOf("/"); lastSlashIndex = getAzureKeyVaultSecret.id.lastIndexOf("/");
} }
@@ -660,6 +667,7 @@ const syncSecretsAzureKeyVault = async ({
}) => { }) => {
let isSecretSet = false; let isSecretSet = false;
let maxTries = 6; let maxTries = 6;
if (disabledAzureKeyVaultSecretKeys.includes(key)) return;
while (!isSecretSet && maxTries > 0) { while (!isSecretSet && maxTries > 0) {
// try to set secret // try to set secret