Skip to content

Commit

Permalink
Remove exception and conditionally protect keys with KV (#1241)
Browse files Browse the repository at this point in the history
  • Loading branch information
DrizzlyOwl authored Dec 10, 2024
1 parent 2bce106 commit f2b0c56
Showing 1 changed file with 3 additions and 4 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -15,16 +15,15 @@ public static void AddDataProtectionService(this IServiceCollection services, IC
var dpTargetPath = "@/srv/app/storage";

if (Directory.Exists(dpTargetPath)) {
dp.PersistKeysToFileSystem(new DirectoryInfo(dpTargetPath));

// If a Key Vault Key URI is defined, expect to encrypt the keys.xml
string kvProtectionKeyUri = configuration.GetValue<string>("DataProtection:KeyVaultKey");

if (!string.IsNullOrWhiteSpace(kvProtectionKeyUri))
{
throw new InvalidOperationException("DataProtection:Path is undefined or empty");
dp.ProtectKeysWithAzureKeyVault(new Uri(kvProtectionKeyUri), new DefaultAzureCredential());
}

dp.PersistKeysToFileSystem(new DirectoryInfo(dpTargetPath));
dp.ProtectKeysWithAzureKeyVault(new Uri(kvProtectionKeyUri), new DefaultAzureCredential());
}
}
}
Expand Down

0 comments on commit f2b0c56

Please sign in to comment.