Skip to content

Commit bf52d63

Browse files
author
Guy Fankam
committed
Add workspace resources
1 parent b40089c commit bf52d63

52 files changed

Lines changed: 3308 additions & 1176 deletions

Some content is hidden

Large Commits have some content hidden by default. Use the searchbox below for content that may be hidden.

src/aspire/aspire.csproj

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -1,18 +1,18 @@
11
<Project Sdk="Microsoft.NET.Sdk">
22

3-
<Sdk Name="Aspire.AppHost.Sdk" Version="9.0.0" />
3+
<Sdk Name="Aspire.AppHost.Sdk" Version="13.0.0" />
44

55
<PropertyGroup>
66
<OutputType>Exe</OutputType>
77
<TargetFramework>net9.0</TargetFramework>
88
<ImplicitUsings>enable</ImplicitUsings>
99
<Nullable>enable</Nullable>
1010
<IsAspireHost>true</IsAspireHost>
11-
<UserSecretsId>6ce9dc18-ea0d-4d82-8f1a-e63877f35b88</UserSecretsId>
11+
<UserSecretsId>005123cc-339c-4ba3-a189-a918d08c6467</UserSecretsId>
1212
</PropertyGroup>
1313

1414
<ItemGroup>
15-
<PackageReference Include="Aspire.Hosting.AppHost" Version="9.5.1" />
15+
<PackageReference Include="Aspire.Hosting.AppHost" Version="13.0.0" />
1616
</ItemGroup>
1717

1818
<ItemGroup>

src/common/Api.cs

Lines changed: 5 additions & 50 deletions
Original file line numberDiff line numberDiff line change
@@ -1,8 +1,6 @@
11
using Azure.Core.Pipeline;
2-
using Flurl;
32
using System;
43
using System.Collections.Immutable;
5-
using System.IO;
64
using System.Linq;
75
using System.Text.Json.Nodes;
86
using System.Text.Json.Serialization;
@@ -260,35 +258,6 @@ public record WsdlSelectorContract
260258
}
261259
}
262260

263-
public static class ApiRevisionModule
264-
{
265-
private const string separator = ";rev=";
266-
267-
public static bool IsRootName(ResourceName name) =>
268-
Parse(name).IsNone;
269-
270-
public static ResourceName GetRootName(ResourceName name) =>
271-
Parse(name).Map(x => x.RootName)
272-
.IfNone(() => name);
273-
274-
public static Option<(ResourceName RootName, int Revision)> Parse(ResourceName name) =>
275-
name.ToString().Split(separator).ToArray() switch
276-
{
277-
[var first, var second] => from rootName in ResourceName.From(first).ToOption()
278-
from revision in int.TryParse(second, out var revision)
279-
? Option.Some(revision)
280-
: Option.None
281-
select (rootName, revision),
282-
_ => Option.None
283-
};
284-
285-
public static ResourceName Combine(ResourceName rootName, int revision) =>
286-
revision < 1
287-
? throw new InvalidOperationException($"Revision must be positive.")
288-
: ResourceName.From($"{rootName}{separator}{revision}")
289-
.IfErrorThrow();
290-
}
291-
292261
public static partial class ResourceModule
293262
{
294263
private static async ValueTask PutApiInApim(ResourceName name, JsonObject dto, GetResourceDtoFromApim getApimDto, HttpPipeline pipeline, ServiceUri serviceUri, CancellationToken cancellationToken)
@@ -298,11 +267,12 @@ private static async ValueTask PutApiInApim(ResourceName name, JsonObject dto, G
298267

299268
var uri = resource.GetUri(name, parentChain, serviceUri);
300269
var formattedDto = await formatDto();
301-
var result = await pipeline.PutJson(uri, formattedDto, cancellationToken);
270+
271+
var result = await pipeline.PutJson(uri, formattedDto, cancellationToken);
302272
result.IfErrorThrow();
303273

304274
// Non-current revisions are not allowed to update certain properties.
305-
// Replace them with the existing revision properties if necessary.
275+
// Replace them with the current revision's properties if necessary.
306276
async ValueTask<JsonObject> formatDto()
307277
{
308278
// If this is the current revision, return the DTO as-is.
@@ -312,9 +282,10 @@ async ValueTask<JsonObject> formatDto()
312282
return dto;
313283
}
314284

315-
// Otherwise, update the DTO with the appropriate current revision properties.
285+
// Otherwise, get the current revision's DTO from APIM...
316286
var existingDto = await getApimDto(resource, rootName, parentChain, cancellationToken);
317287

288+
// ...and use its properties to format the new revision's DTO.
318289
var result = from existingDtoObject in JsonNodeModule.To<ApiDto>(existingDto, resource.SerializerOptions)
319290
from newDtoObject in JsonNodeModule.To<ApiDto>(dto, resource.SerializerOptions)
320291
let formattedDtoObject = newDtoObject with
@@ -354,20 +325,4 @@ private static JsonObject FormatInformationFileDto(this ApiResource resource, Js
354325
return JsonObjectModule.From(dto, serializerOptions)
355326
.IfErrorThrow();
356327
}
357-
358-
private static Option<(ResourceName Name, ParentChain Ancestors)> ParseSpecificationFile(this ApiResource resource, FileInfo? file, ServiceDirectory serviceDirectory)
359-
{
360-
if (file is null)
361-
{
362-
return Option.None;
363-
}
364-
365-
var specificationFileNames = specifications.Select(GetSpecificationFileName);
366-
if (specificationFileNames.Contains(file.Name) is false)
367-
{
368-
return Option.None;
369-
}
370-
371-
return resource.ParseDirectory(file.Directory, serviceDirectory);
372-
}
373328
}

src/common/ApiOperation.cs

Lines changed: 18 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,18 @@
1+
namespace common;
2+
3+
public sealed record ApiOperationResource : IResourceWithDirectory, IChildResource
4+
{
5+
private ApiOperationResource() { }
6+
7+
public string CollectionDirectoryName { get; } = "operations";
8+
9+
public string SingularName { get; } = "operation";
10+
11+
public string PluralName { get; } = "operations";
12+
13+
public string CollectionUriPath { get; } = "operations";
14+
15+
public IResource Parent { get; } = ApiResource.Instance;
16+
17+
public static ApiOperationResource Instance { get; } = new();
18+
}

src/common/ApiOperationPolicy.cs

Lines changed: 10 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,10 @@
1+
namespace common;
2+
3+
public sealed record ApiOperationPolicyResource : IPolicyResource, IChildResource
4+
{
5+
private ApiOperationPolicyResource() { }
6+
7+
public IResource Parent { get; } = ApiOperationResource.Instance;
8+
9+
public static ApiOperationPolicyResource Instance { get; } = new();
10+
}

src/common/ApiRelease.cs

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -70,9 +70,11 @@ private static async ValueTask PutApiReleaseInApim(ResourceName name,
7070

7171
var uri = resource.GetUri(name, ancestors, serviceUri);
7272
var formattedDto = formatDto(dto);
73+
7374
var result = await pipeline.PutJson(uri, formattedDto, cancellationToken);
7475
result.IfErrorThrow();
7576

77+
// Set the API ID if it's missing from the DTO
7678
JsonObject formatDto(JsonObject dtoJson)
7779
{
7880
var serializerOptions = ((IResourceWithDto)resource).SerializerOptions;

src/common/ApiRevision.cs

Lines changed: 40 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,40 @@
1+
using Azure.Core.Pipeline;
2+
using System;
3+
using System.Collections.Immutable;
4+
using System.IO;
5+
using System.Linq;
6+
using System.Text.Json.Nodes;
7+
using System.Text.Json.Serialization;
8+
using System.Threading;
9+
using System.Threading.Tasks;
10+
11+
namespace common;
12+
13+
public static class ApiRevisionModule
14+
{
15+
private const string separator = ";rev=";
16+
17+
public static bool IsRootName(ResourceName name) =>
18+
Parse(name).IsNone;
19+
20+
public static ResourceName GetRootName(ResourceName name) =>
21+
Parse(name).Map(x => x.RootName)
22+
.IfNone(() => name);
23+
24+
public static Option<(ResourceName RootName, int Revision)> Parse(ResourceName name) =>
25+
name.ToString().Split(separator).ToArray() switch
26+
{
27+
[var first, var second] => from rootName in ResourceName.From(first).ToOption()
28+
from revision in int.TryParse(second, out var revision)
29+
? Option.Some(revision)
30+
: Option.None
31+
select (rootName, revision),
32+
_ => Option.None
33+
};
34+
35+
public static ResourceName Combine(ResourceName rootName, int revision) =>
36+
revision < 1
37+
? throw new InvalidOperationException($"Revision must be positive.")
38+
: ResourceName.From($"{rootName}{separator}{revision}")
39+
.IfErrorThrow();
40+
}

0 commit comments

Comments
 (0)