Skip to content

Commit

Permalink
Continue processing secrets if one failes rotation (#8168)
Browse files Browse the repository at this point in the history
  • Loading branch information
hallipr authored Apr 29, 2024
1 parent 677526b commit 9e7f6fc
Showing 1 changed file with 17 additions and 2 deletions.
Original file line number Diff line number Diff line change
@@ -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;

Expand All @@ -25,10 +26,24 @@ protected override async Task HandleCommandAsync(ILogger logger, RotationConfigu
var timeProvider = new TimeProvider();

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

0 comments on commit 9e7f6fc

Please sign in to comment.