Skip to content

Commit 65b293b

Browse files
ssteinerStephan Steiner
andauthored
BlobStorageTarget - Rename config properties to align with Microsoft naming convention (#163)
* renamed configuration properties to be more aligned with the Microsoft naming convention: ResourceIdentity => ManagedIdentityResourceId ClientIdentity => ManagedIdentityClientId ClientId => ClientAuthId ClientSecret => ClientAuthSecret * resolved PR comments --------- Co-authored-by: Stephan Steiner <[email protected]>
1 parent 93e7b6e commit 65b293b

File tree

5 files changed

+59
-46
lines changed

5 files changed

+59
-46
lines changed

src/NLog.Extensions.AzureBlobStorage/BlobStorageTarget.cs

Lines changed: 41 additions & 25 deletions
Original file line numberDiff line numberDiff line change
@@ -30,7 +30,8 @@ public sealed class BlobStorageTarget : AsyncTaskTarget
3030
public Layout ConnectionString { get; set; }
3131

3232
/// <summary>
33-
/// Alternative to ConnectionString
33+
/// Uri to reference the blob service (e.g. https://{account_name}.blob.core.windows.net).
34+
/// Input for <see cref="BlobServiceClient"/>. Required, when <see cref="ConnectionString"/> is not configured. Overrides <see cref="ConnectionString"/> when both are set.
3435
/// </summary>
3536
public Layout ServiceUri { get; set; }
3637

@@ -40,51 +41,66 @@ public sealed class BlobStorageTarget : AsyncTaskTarget
4041

4142
/// <summary>
4243
/// Alternative to ConnectionString, when using <see cref="ServiceUri"/>
44+
/// tenantId for <see cref="Azure.Identity.DefaultAzureCredentialOptions"/> and <see cref="Azure.Identity.ClientSecretCredential"/>. Requires <see cref="ServiceUri"/>.
4345
/// </summary>
4446
public Layout TenantIdentity { get; set; }
4547

48+
[System.ComponentModel.EditorBrowsable(System.ComponentModel.EditorBrowsableState.Never)]
49+
[Obsolete("Instead use ManagedIdentityResourceId")]
50+
public Layout ResourceIdentity { get => ManagedIdentityResourceId; set => ManagedIdentityResourceId = value; }
51+
4652
/// <summary>
47-
/// Alternative to ConnectionString, when using <see cref="ServiceUri"/>.
53+
/// resourceId for <see cref="Azure.Identity.DefaultAzureCredentialOptions.ManagedIdentityResourceId"/> on <see cref="Azure.Identity.DefaultAzureCredentialOptions"/>. Requires <see cref="ServiceUri"/> .
4854
/// </summary>
49-
public Layout ResourceIdentity { get; set; }
55+
public Layout ManagedIdentityResourceId { get; set; }
56+
57+
[System.ComponentModel.EditorBrowsable(System.ComponentModel.EditorBrowsableState.Never)]
58+
[Obsolete("Instead use ManagedIdentityClientId")]
59+
public Layout ClientIdentity { get => ManagedIdentityClientId; set => ManagedIdentityClientId = value; }
5060

5161
/// <summary>
52-
/// Alternative to ConnectionString, when using <see cref="ServiceUri"/> with ManagedIdentityClientId / WorkloadIdentityClientId
62+
/// Sets <see cref="Azure.Identity.DefaultAzureCredentialOptions.ManagedIdentityClientId"/> on <see cref="Azure.Identity.DefaultAzureCredentialOptions"/>. Requires <see cref="ServiceUri"/>.
5363
/// </summary>
54-
public Layout ClientIdentity { get; set; }
64+
public Layout ManagedIdentityClientId { get; set; }
5565

5666
/// <summary>
57-
/// Alternative to ConnectionString, when using <see cref="ServiceUri"/> with AzureSasCredential
67+
/// Access signature for <see cref="Azure.AzureSasCredential"/> authentication. Requires <see cref="ServiceUri"/>.
5868
/// </summary>
5969
public Layout SharedAccessSignature { get; set; }
6070

6171
/// <summary>
62-
/// Alternative to ConnectionString, when using <see cref="ServiceUri"/> with <see cref="Azure.Storage.StorageSharedKeyCredential"/> storage account name.
72+
/// accountName for <see cref="Azure.Storage.StorageSharedKeyCredential"/> authentication. Requires <see cref="ServiceUri"/> and <see cref="AccessKey"/>.
6373
/// </summary>
6474
public Layout AccountName { get; set; }
6575

6676
/// <summary>
67-
/// Alternative to ConnectionString, when using <see cref="ServiceUri"/> with <see cref="Azure.Storage.StorageSharedKeyCredential"/> storage account access-key.
77+
/// accountKey for <see cref="Azure.Storage.StorageSharedKeyCredential"/> authentication. Requires <see cref="ServiceUri"/> and <see cref="AccountName"/>.
6878
/// </summary>
6979
public Layout AccessKey { get; set; }
7080

7181
/// <summary>
72-
/// Alternative to ConnectionString. Instantiates the <see cref="BlobServiceClient"/> using a <see cref="Azure.Identity.ClientSecretCredential"/> with this value as ClientId for authentication. Requires <see cref="TenantIdentity"/> and <see cref="ClientSecret"/> to be set.
82+
/// clientId for <see cref="Azure.Identity.ClientSecretCredential"/> authentication. Requires <see cref="ServiceUri"/>, <see cref="TenantIdentity"/> and <see cref="ClientAuthSecret"/>.
7383
/// </summary>
74-
public Layout ClientId { get; set; }
84+
public Layout ClientAuthId { get; set; }
7585

7686
/// <summary>
77-
/// Secret when using when using <see cref="ClientId"/>. Instantiates the <see cref="BlobServiceClient"/> using a <see cref="Azure.Identity.ClientSecretCredential"/> for authentication. Requires <see cref="TenantIdentity"/> and <see cref="ClientId"/> to be set.
87+
/// clientSecret for <see cref="Azure.Identity.ClientSecretCredential"/> authentication. Requires <see cref="ServiceUri"/>, <see cref="TenantIdentity"/> and <see cref="ClientAuthId"/>.
7888
/// </summary>
79-
public Layout ClientSecret { get; set; }
89+
public Layout ClientAuthSecret { get; set; }
8090

91+
/// <summary>
92+
/// Name of the Blob storage Container
93+
/// </summary>
8194
[RequiredParameter]
8295
public Layout Container { get; set; }
8396

8497
[System.ComponentModel.EditorBrowsable(System.ComponentModel.EditorBrowsableState.Never)]
8598
[Obsolete("Instead use Container")]
8699
public Layout ContainerName { get => Container; set => Container = value; }
87100

101+
/// <summary>
102+
/// name of the Blob Storage Blob
103+
/// </summary>
88104
[RequiredParameter]
89105
public Layout BlobName { get; set; }
90106

@@ -125,13 +141,13 @@ protected override void InitializeTarget()
125141
string connectionString = string.Empty;
126142
string serviceUri = string.Empty;
127143
string tenantIdentity = string.Empty;
128-
string resourceIdentifier = string.Empty;
129-
string clientIdentity = string.Empty;
144+
string managedIdentityResourceId = string.Empty;
145+
string managedIdentityClientId = string.Empty;
130146
string sharedAccessSignature = string.Empty;
131147
string storageAccountName = string.Empty;
132148
string storageAccountAccessKey = string.Empty;
133-
string clientId = string.Empty;
134-
string clientSecret = string.Empty;
149+
string clientAuthId = string.Empty;
150+
string clientAuthSecret = string.Empty;
135151

136152
Dictionary<string, string> blobMetadata = null;
137153
Dictionary<string, string> blobTags = null;
@@ -145,13 +161,13 @@ protected override void InitializeTarget()
145161
{
146162
serviceUri = ServiceUri?.Render(defaultLogEvent);
147163
tenantIdentity = TenantIdentity?.Render(defaultLogEvent);
148-
resourceIdentifier = ResourceIdentity?.Render(defaultLogEvent);
149-
clientIdentity = ClientIdentity?.Render(defaultLogEvent);
164+
managedIdentityResourceId = ManagedIdentityResourceId?.Render(defaultLogEvent);
165+
managedIdentityClientId = ManagedIdentityClientId?.Render(defaultLogEvent);
150166
sharedAccessSignature = SharedAccessSignature?.Render(defaultLogEvent);
151167
storageAccountName = AccountName?.Render(defaultLogEvent);
152168
storageAccountAccessKey = AccessKey?.Render(defaultLogEvent);
153-
clientId = ClientId?.Render(defaultLogEvent);
154-
clientSecret = ClientSecret?.Render(defaultLogEvent);
169+
clientAuthId = ClientAuthId?.Render(defaultLogEvent);
170+
clientAuthSecret = ClientAuthSecret?.Render(defaultLogEvent);
155171
}
156172

157173
if (BlobMetadata?.Count > 0)
@@ -183,7 +199,7 @@ protected override void InitializeTarget()
183199
}
184200
}
185201

186-
_cloudBlobService.Connect(connectionString, serviceUri, tenantIdentity, resourceIdentifier, clientIdentity, sharedAccessSignature, storageAccountName, storageAccountAccessKey, clientId, clientSecret, blobMetadata, blobTags);
202+
_cloudBlobService.Connect(connectionString, serviceUri, tenantIdentity, managedIdentityResourceId, managedIdentityClientId, sharedAccessSignature, storageAccountName, storageAccountAccessKey, clientAuthId, clientAuthSecret, blobMetadata, blobTags);
187203
InternalLogger.Debug("AzureBlobStorageTarget(Name={0}): Initialized", Name);
188204
}
189205
catch (Exception ex)
@@ -390,7 +406,7 @@ class CloudBlobService : ICloudBlobService
390406
private AppendBlobClient _appendBlob;
391407
private BlobContainerClient _container;
392408

393-
public void Connect(string connectionString, string serviceUri, string tenantIdentity, string resourceIdentifier, string clientIdentity, string sharedAccessSignature, string storageAccountName, string storageAccountAccessKey, string clientId, string clientSecret, IDictionary<string, string> blobMetadata, IDictionary<string, string> blobTags)
409+
public void Connect(string connectionString, string serviceUri, string tenantIdentity, string managedIdentityResourceId, string managedIdentityClientId, string sharedAccessSignature, string storageAccountName, string storageAccountAccessKey, string clientAuthId, string clientAuthSecret, IDictionary<string, string> blobMetadata, IDictionary<string, string> blobTags)
394410
{
395411
_blobMetadata = blobMetadata?.Count > 0 ? blobMetadata : null;
396412
_blobTags = blobTags?.Count > 0 ? blobTags : null;
@@ -407,14 +423,14 @@ public void Connect(string connectionString, string serviceUri, string tenantIde
407423
{
408424
_client = new BlobServiceClient(new Uri(serviceUri), new Azure.Storage.StorageSharedKeyCredential(storageAccountName, storageAccountAccessKey));
409425
}
410-
else if (!string.IsNullOrEmpty(clientId) && !string.IsNullOrEmpty(clientSecret) && !string.IsNullOrEmpty(tenantIdentity))
426+
else if (!string.IsNullOrEmpty(clientAuthId) && !string.IsNullOrEmpty(clientAuthSecret) && !string.IsNullOrEmpty(tenantIdentity))
411427
{
412-
var tokenCredentials = new Azure.Identity.ClientSecretCredential(tenantIdentity, clientId, clientSecret);
428+
var tokenCredentials = new Azure.Identity.ClientSecretCredential(tenantIdentity, clientAuthId, clientAuthSecret);
413429
_client = new BlobServiceClient(new Uri(serviceUri), tokenCredentials);
414430
}
415431
else
416432
{
417-
var tokenCredentials = AzureCredentialHelpers.CreateTokenCredentials(clientIdentity, tenantIdentity, resourceIdentifier);
433+
var tokenCredentials = AzureCredentialHelpers.CreateTokenCredentials(managedIdentityClientId, tenantIdentity, managedIdentityResourceId);
418434
_client = new BlobServiceClient(new Uri(serviceUri), tokenCredentials);
419435
}
420436
}
Lines changed: 2 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -1,15 +1,12 @@
1-
using System;
2-
using System.Collections.Generic;
3-
using System.Linq;
4-
using System.Text;
1+
using System.Collections.Generic;
52
using System.Threading;
63
using System.Threading.Tasks;
74

85
namespace NLog.Extensions.AzureStorage
96
{
107
interface ICloudBlobService
118
{
12-
void Connect(string connectionString, string serviceUri, string tenantIdentity, string resourceIdentifier, string clientIdentity, string sharedAccessSignature, string storageAccountName, string storageAccountAccessKey, string clientId, string clientSecret, IDictionary<string, string> blobMetadata, IDictionary<string, string> blobTags);
9+
void Connect(string connectionString, string serviceUri, string tenantIdentity, string managedIdentityResourceId, string managedIdentityClientId, string sharedAccessSignature, string storageAccountName, string storageAccountAccessKey, string clientAuthId, string clientAuthSecret, IDictionary<string, string> blobMetadata, IDictionary<string, string> blobTags);
1310
Task AppendFromByteArrayAsync(string containerName, string blobName, string contentType, byte[] buffer, CancellationToken cancellationToken);
1411
}
1512
}

src/NLog.Extensions.AzureBlobStorage/README.md

Lines changed: 9 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -39,23 +39,23 @@ _contentType_ - Azure blob ContentType (Default = text/plain)
3939

4040
_connectionString_ - Azure storage connection string. Ex. `UseDevelopmentStorage=true;`
4141

42-
_serviceUri_ - Alternative to ConnectionString, where Managed Identiy is acquired from DefaultAzureCredential.
42+
_serviceUri_ - Uri to reference the blob service (e.g. https://{account_name}.blob.core.windows.net). Input for `BlobServiceClient`. Required, when `connectionString` is not configured. Overrides `connectionString` when both are set.
4343

44-
_clientIdentity_ - Alternative to ConnectionString. Used together with ServiceUri. Input for DefaultAzureCredential as ManagedIdentityClientId.
44+
_managedIdentityClientId_ - Sets `ManagedIdentityClientId` on `DefaultAzureCredentialOptions`. Requires `serviceUri`
4545

46-
_resourceIdentity_ - Alternative to ConnectionString. Used together with ServiceUri. Input for DefaultAzureCredential as ManagedIdentityResourceId.
46+
_managedIdentityResourceId_ - resourceId for `ManagedIdentityResourceId` on `DefaultAzureCredentialOptions`. Requires `serviceUri`.
4747

48-
_tenantIdentity_ - Alternative to ConnectionString. Used together with ServiceUri. Input for DefaultAzureCredential / ClientSecretCredential.
48+
_tenantIdentity_ - tenantId for `DefaultAzureCredentialOptions` and `ClientSecretCredential`. Requires `serviceUri`.
4949

50-
_sharedAccessSignature_ - Alternative to ConnectionString. Used together with ServiceUri. Input for AzureSasCredential
50+
_sharedAccessSignature_ - Access signature for `AzureSasCredential` authentication. Requires `serviceUri`.
5151

52-
_accountName_ - Alternative to ConnectionString. Used together with ServiceUri. Input for StorageSharedKeyCredential-AccountName
52+
_accountName_ - accountName for `StorageSharedKeyCredential` authentication. Requires `serviceUri` and `accessKey`.
5353

54-
_accessKey_ - Alternative to ConnectionString. Used together with ServiceUri. Input for StorageSharedKeyCredential-AccessKey
54+
_accessKey_ - accountKey for `StorageSharedKeyCredential` authentication. Requires `serviceUri` and `accountName`.
5555

56-
_clientId_ - Alternative to ConnectionString. Instantiates the `BlobServiceClient` using a `ClientSecretCredential` for authentication. Requires `TenantIdentity` and `ClientSecret`.
56+
_clientAuthId_ - clientId for `ClientSecretCredential` authentication. Requires `serviceUri`, `tenantIdentity` and `clientAuthSecret`.
5757

58-
_clientSecret_ - Secret when using ClientId. Instantiates the `BlobServiceClient` using a `ClientSecretCredential` for authentication. Requires `TenantIdentity` and `ClientId`.
58+
_clientAuthSecret_ - clientSecret for `ClientSecretCredential` authentication. Requires `serviceUri`,`tenantIdentity` and `clientAuthId`.
5959

6060
### Batching Policy
6161

src/NLog.Extensions.AzureStorage/AzureCredentialHelper.cs

Lines changed: 6 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -2,7 +2,7 @@ namespace NLog.Extensions.AzureStorage
22
{
33
internal static class AzureCredentialHelpers
44
{
5-
internal static Azure.Identity.DefaultAzureCredential CreateTokenCredentials(string clientIdentity, string tenantIdentity, string resourceIdentifier)
5+
internal static Azure.Identity.DefaultAzureCredential CreateTokenCredentials(string managedIdentityClientId, string tenantIdentity, string managedIdentityResourceId)
66
{
77
var options = new Azure.Identity.DefaultAzureCredentialOptions();
88

@@ -11,16 +11,16 @@ internal static Azure.Identity.DefaultAzureCredential CreateTokenCredentials(str
1111
options.TenantId = tenantIdentity;
1212
}
1313

14-
if (!string.IsNullOrWhiteSpace(clientIdentity))
14+
if (!string.IsNullOrWhiteSpace(managedIdentityClientId))
1515
{
16-
options.ManagedIdentityClientId = clientIdentity;
17-
options.WorkloadIdentityClientId = clientIdentity;
16+
options.ManagedIdentityClientId = managedIdentityClientId;
17+
options.WorkloadIdentityClientId = managedIdentityClientId;
1818
}
1919
else
2020
{
21-
if (!string.IsNullOrWhiteSpace(resourceIdentifier))
21+
if (!string.IsNullOrWhiteSpace(managedIdentityResourceId))
2222
{
23-
options.ManagedIdentityResourceId = new Azure.Core.ResourceIdentifier(resourceIdentifier);
23+
options.ManagedIdentityResourceId = new Azure.Core.ResourceIdentifier(managedIdentityResourceId);
2424
}
2525
else if (string.IsNullOrWhiteSpace(tenantIdentity))
2626
{

test/NLog.Extensions.AzureBlobStorage.Tests/CloudBlobServiceMock.cs

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -17,7 +17,7 @@ class CloudBlobServiceMock : ICloudBlobService
1717

1818
public IDictionary<string, string> BlobTags { get; private set; }
1919

20-
public void Connect(string connectionString, string serviceUri, string tenantIdentity, string resourceIdentifier, string clientIdentity, string sharedAccessSignature, string storageAccountName, string storageAccountAccessKey, string clientId, string clientSecret, IDictionary<string, string> blobMetadata, IDictionary<string, string> blobTags)
20+
public void Connect(string connectionString, string serviceUri, string tenantIdentity, string managedIdentityResourceId, string managedIdentityClientId, string sharedAccessSignature, string storageAccountName, string storageAccountAccessKey, string clientAuthId, string clientAuthSecret, IDictionary<string, string> blobMetadata, IDictionary<string, string> blobTags)
2121
{
2222
ConnectionString = connectionString;
2323
BlobMetadata = blobMetadata;

0 commit comments

Comments
 (0)