Skip to content

Commit

Permalink
feat: export/publish built-in managed gateway apis
Browse files Browse the repository at this point in the history
  • Loading branch information
daviian committed Aug 21, 2024
1 parent b9c4361 commit b1725b7
Show file tree
Hide file tree
Showing 4 changed files with 32 additions and 5 deletions.
11 changes: 11 additions & 0 deletions tools/code/common/Gateway.cs
Original file line number Diff line number Diff line change
Expand Up @@ -15,6 +15,8 @@ namespace common;

public sealed record GatewayName : ResourceName, IResourceName<GatewayName>
{
public static GatewayName Managed { get; } = From("managed");

private GatewayName(string value) : base(value) { }

public static GatewayName From(string value) => new(value);
Expand Down Expand Up @@ -119,6 +121,15 @@ public static Option<GatewayInformationFile> 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; }
Expand Down
8 changes: 6 additions & 2 deletions tools/code/extractor/Gateway.cs
Original file line number Diff line number Diff line change
Expand Up @@ -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);
}
}
Expand All @@ -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<GatewayName> names, CancellationToken cancellationToken) =>
names.Select(name => GatewayUri.From(name, serviceUri))
Expand Down
2 changes: 2 additions & 0 deletions tools/code/publisher/Gateway.cs
Original file line number Diff line number Diff line change
Expand Up @@ -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);
};
Expand Down Expand Up @@ -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);
};
Expand Down
16 changes: 13 additions & 3 deletions tools/code/publisher/GatewayApi.cs
Original file line number Diff line number Diff line change
Expand Up @@ -11,6 +11,7 @@
using System.Linq;
using System.Threading;
using System.Threading.Tasks;
using LanguageExt.UnsafeValueAccess;

namespace publisher;

Expand Down Expand Up @@ -182,7 +183,9 @@ public static void ConfigureDeleteGatewayApis(IHostApplicationBuilder builder)
private static DeleteGatewayApis GetDeleteGatewayApis(IServiceProvider provider)
{
var getPublisherFiles = provider.GetRequiredService<GetPublisherFiles>();
var tryParseName = provider.GetRequiredService<TryParseGatewayApiName>();
var tryParseGatewayApiName = provider.GetRequiredService<TryParseGatewayApiName>();
var tryParseApiName = provider.GetRequiredService<TryParseApiName>();
var serviceDirectory = provider.GetRequiredService<ManagementServiceDirectory>();
var isNameInSourceControl = provider.GetRequiredService<IsGatewayApiNameInSourceControl>();
var delete = provider.GetRequiredService<DeleteGatewayApi>();
var activitySource = provider.GetRequiredService<ActivitySource>();
Expand All @@ -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);
Expand Down

0 comments on commit b1725b7

Please sign in to comment.