Skip to content

Commit b04cc52

Browse files
author
Guy Fankam
committed
Closes #803
1 parent 66c0ecc commit b04cc52

3 files changed

Lines changed: 38 additions & 13 deletions

File tree

src/common/Api.cs

Lines changed: 1 addition & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -308,16 +308,14 @@ from updatedDto in JsonObjectModule.From(formattedDtoObject, resource.Serializer
308308
}
309309
}
310310

311-
/// <summary>
312-
/// If the 'serviceUrl' property is empty, remove it. APIM doesn't support publishing blank service URLs.
313-
/// </summary>
314311
private static JsonObject FormatInformationFileDto(this ApiResource resource, JsonObject dtoJson)
315312
{
316313
var serializerOptions = ((IResourceWithDto)resource).SerializerOptions;
317314

318315
var dto = JsonNodeModule.To<ApiDto>(dtoJson, serializerOptions)
319316
.IfErrorThrow();
320317

318+
// If the 'serviceUrl' property is empty, remove it. APIM doesn't support publishing blank service URLs.
321319
dto = string.IsNullOrWhiteSpace(dto.Properties.ServiceUrl)
322320
? dto with { Properties = dto.Properties with { ServiceUrl = null } }
323321
: dto;

src/common/Resource.Http.cs

Lines changed: 37 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -3,12 +3,14 @@
33
using Flurl;
44
using Microsoft.Extensions.DependencyInjection;
55
using Microsoft.Extensions.Hosting;
6+
using OpenTelemetry.Resources;
67
using System;
78
using System.Collections.Concurrent;
89
using System.Collections.Generic;
910
using System.Linq;
1011
using System.Net;
1112
using System.Net.Http;
13+
using System.Runtime.InteropServices.JavaScript;
1214
using System.Text.Json;
1315
using System.Text.Json.Nodes;
1416
using System.Threading;
@@ -136,17 +138,44 @@ private static ListResourceDtosFromApim ResolveListResourceDtosFromApim(IService
136138
{
137139
case IPolicyResource policyResource:
138140
return policyResource.ListDtosFromApim(parents, listNames, getDto, cancellationToken);
141+
case var _ when isWorkspaceResource(parents):
142+
return getWorkspaceResourceDtos(resource, parents, cancellationToken);
139143
default:
140-
var uri = resource.GetCollectionUri(parents, serviceUri);
141-
142-
return pipeline.ListJsonObjects(uri, cancellationToken)
143-
.Select(jsonObject => from name in jsonObject.GetStringProperty("name")
144-
from resourceName in ResourceName.From(name)
145-
from normalizedDto in resource.DeserializeToDtoJson(jsonObject)
146-
select (resourceName, normalizedDto))
147-
.Select(result => result.IfErrorThrow());
144+
return getNonWorkspaceResourceDtos(resource, parents, cancellationToken);
148145
}
149146
};
147+
148+
bool isWorkspaceResource(ParentChain parents) =>
149+
parents.Any(parent => parent.Resource is WorkspaceResource);
150+
151+
// The APIM REST API is buggy for some workspace-scoped resources.
152+
// If the resource is workspace-scoped, we fetch its DTO individually
153+
// rather than relying on the "list-all" response.
154+
IAsyncEnumerable<(ResourceName, JsonObject)> getWorkspaceResourceDtos(IResourceWithDto resource, ParentChain parents, CancellationToken cancellationToken)
155+
{
156+
var uri = resource.GetCollectionUri(parents, serviceUri);
157+
158+
return pipeline.ListJsonObjects(uri, cancellationToken)
159+
.Select(jsonObject => from nameString in jsonObject.GetStringProperty("name")
160+
from name in ResourceName.From(nameString)
161+
select name)
162+
.Select(nameResult => nameResult.IfErrorThrow())
163+
.Select(async (name, cancellationToken) => from dto in await resource.GetDtoFromApim(name, parents, serviceUri, pipeline, cancellationToken)
164+
select (name, dto))
165+
.Select(result => result.IfErrorThrow());
166+
}
167+
168+
IAsyncEnumerable<(ResourceName, JsonObject)> getNonWorkspaceResourceDtos(IResourceWithDto resource, ParentChain parents, CancellationToken cancellationToken)
169+
{
170+
var uri = resource.GetCollectionUri(parents, serviceUri);
171+
172+
return pipeline.ListJsonObjects(uri, cancellationToken)
173+
.Select(jsonObject => from nameString in jsonObject.GetStringProperty("name")
174+
from name in ResourceName.From(nameString)
175+
from dto in resource.DeserializeToDtoJson(jsonObject)
176+
select (name, dto))
177+
.Select(result => result.IfErrorThrow());
178+
}
150179
}
151180

152181
/// <summary>

src/publisher/Relationships.cs

Lines changed: 0 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,8 +1,6 @@
1-
using Azure;
21
using common;
32
using Microsoft.Extensions.DependencyInjection;
43
using Microsoft.Extensions.Hosting;
5-
using OpenTelemetry.Resources;
64
using System;
75
using System.Collections.Concurrent;
86
using System.Collections.Generic;

0 commit comments

Comments
 (0)