-
Notifications
You must be signed in to change notification settings - Fork 686
Fix Blob Container Connection String Format Exception #9472
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
Conversation
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.
Pull Request Overview
This PR fixes how AzureBlobStorageContainerSettings
distinguishes between a service URI and an emulator connection string when parsing, ensuring the correct client constructor is used.
- Introduce
ParseConnectionStringInternal
to centralize parsing logic. - Update
AzureBlobStorageContainerSettings
to call the internal parser on the endpoint value. - Add unit tests covering service URI, emulator connection string, and invalid URI scenarios.
Reviewed Changes
Copilot reviewed 4 out of 4 changed files in this pull request and generated 1 comment.
File | Description |
---|---|
tests/Aspire.Azure.Storage.Blobs.Tests/AzureBlobStorageContainerSettingsTests.cs | Added tests for parsing service URI, emulator connection string, and non-URI endpoints. |
src/Components/Aspire.Azure.Storage.Blobs/AzureStorageBlobsSettings.cs | Exposed ParseConnectionStringInternal and hooked up the interface implementation. |
src/Components/Aspire.Azure.Storage.Blobs/AzureBlobStorageContainerSettings.cs | Changed logic to call ParseConnectionStringInternal instead of assigning directly to ConnectionString . |
playground/AzureStorageEndToEnd/AzureStorageEndToEnd.AppHost/Program.cs | Commented-out RunAsEmulator calls in example host to reflect new defaults. |
Comments suppressed due to low confidence (2)
src/Components/Aspire.Azure.Storage.Blobs/AzureBlobStorageContainerSettings.cs:29
- [nitpick] The constant 'ContainerName' is shadowing the property name and can be confusing; consider renaming it to 'ContainerNameKey' or similar to clarify its purpose.
const string ContainerName = nameof(ContainerName);
tests/Aspire.Azure.Storage.Blobs.Tests/AzureBlobStorageContainerSettingsTests.cs:49
- Add an assertion that
settings.ConnectionString
is null when a service URI is provided to ensure onlyServiceUri
is set andConnectionString
remains unset.
public void ParseConnectionString_With_ServiceUri(string connectionString)
playground/AzureStorageEndToEnd/AzureStorageEndToEnd.AppHost/Program.cs
Outdated
Show resolved
Hide resolved
src/Components/Aspire.Azure.Storage.Blobs/AzureBlobStorageContainerSettings.cs
Outdated
Show resolved
Hide resolved
else | ||
{ | ||
builder.Append($"Endpoint={ConnectionStringExpression}"); | ||
} | ||
|
||
if (!string.IsNullOrEmpty(blobContainerName)) |
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 can be removed cuz it is already checked above.
@@ -231,10 +231,11 @@ public async Task AddBlobContainer_ConnectionString_resolved_expected_RunAsEmula | |||
var blobs = storage.AddBlobs("blob"); |
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 we also update this test to verify blob containers work end-to-end?
aspire/tests/Aspire.Hosting.Azure.Tests/AzureStorageEmulatorFunctionalTests.cs
Lines 109 to 134 in 69143ae
[Fact] | |
[RequiresDocker] | |
public async Task VerifyAzureStorageEmulatorResource() | |
{ | |
using var builder = TestDistributedApplicationBuilder.Create().WithTestAndResourceLogging(testOutputHelper); | |
var storage = builder.AddAzureStorage("storage").RunAsEmulator().AddBlobs("BlobConnection"); | |
using var app = builder.Build(); | |
await app.StartAsync(); | |
var hb = Host.CreateApplicationBuilder(); | |
hb.Configuration["ConnectionStrings:BlobConnection"] = await storage.Resource.ConnectionStringExpression.GetValueAsync(CancellationToken.None); | |
hb.AddAzureBlobClient("BlobConnection"); | |
using var host = hb.Build(); | |
await host.StartAsync(); | |
var serviceClient = host.Services.GetRequiredService<BlobServiceClient>(); | |
var blobContainer = (await serviceClient.CreateBlobContainerAsync("container")).Value; | |
var blobClient = blobContainer.GetBlobClient("testKey"); | |
await blobClient.UploadAsync(BinaryData.FromString("testValue")); | |
var downloadResult = (await blobClient.DownloadContentAsync()).Value; | |
Assert.Equal("testValue", downloadResult.Content.ToString()); | |
} |
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 don't understand, update AddBlobContainer_ConnectionString_resolved_expected_RunAsEmulator
or VerifyAzureStorageEmulatorResource
. The first one is a unit test, the second is already testing the container client with the emulator.
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.
Update the VerifyAzureStorageEmulatorResource
functional e2e test to also ensure that Hosting builder.AddBlobContainer("container");
and Client side builder.AddAzureBlobContainerClient("container");
work together end-to-end.
/backport to release/9.3 |
Started backporting to release/9.3: https://github.com/dotnet/aspire/actions/runs/15220833760 |
Description
The
AzureBlobStorageContainerSettings
specialized class is preventing the distinction betweenConnectionString
andServiceUri
from happening. In the case of Azure deployment it would then assign a service uri to theConnectionString
property and the wrong client constructor was invoked.Fixes #9454
Checklist
<remarks />
and<code />
elements on your triple slash comments?doc-idea
templatebreaking-change
templatediagnostic
template