Skip to content

Commit fcbcf1d

Browse files
author
Guy Fankam
committed
Addresses #797
1 parent 0eea0c1 commit fcbcf1d

1 file changed

Lines changed: 36 additions & 6 deletions

File tree

src/publisher/Relationships.cs

Lines changed: 36 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -255,11 +255,11 @@ await resources.Values
255255
pairs.Add((parent, key));
256256
}
257257

258-
// Get DTO from information file resources
259-
var dtoOption = Option<JsonObject>.None();
258+
// Get DTO JSON from information file resources
259+
var dtoJsonOption = Option<JsonObject>.None();
260260
if (key.Resource is IResourceWithInformationFile resourceWithInformationFile)
261261
{
262-
dtoOption = await getDto(resourceWithInformationFile, key.Name, key.Parents, operations.ReadFile, operations.GetSubDirectories, cancellationToken);
262+
dtoJsonOption = await getDto(resourceWithInformationFile, key.Name, key.Parents, operations.ReadFile, operations.GetSubDirectories, cancellationToken);
263263
}
264264

265265
// Process composite resources
@@ -268,7 +268,7 @@ await resources.Values
268268
var primary = getPrimary(compositeResource, key.Name, key.Parents);
269269
pairs.Add((primary, key));
270270

271-
var dto = dtoOption.IfNone(() => throw new InvalidOperationException($"Could not get DTO for resource '{key}'."));
271+
var dto = dtoJsonOption.IfNone(() => throw new InvalidOperationException($"Could not get DTO for resource '{key}'."));
272272

273273
var secondary = getSecondary(compositeResource, key.Name, key.Parents, dto)
274274
.IfNone(() => throw new InvalidOperationException($"Could not get secondary resource for composite resource '{key}'."));
@@ -278,7 +278,7 @@ await resources.Values
278278
// Process resources with references
279279
if (key.Resource is IResourceWithReference resourceWithReference)
280280
{
281-
var dto = dtoOption.IfNone(() => throw new InvalidOperationException($"Could not get DTO for resource '{key}'."));
281+
var dto = dtoJsonOption.IfNone(() => throw new InvalidOperationException($"Could not get DTO for resource '{key}'."));
282282

283283
getReferences(resourceWithReference, key.Name, key.Parents, dto, cancellationToken)
284284
.Iter(reference => pairs.Add((reference, key)));
@@ -303,7 +303,7 @@ from workspaceNamedValue in
303303
workspaceNamedValues.Head(key => key.Parents.Any(parent => parent == workspace)
304304
&& key.Name == namedValueName)
305305
select workspaceNamedValue)
306-
// If not found, look for a service-level named value
306+
// If not found, look for a service-level named value
307307
.IfNone(() => from namedValues in resources.Find(NamedValueResource.Instance)
308308
from namedValue in
309309
namedValues.Head(key => key.Name == namedValueName)
@@ -312,6 +312,36 @@ from namedValue in
312312
});
313313
}
314314

315+
// Process backend pools for individual backend references
316+
if (key.Resource is BackendResource backendResource)
317+
{
318+
var parents = key.Parents;
319+
var serializerOptions = ((IResourceWithDto)backendResource).SerializerOptions;
320+
321+
dtoJsonOption.Bind(json => JsonNodeModule.To<BackendDto>(json, serializerOptions)
322+
.ToOption())
323+
// Get pool backends
324+
.Map(dto => dto.Properties.Pool?.Services ?? [])
325+
.IfNone(() => [])
326+
// Get backend names from their IDs
327+
.Choose(backend =>
328+
{
329+
var nameString = backend.Id?.Split('/').LastOrDefault() ?? string.Empty;
330+
331+
return ResourceName.From(nameString)
332+
.ToOption();
333+
})
334+
// Create resource keys for each backend
335+
.Select(backendName => new ResourceKey
336+
{
337+
Resource = backendResource,
338+
Name = backendName,
339+
Parents = parents
340+
})
341+
// Pair backends with the pool
342+
.Iter(backendPredecessor => pairs.Add((backendPredecessor, key)), cancellationToken);
343+
}
344+
315345
// Process non-root API revisions
316346
if (key.Resource is ApiResource)
317347
{

0 commit comments

Comments
 (0)