diff --git a/tools/code/publisher/App.cs b/tools/code/publisher/App.cs index 8bb27ede..56250196 100644 --- a/tools/code/publisher/App.cs +++ b/tools/code/publisher/App.cs @@ -15,6 +15,8 @@ namespace publisher; file sealed class RunPublisherHandler(ProcessNamedValuesToPut processNamedValuesToPut, ProcessDeletedNamedValues processDeletedNamedValues, + ProcessBackendsToPut processBackendsToPut, + ProcessDeletedBackends processDeletedBackends, GetPublisherFiles getPublisherFiles, PublishFile publishFile, ILoggerFactory loggerFactory) @@ -24,10 +26,12 @@ file sealed class RunPublisherHandler(ProcessNamedValuesToPut processNamedValues public async ValueTask Handle(CancellationToken cancellationToken) { await processNamedValuesToPut(cancellationToken); + await processBackendsToPut(cancellationToken); await ProcessPublisherFiles(cancellationToken); await processDeletedNamedValues(cancellationToken); + await processDeletedBackends(cancellationToken); logger.LogInformation("Publisher completed."); } @@ -47,7 +51,6 @@ private async ValueTask ProcessPublisherFiles(CancellationToken cancellationToke file sealed class PublishFileHandler(FindTagAction findTagAction, FindGatewayAction findGatewayAction, FindVersionSetAction findVersionSetAction, - FindBackendAction findBackendAction, FindLoggerAction findLoggerAction, FindDiagnosticAction findDiagnosticAction, FindPolicyFragmentAction findPolicyFragmentAction, @@ -75,7 +78,6 @@ private Option FindPublisherAction(FileInfo file) => findTagAction(file) | findGatewayAction(file) | findVersionSetAction(file) - | findBackendAction(file) | findLoggerAction(file) | findDiagnosticAction(file) | findPolicyFragmentAction(file) @@ -100,6 +102,8 @@ public static void ConfigureRunPublisher(IServiceCollection services) { NamedValueServices.ConfigureProcessNamedValuesToPut(services); NamedValueServices.ConfigureProcessDeletedNamedValues(services); + BackendServices.ConfigureProcessBackendsToPut(services); + BackendServices.ConfigureProcessDeletedBackends(services); ConfigurePublishFile(services); services.TryAddSingleton(); @@ -111,7 +115,6 @@ private static void ConfigurePublishFile(IServiceCollection services) TagServices.ConfigureFindTagAction(services); GatewayServices.ConfigureFindGatewayAction(services); VersionSetServices.ConfigureFindVersionSetAction(services); - BackendServices.ConfigureFindBackendAction(services); LoggerServices.ConfigureFindLoggerAction(services); DiagnosticServices.ConfigureFindDiagnosticAction(services); PolicyFragmentServices.ConfigureFindPolicyFragmentAction(services); diff --git a/tools/code/publisher/Backend.cs b/tools/code/publisher/Backend.cs index 00ecea3a..c0dcb259 100644 --- a/tools/code/publisher/Backend.cs +++ b/tools/code/publisher/Backend.cs @@ -9,12 +9,14 @@ using System.Collections.Generic; using System.Collections.Immutable; using System.IO; +using System.Linq; using System.Threading; using System.Threading.Tasks; namespace publisher; -internal delegate Option FindBackendAction(FileInfo file); +internal delegate ValueTask ProcessBackendsToPut(CancellationToken cancellationToken); +internal delegate ValueTask ProcessDeletedBackends(CancellationToken cancellationToken); file delegate Option TryParseBackendName(FileInfo file); @@ -32,6 +34,30 @@ namespace publisher; file delegate ValueTask DeleteBackendFromApim(BackendName name, CancellationToken cancellationToken); +file sealed class ProcessBackendsToPutHandler(GetPublisherFiles getPublisherFiles, + TryParseBackendName tryParseBackendName, + IsBackendNameInSourceControl isNameInSourceControl, + PutBackend putBackend) +{ + public async ValueTask Handle(CancellationToken cancellationToken) => + await getPublisherFiles() + .Choose(tryParseBackendName.Invoke) + .Where(isNameInSourceControl.Invoke) + .IterParallel(putBackend.Invoke, cancellationToken); +} + +file sealed class ProcessDeletedBackendsHandler(GetPublisherFiles getPublisherFiles, + TryParseBackendName tryParseBackendName, + IsBackendNameInSourceControl isNameInSourceControl, + DeleteBackend deleteBackend) +{ + public async ValueTask Handle(CancellationToken cancellationToken) => + await getPublisherFiles() + .Choose(tryParseBackendName.Invoke) + .Where(name => isNameInSourceControl(name) is false) + .IterParallel(deleteBackend.Invoke, cancellationToken); +} + file sealed class FindBackendActionHandler(TryParseBackendName tryParseName, ProcessBackend processBackend) { public Option Handle(FileInfo file) => @@ -189,13 +215,14 @@ public async ValueTask Handle(BackendName name, CancellationToken cancellationTo internal static class BackendServices { - public static void ConfigureFindBackendAction(IServiceCollection services) + public static void ConfigureProcessBackendsToPut(IServiceCollection services) { ConfigureTryParseBackendName(services); - ConfigureProcessBackend(services); + ConfigureIsBackendNameInSourceControl(services); + ConfigurePutBackend(services); - services.TryAddSingleton(); - services.TryAddSingleton(provider => provider.GetRequiredService().Handle); + services.TryAddSingleton(); + services.TryAddSingleton(provider => provider.GetRequiredService().Handle); } private static void ConfigureTryParseBackendName(IServiceCollection services) @@ -241,6 +268,16 @@ private static void ConfigurePutBackendInApim(IServiceCollection services) services.TryAddSingleton(provider => provider.GetRequiredService().Handle); } + public static void ConfigureProcessDeletedBackends(IServiceCollection services) + { + ConfigureTryParseBackendName(services); + ConfigureIsBackendNameInSourceControl(services); + ConfigureDeleteBackend(services); + + services.TryAddSingleton(); + services.TryAddSingleton(provider => provider.GetRequiredService().Handle); + } + private static void ConfigureDeleteBackend(IServiceCollection services) { ConfigureDeleteBackendFromApim(services);