diff --git a/tools/code/common/Gateway.cs b/tools/code/common/Gateway.cs index 9b40ed9c..b177f51b 100644 --- a/tools/code/common/Gateway.cs +++ b/tools/code/common/Gateway.cs @@ -15,6 +15,8 @@ namespace common; public sealed record GatewayName : ResourceName, IResourceName { + public static GatewayName Managed { get; } = From("managed"); + private GatewayName(string value) : base(value) { } public static GatewayName From(string value) => new(value); @@ -119,6 +121,15 @@ public static Option TryParse(FileInfo? file, Management public sealed record GatewayDto { + public static GatewayDto Managed { get; } = new() + { + Properties = new GatewayContract + { + Description = null, + LocationData = null + } + }; + [JsonPropertyName("properties")] [JsonIgnore(Condition = JsonIgnoreCondition.WhenWritingDefault)] public required GatewayContract Properties { get; init; } diff --git a/tools/code/extractor/Gateway.cs b/tools/code/extractor/Gateway.cs index 47611dff..09ca0487 100644 --- a/tools/code/extractor/Gateway.cs +++ b/tools/code/extractor/Gateway.cs @@ -52,7 +52,10 @@ await list(cancellationToken) async ValueTask extractGateway(GatewayName name, GatewayDto dto, CancellationToken cancellationToken) { - await writeArtifacts(name, dto, cancellationToken); + if (name != GatewayName.Managed) + { + await writeArtifacts(name, dto, cancellationToken); + } await extractGatewayApis(name, cancellationToken); } } @@ -77,7 +80,8 @@ private static ListGateways GetListGateways(IServiceProvider provider) return cancellationToken => findConfigurationNames() .Map(names => listFromSet(names, cancellationToken)) - .IfNone(() => listAll(cancellationToken)); + .IfNone(() => listAll(cancellationToken)) + .Append((GatewayName.Managed, GatewayDto.Managed)); IAsyncEnumerable<(GatewayName, GatewayDto)> listFromSet(IEnumerable names, CancellationToken cancellationToken) => names.Select(name => GatewayUri.From(name, serviceUri)) diff --git a/tools/code/publisher/Gateway.cs b/tools/code/publisher/Gateway.cs index cd6916c0..7591290f 100644 --- a/tools/code/publisher/Gateway.cs +++ b/tools/code/publisher/Gateway.cs @@ -54,6 +54,7 @@ private static PutGateways GetPutGateways(IServiceProvider provider) await getPublisherFiles() .Choose(tryParseName.Invoke) .Where(isNameInSourceControl.Invoke) + .Where(name => name != GatewayName.Managed) .Distinct() .IterParallel(put.Invoke, cancellationToken); }; @@ -203,6 +204,7 @@ private static DeleteGateways GetDeleteGateways(IServiceProvider provider) await getPublisherFiles() .Choose(tryParseName.Invoke) .Where(name => isNameInSourceControl(name) is false) + .Where(name => name != GatewayName.Managed) .Distinct() .IterParallel(delete.Invoke, cancellationToken); }; diff --git a/tools/code/publisher/GatewayApi.cs b/tools/code/publisher/GatewayApi.cs index dd205518..05f476aa 100644 --- a/tools/code/publisher/GatewayApi.cs +++ b/tools/code/publisher/GatewayApi.cs @@ -11,6 +11,7 @@ using System.Linq; using System.Threading; using System.Threading.Tasks; +using LanguageExt.UnsafeValueAccess; namespace publisher; @@ -182,7 +183,9 @@ public static void ConfigureDeleteGatewayApis(IHostApplicationBuilder builder) private static DeleteGatewayApis GetDeleteGatewayApis(IServiceProvider provider) { var getPublisherFiles = provider.GetRequiredService(); - var tryParseName = provider.GetRequiredService(); + var tryParseGatewayApiName = provider.GetRequiredService(); + var tryParseApiName = provider.GetRequiredService(); + var serviceDirectory = provider.GetRequiredService(); var isNameInSourceControl = provider.GetRequiredService(); var delete = provider.GetRequiredService(); var activitySource = provider.GetRequiredService(); @@ -194,8 +197,15 @@ private static DeleteGatewayApis GetDeleteGatewayApis(IServiceProvider provider) logger.LogInformation("Deleting gateway apis..."); - await getPublisherFiles() - .Choose(tryParseName.Invoke) + var publisherFiles = getPublisherFiles(); + var managedGatewayGatewayApis = publisherFiles.Select(x => tryParseApiName(x)) + .Where(x => x.IsSome) + .Select(x => GatewayApiInformationFile.From(x.ValueUnsafe()!, GatewayName.Managed, serviceDirectory) + .ToFileInfo()); + + await publisherFiles + .Concat(managedGatewayGatewayApis) + .Choose(tryParseGatewayApiName.Invoke) .Where(api => isNameInSourceControl(api.Name, api.GatewayName) is false) .Distinct() .IterParallel(delete.Invoke, cancellationToken);