-
Notifications
You must be signed in to change notification settings - Fork 2.4k
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
Added BlobFileStoreFactory to allow DefaultAzureCredential or Connectionstring authentication for Azure Blob storage #12874
Conversation
This allows to use registered clients from Azure.Configuration.Extensions (and DefaultAzureCredential )or specify a connectionstring
…es collection and not on each tenant.
using Microsoft.Extensions.DependencyInjection; | ||
using OrchardCore.Modules; | ||
|
||
namespace OrchardCore.FileStorage.AzureBlob; |
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.
Add new line after the namespace.
private readonly IAzureClientFactory<BlobServiceClient> _clientFactory; | ||
private readonly IServiceProvider _serviceProvider; | ||
|
||
private const string DefaultStorageName = "Default"; |
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.
rename the variable to _defaultStorageName
|
||
private BlobContainerClient CreateContainerClientFromOptions(BlobStorageOptions options) | ||
{ | ||
// return a container client from connectionstring, if specified |
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.
// return a container client from connectionstring, if specified | |
// Create a container using the specified connection string. |
return new BlobContainerClient(options.ConnectionString, options.ContainerName); | ||
} | ||
|
||
// else use the clientFactory to lookup a BlobService with the specified name |
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.
// else use the clientFactory to lookup a BlobService with the specified name | |
// Create a container using the specified Blob service. |
.GetBlobContainerClient(options.ContainerName); | ||
} | ||
|
||
// fall-back to the default registered blob storage |
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.
// fall-back to the default registered blob storage | |
// Create a container using the Default client. |
@@ -24,6 +24,9 @@ public static OrchardCoreBuilder AddAzureShellsConfiguration(this OrchardCoreBui | |||
|
|||
services.TryAddSingleton<IContentTypeProvider, FileExtensionContentTypeProvider>(); | |||
|
|||
// register the azure blob file storage services |
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 would just remove this comment.
// always use TryXXX methods because this method can be called multiple times | ||
// by different modules (currently: Azure Media and Azure Shells module) | ||
services.TryAddSingleton<BlobFileStoreFactory>(); | ||
return services; |
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.
New line before return
Then either remove the comment or change the comment block to something like this
// TryAddSingleton is used to prevent registering the service again.
{ | ||
/// <summary> | ||
/// Registers the BlobFileStorage services in the ServiceCollection. | ||
/// Note: this method can be called multiple times |
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 would remove the comments here.
/// <returns></returns> | ||
public static OrchardCoreBuilder AddAzureBlobFileStorage(this OrchardCoreBuilder builder) | ||
{ | ||
builder.ApplicationServices.AddAzureBlobFileStorage(); |
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.
new line before return.
@@ -95,22 +95,22 @@ public override void ConfigureServices(IServiceCollection services) | |||
services.AddSingleton<IMediaFileStoreCache>(serviceProvider => | |||
serviceProvider.GetRequiredService<IMediaFileStoreCacheFileProvider>()); | |||
|
|||
// Register the BlobFileStorageFactory |
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.
Comment isn't needed here
Additionally, please
|
It looks like the trail has gone cold on this. Just commenting to say that I'm looking for a way to use Azure Managed Identity for |
This pull request has merge conflicts. Please resolve those before requesting a review. |
Is this something you'd like to revisit any time soon @rikbosch or should we close? |
Would you like to perhaps take over this, @mariojsnunes? |
Yes, I'll look into it towards the end of the week |
Superseded by #15753. |
Fixes #12639
This PR introduces a
BlobFileStoreFactory
which is used by theOrchardCore.Shells.Azure
andOrchardCore.Media.Azure
module.It allows to specify a reference to a configured
BlobServiceClient
through the Microsoft.Extensions.Azure nuget package.see https://learn.microsoft.com/en-us/dotnet/azure/sdk/dependency-injection#configure-multiple-service-clients-with-different-names about configuring multiple blob clients and also: https://devblogs.microsoft.com/azure-sdk/best-practices-for-using-azure-sdk-with-asp-net-core/ for best-practices
for example:
program.cs
appsettings.json