From 9e7f6fcbbd8dab594a9ea67e7aa75cb0931ed328 Mon Sep 17 00:00:00 2001 From: Patrick Hallisey Date: Mon, 29 Apr 2024 13:53:18 -0700 Subject: [PATCH] Continue processing secrets if one failes rotation (#8168) --- .../Commands/RotateCommand.cs | 19 +++++++++++++++++-- 1 file changed, 17 insertions(+), 2 deletions(-) diff --git a/tools/secret-management/Azure.Sdk.Tools.SecretManagement.Cli/Commands/RotateCommand.cs b/tools/secret-management/Azure.Sdk.Tools.SecretManagement.Cli/Commands/RotateCommand.cs index 9f4c29deef3..4ba2fafd6a9 100644 --- a/tools/secret-management/Azure.Sdk.Tools.SecretManagement.Cli/Commands/RotateCommand.cs +++ b/tools/secret-management/Azure.Sdk.Tools.SecretManagement.Cli/Commands/RotateCommand.cs @@ -1,7 +1,8 @@ -using System.CommandLine; +using System.CommandLine; using System.CommandLine.Invocation; using Azure.Sdk.Tools.SecretRotation.Configuration; using Azure.Sdk.Tools.SecretRotation.Core; +using Microsoft.Extensions.Logging; namespace Azure.Sdk.Tools.SecretManagement.Cli.Commands; @@ -25,10 +26,24 @@ protected override async Task HandleCommandAsync(ILogger logger, RotationConfigu var timeProvider = new TimeProvider(); IEnumerable plans = rotationConfiguration.GetAllRotationPlans(logger, timeProvider); + bool success = true; foreach (RotationPlan plan in plans) { - await plan.ExecuteAsync(onlyRotateExpiring, whatIf); + try + { + await plan.ExecuteAsync(onlyRotateExpiring, whatIf); + } + catch (Exception ex) + { + logger.LogError(ex, "Exception thrown while executing plan {PlanName}", plan.Name); + success = false; + } + } + + if(!success) + { + throw new RotationException("Errors occurred while rotating secrets."); } } }