Skip to content

Commit

Permalink
Azure Blob Storage Databus Managed Identity documentation (#6641)
Browse files Browse the repository at this point in the history
* Azure Blob Storage Databus Managed Identity documentation

* Apply suggestions from code review
  • Loading branch information
danielmarbach committed May 24, 2024
1 parent 6685b93 commit 364336d
Show file tree
Hide file tree
Showing 8 changed files with 109 additions and 0 deletions.
3 changes: 3 additions & 0 deletions Snippets/ABSDataBus/ABSDataBus_4/ABSDataBus_4.csproj
Original file line number Diff line number Diff line change
Expand Up @@ -3,6 +3,9 @@
<TargetFramework>net48</TargetFramework>
</PropertyGroup>
<ItemGroup>
<PackageReference Include="Azure.Identity" Version="1.*" />
<PackageReference Include="Microsoft.Extensions.Azure" Version="1.*" />
<PackageReference Include="Microsoft.Extensions.Hosting.Abstractions" Version="8.*" />
<PackageReference Include="NServiceBus.DataBus.AzureBlobStorage" Version="4.*" />
</ItemGroup>
</Project>
26 changes: 26 additions & 0 deletions Snippets/ABSDataBus/ABSDataBus_4/Usage.cs
Original file line number Diff line number Diff line change
@@ -1,5 +1,9 @@
using System;
using Azure.Identity;
using Azure.Storage.Blobs;
using Microsoft.Extensions.Azure;
using Microsoft.Extensions.DependencyInjection;
using Microsoft.Extensions.Hosting;
using NServiceBus;
using NServiceBus.DataBus.AzureBlobStorage;

Expand Down Expand Up @@ -37,6 +41,28 @@ class Usage
#endregion
}

void UsageManagedIdentity(EndpointConfiguration endpointConfiguration, IHostApplicationBuilder builder)
{
#region AzureDataBusManagedIdentityServiceClient

var serviceClient = new BlobServiceClient(new Uri("https://<account-name>.blob.core.windows.net"), new DefaultAzureCredential());
endpointConfiguration.UseDataBus<AzureDataBus>()
.UseBlobServiceClient(serviceClient);

#endregion

#region AzureDataBusManagedIdentityExtensions

builder.Services.AddAzureClients(azureClients =>
{
azureClients.AddBlobServiceClient(new Uri("https://<account-name>.blob.core.windows.net"));
azureClients.UseCredential(new DefaultAzureCredential());
});
builder.Services.AddSingleton<IProvideBlobServiceClient, CustomProvider>();

#endregion
}

#region CustomBlobServiceClientProvider

public class CustomProvider : IProvideBlobServiceClient
Expand Down
3 changes: 3 additions & 0 deletions Snippets/ABSDataBus/ABSDataBus_5/ABSDataBus_5.csproj
Original file line number Diff line number Diff line change
Expand Up @@ -4,5 +4,8 @@
</PropertyGroup>
<ItemGroup>
<PackageReference Include="NServiceBus.DataBus.AzureBlobStorage" Version="5.*" />
<PackageReference Include="Azure.Identity" Version="1.*" />
<PackageReference Include="Microsoft.Extensions.Azure" Version="1.*" />
<PackageReference Include="Microsoft.Extensions.Hosting.Abstractions" Version="8.*" />
</ItemGroup>
</Project>
25 changes: 25 additions & 0 deletions Snippets/ABSDataBus/ABSDataBus_5/Usage.cs
Original file line number Diff line number Diff line change
Expand Up @@ -3,6 +3,9 @@
using NServiceBus;
using NServiceBus.DataBus.AzureBlobStorage;
using System;
using Azure.Identity;
using Microsoft.Extensions.Azure;
using Microsoft.Extensions.Hosting;

class Usage
{
Expand Down Expand Up @@ -38,6 +41,28 @@ class Usage
#endregion
}

void UsageManagedIdentity(EndpointConfiguration endpointConfiguration, IHostApplicationBuilder builder)
{
#region AzureDataBusManagedIdentityServiceClient

var serviceClient = new BlobServiceClient(new Uri("https://<account-name>.blob.core.windows.net"), new DefaultAzureCredential());
endpointConfiguration.UseDataBus<AzureDataBus, SystemJsonDataBusSerializer>()
.UseBlobServiceClient(serviceClient);

#endregion

#region AzureDataBusManagedIdentityExtensions

builder.Services.AddAzureClients(azureClients =>
{
azureClients.AddBlobServiceClient(new Uri("https://<account-name>.blob.core.windows.net"));
azureClients.UseCredential(new DefaultAzureCredential());
});
builder.Services.AddSingleton<IProvideBlobServiceClient, CustomProvider>();

#endregion
}

#region CustomBlobServiceClientProvider

public class CustomProvider : IProvideBlobServiceClient
Expand Down
3 changes: 3 additions & 0 deletions Snippets/ABSDataBus/ABSDataBus_6/ABSDataBus_6.csproj
Original file line number Diff line number Diff line change
Expand Up @@ -3,6 +3,9 @@
<TargetFramework>net8.0</TargetFramework>
</PropertyGroup>
<ItemGroup>
<PackageReference Include="Azure.Identity" Version="1.*" />
<PackageReference Include="Microsoft.Extensions.Azure" Version="1.*" />
<PackageReference Include="Microsoft.Extensions.Hosting.Abstractions" Version="8.*" />
<PackageReference Include="NServiceBus.DataBus.AzureBlobStorage" Version="6.*" />
</ItemGroup>
</Project>
25 changes: 25 additions & 0 deletions Snippets/ABSDataBus/ABSDataBus_6/Usage.cs
Original file line number Diff line number Diff line change
Expand Up @@ -3,6 +3,9 @@
using NServiceBus;
using NServiceBus.DataBus.AzureBlobStorage;
using System;
using Azure.Identity;
using Microsoft.Extensions.Azure;
using Microsoft.Extensions.Hosting;

class Usage
{
Expand Down Expand Up @@ -38,6 +41,28 @@ class Usage
#endregion
}

void UsageManagedIdentity(EndpointConfiguration endpointConfiguration, IHostApplicationBuilder builder)
{
#region AzureDataBusManagedIdentityServiceClient

var serviceClient = new BlobServiceClient(new Uri("https://<account-name>.blob.core.windows.net"), new DefaultAzureCredential());
endpointConfiguration.UseDataBus<AzureDataBus, SystemJsonDataBusSerializer>()
.UseBlobServiceClient(serviceClient);

#endregion

#region AzureDataBusManagedIdentityExtensions

builder.Services.AddAzureClients(azureClients =>
{
azureClients.AddBlobServiceClient(new Uri("https://<account-name>.blob.core.windows.net"));
azureClients.UseCredential(new DefaultAzureCredential());
});
builder.Services.AddSingleton<IProvideBlobServiceClient, CustomProvider>();

#endregion
}

#region CustomBlobServiceClientProvider

public class CustomProvider : IProvideBlobServiceClient
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -24,3 +24,15 @@ snippet: AzureDataBusConnectionAndContainer

> [!NOTE]
> The container name is optional and will be set to the default when omitted.
#### Token-credentials

Enables usage of Azure Active Directory (AAD) authentication such as [managed identities for Azure resources](https://learn.microsoft.com/en-us/azure/storage/blobs/authorize-access-azure-active-directory) instead of the shared secret in the connection string.

#### With a preconfigured BlobServiceClient

snippet: AzureDataBusManagedIdentityServiceClient

#### With Microsoft.Extensions.Azure

snippet: AzureDataBusManagedIdentityExtensions
Original file line number Diff line number Diff line change
Expand Up @@ -24,3 +24,15 @@ snippet: AzureDataBusConnectionAndContainer

> [!NOTE]
> The container name is optional and will be set to the default when omitted.
#### Token-credentials

Enables usage of Azure Active Directory (AAD) authentication such as [managed identities for Azure resources](https://learn.microsoft.com/en-us/azure/storage/blobs/authorize-access-azure-active-directory) instead of the shared secret in the connection string.

#### With a preconfigured BlobServiceClient

snippet: AzureDataBusManagedIdentityServiceClient

#### With Microsoft.Extensions.Azure

snippet: AzureDataBusManagedIdentityExtensions

0 comments on commit 364336d

Please sign in to comment.