-
Notifications
You must be signed in to change notification settings - Fork 531
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
Fix Azure ServiceBus persistent container support #7136
base: main
Are you sure you want to change the base?
Conversation
src/Aspire.Hosting.Azure.ServiceBus/AzureServiceBusExtensions.cs
Outdated
Show resolved
Hide resolved
var configHostFile = Path.Combine(Directory.CreateTempSubdirectory("AspireServiceBusEmulator").FullName, "Config.json"); | ||
|
||
if (lifetime == ContainerLifetime.Persistent && builder.ApplicationBuilder.ExecutionContext.IsRunMode && builder.ApplicationBuilder.AppHostAssembly is not null) |
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.
I wonder if we can centralize this logic.
/azp run |
Azure Pipelines successfully started running 1 pipeline(s). |
AddAzureServiceBusWithEmulatorGetsExpectedPort - actual failing test |
var lifetime = ContainerLifetime.Session; | ||
|
||
// Create a default file mount. This could be replaced by a user-provided file mount. | ||
var configHostFile = Path.Combine(Directory.CreateTempSubdirectory("AspireServiceBusEmulator").FullName, "Config.json"); |
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 always want to create the directory up front? In the case where the lifetime of is persistent, we may not want this right?
/// </remarks> | ||
/// <param name="builder">Distributed application builder</param> | ||
/// <param name="name">Name of the parameter</param> | ||
/// <param name="value"></param> |
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.
The value
parameter is a bit odd since it is only used on the first run. After the value is persisted once, calling AddPersistentParameter
again with a different value
is ignored, since it reads it from user secrets.
Maybe calling this initialValue
or similar may help.
/// <param name="name">Name of the parameter</param> | ||
/// <param name="value"></param> | ||
/// <returns>The created <see cref="ParameterResource"/>.</returns> | ||
public static ParameterResource AddPersistentParameter(this IDistributedApplicationBuilder builder, string name, string value) |
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.
What's the difference between this API and AddParameter(..., persist: true)
?
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.
In the end it does the same thing, but you need to use a ParameterDefault
in the existing one and the one we need is private. So it's either making ConstantParameterDefault
public or create a new helper method that uses it (which is what I implemented).
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.
Can this one be built on top of the other one to show that it is the same thing only with different inputs?
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.
Given your current build errors, it kind of shows why this API isn't working very well. You want to pass a ParameterDefault that will generate a temp file when the parameter value isn't already persisted. Basically a callback func that produces the default value when the value isn't already there.
@@ -14,6 +14,7 @@ | |||
|
|||
<ItemGroup> | |||
<Compile Include="$(RepoRoot)src\Aspire.Hosting\Utils\PasswordGenerator.cs" Link="Utils\PasswordGenerator.cs" /> | |||
<Compile Include="$(SharedDir)SecretsStore.cs" Link="Utils\SecretsStore.cs" /> |
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.
Is this still needed?
// Add emulator container | ||
|
||
var password = PasswordGenerator.Generate(16, true, true, true, true, 0, 0, 0, 0); | ||
// The password must be at least 8 characters long and contain characters from three of the following four sets: Uppercase letters, Lowercase letters, Base 10 digits, and Symbols | ||
var passwordParameter = ParameterResourceBuilderExtensions.CreateDefaultPasswordParameter(builder.ApplicationBuilder, $"{builder.Resource.Name}-sqledge-pwd", minLower: 1, minUpper: 1, minNumeric: 1); |
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.
var passwordParameter = ParameterResourceBuilderExtensions.CreateDefaultPasswordParameter(builder.ApplicationBuilder, $"{builder.Resource.Name}-sqledge-pwd", minLower: 1, minUpper: 1, minNumeric: 1); | |
var passwordParameter = ParameterResourceBuilderExtensions.CreateDefaultPasswordParameter(builder.ApplicationBuilder, $"{builder.Resource.Name}-sql-pwd", minLower: 1, minUpper: 1, minNumeric: 1); |
Do we need to explicitly call this "sqledge"? What if we changed it in the future?
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.
What if it's not even sql
in the future ;) Will update.
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.
But the resource is named $"{builder.Resource.Name}-sqledge"
, that's why it's named $"{builder.Resource.Name}-sqledge-pwd"
with the extra -pwd
. If we were to change the type of resource, and the name, we could also use a different one for the password.
Or we can name everything without sqledge
at all.
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.
I think let's drop the edge
in all for sure. I think sql
is fine, but if you want to call it something more generic like -data
I wouldn't object.
ContainerMountType.BindMount, | ||
isReadOnly: true); | ||
|
||
var hasCustomConfigJson = builder.Resource.Annotations.OfType<ContainerMountAnnotation>().Any(v => v.Target == AzureServiceBusEmulatorResource.EmulatorConfigJsonPath); |
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.
Why are we checking this now? We weren't before.
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.
WithConfigurationFile
is removing an existing one. Before this PR the call back would be executed before WithConfigurationFile
so it would keep only one. Now the callback is called after WithConfigurationFile
so it won't have the same effect.
There is a test ensuring a single mount is defined.
src/Aspire.Hosting.Azure.ServiceBus/AzureServiceBusExtensions.cs
Outdated
Show resolved
Hide resolved
src/Shared/AspireStore.cs
Outdated
|
||
namespace Aspire.Hosting.Utils; | ||
|
||
internal sealed class AspireStore : KeyValueStore |
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.
I think we will want to make this API public because any integration (including outside of dotnet/aspire) will want to write to this folder.
src/Shared/SecretsStore.cs
Outdated
@@ -12,83 +11,92 @@ namespace Microsoft.Extensions.SecretManager.Tools.Internal; | |||
/// <summary> | |||
/// Adapted from dotnet user-secrets at https://github.com/dotnet/aspnetcore/blob/482730a4c773ee4b3ae9525186d10999c89b556d/src/Tools/dotnet-user-secrets/src/Internal/SecretsStore.cs | |||
/// </summary> | |||
internal sealed class SecretsStore | |||
internal abstract class KeyValueStore |
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.
I'm not sure we need this abstraction. SecretsStore is just about reading/writing the secrets.json
file. The new Store should be about reading/writing files to the app directory (wherever it is that we decide).
Description
Fixes #7071
Issues identified:
Now the password and the folder are stored in user secrets and reused.
Checklist
<remarks />
and<code />
elements on your triple slash comments?breaking-change
template):doc-idea
template):