-
Notifications
You must be signed in to change notification settings - Fork 2.4k
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
feat: Support azure blob storage auth with managed identity.
- Loading branch information
1 parent
f59edd1
commit daf2e03
Showing
7 changed files
with
61 additions
and
3 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
7 changes: 7 additions & 0 deletions
7
src/OrchardCore/OrchardCore.FileStorage.AzureBlob/BlobAuthenticationType.cs
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,7 @@ | ||
namespace OrchardCore.FileStorage.AzureBlob; | ||
|
||
public enum BlobAuthenticationType | ||
{ | ||
ConnectionString = 0, | ||
ManagedIdentity = 1, | ||
} |
29 changes: 29 additions & 0 deletions
29
src/OrchardCore/OrchardCore.FileStorage.AzureBlob/BlobContainerClientFactory.cs
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,29 @@ | ||
using System; | ||
using Azure.Identity; | ||
using Azure.Storage.Blobs; | ||
|
||
namespace OrchardCore.FileStorage.AzureBlob; | ||
|
||
public class BlobContainerClientFactory | ||
{ | ||
public static BlobContainerClient Create(BlobStorageOptions options) | ||
{ | ||
if (options.AuthenticationType == BlobAuthenticationType.ConnectionString) | ||
{ | ||
return new BlobContainerClient(options.ConnectionString, options.ContainerName); | ||
} | ||
else if (options.AuthenticationType == BlobAuthenticationType.ManagedIdentity && !String.IsNullOrWhiteSpace(options.IdentityClientId)) | ||
{ | ||
return new BlobContainerClient(GetStorageAccountUri(options.StorageAccountName), new ManagedIdentityCredential(options.IdentityClientId)); | ||
} | ||
else | ||
{ | ||
return new BlobContainerClient(GetStorageAccountUri(options.StorageAccountName), new DefaultAzureCredential()); | ||
} | ||
} | ||
|
||
private static Uri GetStorageAccountUri(string storageAccountName) | ||
{ | ||
return new Uri($"https://{storageAccountName}.blob.core.windows.net"); | ||
} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters