-
Notifications
You must be signed in to change notification settings - Fork 63
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Dapr component schema #460
base: main
Are you sure you want to change the base?
Changes from 2 commits
b518dff
941569a
8ac830c
fa694c8
8c3c081
accb128
148b588
eb57614
6d325a2
33fea9b
8ab51c1
d786a01
767385e
225a2bf
9055248
3bba6ee
1b683fa
38eded5
File filter
Filter by extension
Conversations
Jump to
Diff view
Diff view
There are no files selected for viewing
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -14,4 +14,4 @@ spec: | |
- name: username | ||
value: guest | ||
- name: password | ||
value: guest | ||
value: guest |
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -5,18 +5,23 @@ | |
.WithEndpoint("tcp", e => e.Port = 5672) | ||
.WithEndpoint("management", e => e.Port = 15672); | ||
|
||
|
||
var stateStore = builder.AddDaprStateStore("statestore"); | ||
|
||
var pubSub = builder.AddDaprPubSub("pubsub") | ||
.WithMetadata("password", rmq.Resource.PasswordParameter) | ||
FullStackChef marked this conversation as resolved.
Show resolved
Hide resolved
|
||
.WaitFor(rmq); | ||
|
||
builder.AddProject<Projects.CommunityToolkit_Aspire_Hosting_Dapr_ServiceA>("servicea") | ||
.WithDaprSidecar() | ||
.WithReference(stateStore) | ||
.WithReference(pubSub); | ||
.WithReference(pubSub) | ||
.WithDaprSidecar() | ||
.WaitFor(rmq); | ||
|
||
builder.AddProject<Projects.CommunityToolkit_Aspire_Hosting_Dapr_ServiceB>("serviceb") | ||
.WithReference(pubSub) | ||
.WithDaprSidecar() | ||
Comment on lines
+19
to
20
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. From a developer standpoint I would more expect something like: .WithDaprSidecar()
.WithReference(pubSub) Because you configure the sidecare to use the pubSub reference as a pubsub. Not the project. You can look for the AzurePostgreSql resource of aspire how you can configure the development contianer. I would prefer an API like their There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. To prevent breaking changes for now closing this comment. There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. this is up to the developer the both work the same |
||
.WithReference(pubSub); | ||
.WaitFor(rmq); | ||
|
||
// console app with no appPort (sender only) | ||
builder.AddProject<Projects.CommunityToolkit_Aspire_Hosting_Dapr_ServiceC>("servicec") | ||
|
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,4 @@ | ||
using Aspire.Hosting.ApplicationModel; | ||
|
||
namespace CommunityToolkit.Aspire.Hosting.Dapr; | ||
internal sealed record DaprComponentConfigurationAnnotation(Action<DaprComponentSchema> Configure) : IResourceAnnotation; |
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,138 @@ | ||
using YamlDotNet.Serialization; | ||
using YamlDotNet.Serialization.NamingConventions; | ||
|
||
namespace CommunityToolkit.Aspire.Hosting.Dapr; | ||
|
||
internal interface IDaprComponentSpecMetadata : IList<DaprComponentSpecMetadata>; | ||
|
||
internal class DaprComponentSchema | ||
{ | ||
internal static readonly ISerializer serializer = BuildSerializer(); | ||
internal static readonly IDeserializer deserializer = BuildDeSerializer(); | ||
|
||
public string ApiVersion { get; init; } = "dapr.io/v1alpha1"; | ||
public string Kind { get; init; } = "Component"; | ||
public DaprComponentAuth? Auth { get; set; } | ||
public DaprComponentMetadata Metadata { get; init; } = default!; | ||
public DaprComponentSpec Spec { get; init; } = default!; | ||
|
||
// Required for deserialization | ||
public DaprComponentSchema() { } | ||
|
||
public DaprComponentSchema(string name, string type) | ||
{ | ||
Metadata = new DaprComponentMetadata { Name = name }; | ||
Spec = new DaprComponentSpec | ||
{ | ||
Type = type, | ||
Metadata = [] | ||
}; | ||
} | ||
public override string ToString() | ||
{ | ||
return serializer.Serialize(this); | ||
} | ||
public static implicit operator DaprComponentSchema(string yamlContent) | ||
{ | ||
return deserializer.Deserialize<DaprComponentSchema>(yamlContent); | ||
} | ||
davidfowl marked this conversation as resolved.
Show resolved
Hide resolved
|
||
private static IDeserializer BuildDeSerializer() | ||
{ | ||
DeserializerBuilder builder = new(); | ||
builder.WithNamingConvention(CamelCaseNamingConvention.Instance) | ||
.WithTypeDiscriminatingNodeDeserializer(static o => | ||
{ | ||
Dictionary<string, Type> keyMappings = new() | ||
{ | ||
["value"] = typeof(DaprComponentSpecMetadataValue), | ||
["secretKeyRef"] = typeof(DaprComponentSpecMetadataSecret) | ||
}; | ||
o.AddUniqueKeyTypeDiscriminator<DaprComponentSpecMetadata>(keyMappings); | ||
}); | ||
return builder.Build(); | ||
} | ||
|
||
private static ISerializer BuildSerializer() | ||
{ | ||
SerializerBuilder builder = new(); | ||
builder.WithNamingConvention(CamelCaseNamingConvention.Instance) | ||
.ConfigureDefaultValuesHandling(DefaultValuesHandling.OmitDefaults); | ||
return builder.Build(); | ||
} | ||
|
||
} | ||
internal class DaprComponentMetadata | ||
{ | ||
public required string Name { get; init; } | ||
public string? Namespace { get; init; } | ||
|
||
} | ||
|
||
internal class DaprComponentAuth | ||
{ | ||
public required string SecretStore { get; init; } | ||
} | ||
|
||
internal class GenericDaprComponentSpecMetadata : List<DaprComponentSpecMetadata>, IDaprComponentSpecMetadata; | ||
|
||
internal class DaprComponentSpec : DaprComponentSpec<GenericDaprComponentSpecMetadata> { } | ||
|
||
internal class DaprComponentSpec<TSpecMetadata> where TSpecMetadata : IDaprComponentSpecMetadata | ||
{ | ||
public required string Type { get; init; } | ||
public string Version { get; init; } = "v1"; | ||
public required TSpecMetadata Metadata { get; init; } | ||
} | ||
|
||
/// <summary> | ||
/// Represents a Dapr component spec metadata item | ||
/// </summary> | ||
public abstract class DaprComponentSpecMetadata | ||
{ | ||
/// <summary> | ||
/// The name of the metadata item | ||
/// </summary> | ||
[YamlMember(Order = 1)] | ||
public required string Name { get; init; } | ||
} | ||
|
||
/// <summary> | ||
/// Represents a Dapr component spec metadata item with a value | ||
/// </summary> | ||
public sealed class DaprComponentSpecMetadataValue : DaprComponentSpecMetadata | ||
{ | ||
/// <summary> | ||
/// The value of the metadata item | ||
/// </summary> | ||
[YamlMember(Order = 2)] | ||
public required string Value { get; set; } | ||
} | ||
|
||
/// <summary> | ||
/// Represents a Dapr component spec metadata item with a secret key reference | ||
/// </summary> | ||
public sealed class DaprComponentSpecMetadataSecret : DaprComponentSpecMetadata | ||
{ | ||
/// <summary> | ||
/// The secret key reference of the metadata item | ||
/// </summary> | ||
[YamlMember(Order = 2)] | ||
public required DaprSecretKeyRef SecretKeyRef { get; set; } | ||
|
||
} | ||
|
||
/// <summary> | ||
/// Represents a Dapr secret key reference | ||
/// </summary> | ||
public sealed class DaprSecretKeyRef | ||
{ | ||
/// <summary> | ||
/// The name of the secret | ||
/// </summary> | ||
public required string Name { get; init; } = default!; | ||
davidfowl marked this conversation as resolved.
Show resolved
Hide resolved
|
||
/// <summary> | ||
/// The key of the secret | ||
/// </summary> | ||
public required string Key { get; init; } = default!; | ||
}; | ||
|
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,4 @@ | ||
using Aspire.Hosting.ApplicationModel; | ||
|
||
namespace CommunityToolkit.Aspire.Hosting.Dapr; | ||
internal record DaprComponentSecretAnnotation(string Key, string Value) : IResourceAnnotation; | ||
FullStackChef marked this conversation as resolved.
Show resolved
Hide resolved
|
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Do we need this file still? I don't see the reference of it in the sample
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
this file is used by this line of the apphost
this is not new - it's simply in a project relative location