Skip to content

Commit a1018db

Browse files
Add additional constructor to allow configuration using managed identities
1 parent 7ca48b5 commit a1018db

File tree

2 files changed

+36
-17
lines changed

2 files changed

+36
-17
lines changed

.editorconfig

Lines changed: 4 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -27,11 +27,13 @@ indent_size = 2
2727
dotnet_style_predefined_type_for_locals_parameters_members = true:error
2828

2929
dotnet_naming_rule.private_members_with_underscore.symbols = private_fields
30-
dotnet_naming_rule.private_members_with_underscore.style = prefix_underscore
30+
dotnet_naming_rule.private_members_with_underscore.style = prefix_underscore
3131
dotnet_naming_rule.private_members_with_underscore.severity = suggestion
3232

33-
dotnet_naming_symbols.private_fields.applicable_kinds = field
33+
dotnet_naming_symbols.private_fields.applicable_kinds = field
3434
dotnet_naming_symbols.private_fields.applicable_accessibilities = private
3535

3636
dotnet_naming_style.prefix_underscore.capitalization = camel_case
3737
dotnet_naming_style.prefix_underscore.required_prefix = _
38+
39+
dotnet_diagnostic.CA1054.severity = suggestion

src/Umbraco.StorageProviders.AzureBlob/IO/AzureBlobFileSystem.cs

Lines changed: 32 additions & 15 deletions
Original file line numberDiff line numberDiff line change
@@ -18,34 +18,51 @@ namespace Umbraco.StorageProviders.AzureBlob.IO
1818
/// <inheritdoc />
1919
public class AzureBlobFileSystem : IAzureBlobFileSystem, IFileProviderFactory
2020
{
21-
private readonly BlobContainerClient _container;
22-
private readonly IContentTypeProvider _contentTypeProvider;
23-
private readonly IIOHelper _ioHelper;
2421
private readonly string _rootUrl;
2522
private readonly string _containerRootPath;
23+
private readonly BlobContainerClient _container;
24+
private readonly IIOHelper _ioHelper;
25+
private readonly IContentTypeProvider _contentTypeProvider;
2626

2727
/// <summary>
28-
/// Creates a new instance of <see cref="AzureBlobFileSystem" />.
28+
/// Creates a new instance of <see cref="AzureBlobFileSystem" />.
2929
/// </summary>
30-
/// <param name="options"></param>
31-
/// <param name="hostingEnvironment"></param>
32-
/// <param name="ioHelper"></param>
33-
/// <param name="contentTypeProvider"></param>
34-
/// <exception cref="ArgumentNullException"></exception>
35-
public AzureBlobFileSystem(AzureBlobFileSystemOptions options, IHostingEnvironment hostingEnvironment,
36-
IIOHelper ioHelper, IContentTypeProvider contentTypeProvider)
30+
/// <param name="options">The options.</param>
31+
/// <param name="hostingEnvironment">The hosting environment.</param>
32+
/// <param name="ioHelper">The I/O helper.</param>
33+
/// <param name="contentTypeProvider">The content type provider.</param>
34+
public AzureBlobFileSystem(AzureBlobFileSystemOptions options, IHostingEnvironment hostingEnvironment, IIOHelper ioHelper, IContentTypeProvider contentTypeProvider)
3735
{
3836
if (options == null) throw new ArgumentNullException(nameof(options));
3937
if (hostingEnvironment == null) throw new ArgumentNullException(nameof(hostingEnvironment));
4038

39+
_rootUrl = EnsureUrlSeparatorChar(hostingEnvironment.ToAbsolute(options.VirtualPath)).TrimEnd('/');
40+
_containerRootPath = options.ContainerRootPath ?? _rootUrl;
41+
_container = new BlobContainerClient(options.ConnectionString, options.ContainerName);
4142
_ioHelper = ioHelper ?? throw new ArgumentNullException(nameof(ioHelper));
4243
_contentTypeProvider = contentTypeProvider ?? throw new ArgumentNullException(nameof(contentTypeProvider));
44+
}
4345

44-
_rootUrl = EnsureUrlSeparatorChar(hostingEnvironment.ToAbsolute(options.VirtualPath)).TrimEnd('/');
45-
_containerRootPath = options.ContainerRootPath ?? _rootUrl;
46+
/// <summary>
47+
/// Creates a new instance of <see cref="AzureBlobFileSystem" />.
48+
/// </summary>
49+
/// <param name="rootUrl">The root URL.</param>
50+
/// <param name="blobContainerClient">The blob container client.</param>
51+
/// <param name="ioHelper">The I/O helper.</param>
52+
/// <param name="contentTypeProvider">The content type provider.</param>
53+
/// <param name="containerRootPath">The container root path (uses the root URL if not set).</param>
54+
public AzureBlobFileSystem(string rootUrl, BlobContainerClient blobContainerClient, IIOHelper ioHelper, IContentTypeProvider contentTypeProvider, string? containerRootPath = null)
55+
{
56+
if (rootUrl is null)
57+
{
58+
throw new ArgumentNullException(nameof(rootUrl));
59+
}
4660

47-
var client = new BlobServiceClient(options.ConnectionString);
48-
_container = client.GetBlobContainerClient(options.ContainerName);
61+
_rootUrl = EnsureUrlSeparatorChar(rootUrl).TrimEnd('/');
62+
_containerRootPath = containerRootPath ?? _rootUrl;
63+
_container = blobContainerClient ?? throw new ArgumentNullException(nameof(blobContainerClient));
64+
_ioHelper = ioHelper ?? throw new ArgumentNullException(nameof(ioHelper));
65+
_contentTypeProvider = contentTypeProvider ?? throw new ArgumentNullException(nameof(contentTypeProvider));
4966
}
5067

5168
/// <inheritdoc />

0 commit comments

Comments
 (0)