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."); } } }