Skip to content

Commit

Permalink
Enable External Durable Client Managed Identity Support (#2856)
Browse files Browse the repository at this point in the history
* Update StandardConnectionInfoProvider.cs

* Update StandardConnectionInfoProvider.cs

* Update StandardConnectionInfoProvider.cs

* Update StandardConnectionInfoProvider.cs

* add description about the resolve method implementation

* remove whitespace

* update by comment
  • Loading branch information
nytian authored and bachuv committed Jul 9, 2024
1 parent 2d50e2d commit 063d2ca
Showing 1 changed file with 33 additions and 2 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -2,6 +2,7 @@
// Licensed under the MIT License. See LICENSE in the project root for license information.

using System;
using System.Linq;
using Microsoft.Extensions.Configuration;

namespace Microsoft.Azure.WebJobs.Extensions.DurableTask
Expand All @@ -23,10 +24,40 @@ public StandardConnectionInfoProvider(IConfiguration configuration)
this.configuration = configuration ?? throw new ArgumentNullException(nameof(configuration));
}

// This implementation is a clone of `IConfigurationSection.Exists` found here https://github.com/dotnet/runtime/blob/main/src/libraries/Microsoft.Extensions.Configuration.Abstractions/src/ConfigurationExtensions.cs#L78
// Functions host v1 (.net462 framework) doesn't support this method so we implement a substitute one here.
private bool IfExists(IConfigurationSection section)
{
if (section == null)
{
return false;
}

if (section.Value == null)
{
return section.GetChildren().Any();
}

return true;
}

/// <inheritdoc />
public IConfigurationSection Resolve(string name)
{
return this.configuration.GetSection(name);
// This implementation is a replica of the WebJobsConnectionInfoProvider used for the internal durable client.
// The original code can be found at:
// https://github.com/Azure/azure-functions-durable-extension/blob/dev/src/WebJobs.Extensions.DurableTask/WebJobsConnectionInfoProvider.cs#L37.
// We need to first check the configuration section with the AzureWebJobs prefix, as this is the default name within the Functions app whether it's internal or external.
string prefixedConnectionStringName = "AzureWebJobs" + name;
IConfigurationSection section = this.configuration?.GetSection(prefixedConnectionStringName);

if (!this.IfExists(section))
{
// If the section doesn't exist, then look for the configuration section without the prefix, since there is no prefix outside the WebJobs app.
section = this.configuration?.GetSection(name);
}

return section;
}
}
}
}

0 comments on commit 063d2ca

Please sign in to comment.