Skip to content

Commit 8af6ebd

Browse files
committed
Whoops, stack overflowgit add -A
1 parent 6946e06 commit 8af6ebd

File tree

3 files changed

+23
-8
lines changed

3 files changed

+23
-8
lines changed
Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,4 @@
11
using Aspire.Hosting.ApplicationModel;
22

33
namespace CommunityToolkit.Aspire.Hosting.Dapr;
4-
internal sealed record DaprComponentConfigurationAnnotation(Action<DaprComponentSchema> Configure) : IResourceAnnotation;
4+
internal sealed record DaprComponentConfigurationAnnotation(Func<DaprComponentSchema, Task> Configure) : IResourceAnnotation;

src/Shared/Dapr/Core/DaprDistributedApplicationLifecycleHook.cs

Lines changed: 7 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -12,6 +12,7 @@
1212
using System.Diagnostics.CodeAnalysis;
1313
using System.Globalization;
1414
using System.Net.Sockets;
15+
using System.Threading.Tasks;
1516
using static CommunityToolkit.Aspire.Hosting.Dapr.CommandLineArgs;
1617

1718
namespace CommunityToolkit.Aspire.Hosting.Dapr;
@@ -491,7 +492,7 @@ private async Task<string> GetComponentAsync(DaprComponentResource component, Fu
491492
{
492493
// We should try to read content from a known location (such as aspire root directory)
493494
logger.LogInformation("Unvalidated configuration {specType} for component '{ComponentName}'.", component.Type, component.Name);
494-
return await contentWriter(GetDaprComponent(component, component.Type)).ConfigureAwait(false);
495+
return await contentWriter(await GetDaprComponent(component, component.Type)).ConfigureAwait(false);
495496
}
496497
private async Task<string> GetBuildingBlockComponentAsync(DaprComponentResource component, Func<string, Task<string>> contentWriter, string defaultProvider, CancellationToken cancellationToken)
497498
{
@@ -544,19 +545,19 @@ private static async Task<string> GetDefaultContent(DaprComponentResource compon
544545
string defaultContent = await File.ReadAllTextAsync(defaultContentPath, cancellationToken).ConfigureAwait(false);
545546
string yaml = defaultContent.Replace($"name: {component.Type}", $"name: {component.Name}");
546547
DaprComponentSchema content = DaprComponentSchema.FromYaml(yaml);
547-
ConfigureDaprComponent(component, content);
548+
await ConfigureDaprComponent(component, content);
548549
return content.ToString();
549550
}
550551

551552

552-
private static string GetDaprComponent(DaprComponentResource component, string type)
553+
private static async Task<string> GetDaprComponent(DaprComponentResource component, string type)
553554
{
554555
var content = new DaprComponentSchema(component.Name, type);
555-
ConfigureDaprComponent(component, content);
556+
await ConfigureDaprComponent(component, content);
556557
return content.ToString();
557558
}
558559

559-
private static void ConfigureDaprComponent(DaprComponentResource component, DaprComponentSchema content)
560+
private static async Task ConfigureDaprComponent(DaprComponentResource component, DaprComponentSchema content)
560561
{
561562
if (component.TryGetAnnotationsOfType<DaprComponentSecretAnnotation>(out var secrets) && secrets.Any())
562563
{
@@ -566,7 +567,7 @@ private static void ConfigureDaprComponent(DaprComponentResource component, Dapr
566567
{
567568
foreach (var annotation in annotations)
568569
{
569-
annotation.Configure(content);
570+
await annotation.Configure(content);
570571
}
571572
}
572573
}

src/Shared/Dapr/Core/DaprMetadataResourceBuilderExtensions.cs

Lines changed: 15 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -28,6 +28,7 @@ public static IResourceBuilder<IDaprComponentResource> WithMetadata(this IResour
2828
Name = name,
2929
Value = value
3030
});
31+
return Task.CompletedTask;
3132
}));
3233

3334

@@ -59,9 +60,22 @@ public static IResourceBuilder<IDaprComponentResource> WithMetadata(this IResour
5960
Key = parameterResource.Name
6061
}
6162
});
63+
return Task.CompletedTask;
6264
}));
6365
}
6466

65-
return builder.WithMetadata(name, parameterResource);
67+
return builder.WithAnnotation(new DaprComponentConfigurationAnnotation(async schema =>
68+
{
69+
var existing = schema.Spec.Metadata.Find(m => m.Name == name);
70+
if (existing is not null)
71+
{
72+
schema.Spec.Metadata.Remove(existing);
73+
}
74+
schema.Spec.Metadata.Add(new DaprComponentSpecMetadataValue
75+
{
76+
Name = name,
77+
Value = (await ((IValueProvider)parameterResource).GetValueAsync(default))!
78+
});
79+
}));
6680
}
6781
}

0 commit comments

Comments
 (0)