-
Notifications
You must be signed in to change notification settings - Fork 4.9k
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Support WebJobs configuration fallback logic (#14825)
- Loading branch information
Showing
15 changed files
with
337 additions
and
40 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
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
8 changes: 8 additions & 0 deletions
8
sdk/extensions/Microsoft.Azure.WebJobs.Extensions.Clients/samples/local.settings.json
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,8 @@ | ||
{ | ||
"IsEncrypted": false, | ||
"Values": { | ||
"AzureWebJobsStorage": "UseDevelopmentStorage=true", | ||
"MyStorageConnection": "DefaultEndpointsProtocol=http;AccountName=devstoreaccount1;AccountKey=Eby8vdM02xNOcqFlqUwJPLlmEtlCDXJ1OUzFT50uSRZ6IFsuFq2UVErCz4I6tq/K1SZFPTOtr/KBHBeksoGMGw==;BlobEndpoint=http://127.0.0.1:10000/devstoreaccount1;QueueEndpoint=http://127.0.0.1:10001/devstoreaccount1;", | ||
"FUNCTIONS_WORKER_RUNTIME": "dotnet" | ||
} | ||
} |
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
sdk/extensions/Microsoft.Azure.WebJobs.Extensions.Clients/src/Properties/AssemblyInfo.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 @@ | ||
// Copyright (c) Microsoft Corporation. All rights reserved. | ||
// Licensed under the MIT License. | ||
|
||
using System.Runtime.CompilerServices; | ||
|
||
[assembly: InternalsVisibleTo("DynamicProxyGenAssembly2, PublicKey=0024000004800000940000000602000000240000525341310004000001000100c547cac37abd99c8db225ef2f6c8a3602f3b3606cc9891605d02baa56104f4cfc0734aa39b93bf7852f7d9266654753cc297e7d2edfe0bac1cdcf9f717241550e0a7b191195b7667bb4f64bcb8e2121380fd1d9d46ad2d92d2d15605093924cceaf74c4861eff62abf69b9291ed0a340e113be11e6a7d3113e92484cf7045cc7")] | ||
[assembly: InternalsVisibleTo("Microsoft.Azure.WebJobs.Extensions.Clients.Tests, PublicKey=0024000004800000940000000602000000240000525341310004000001000100d15ddcb29688295338af4b7686603fe614abd555e09efba8fb88ee09e1f7b1ccaeed2e8f823fa9eef3fdd60217fc012ea67d2479751a0b8c087a4185541b851bd8b16f8d91b840e51b1cb0ba6fe647997e57429265e85ef62d565db50a69ae1647d54d7bd855e4db3d8a91510e5bcbd0edfbbecaa20a7bd9ae74593daa7b11b4")] |
56 changes: 56 additions & 0 deletions
56
sdk/extensions/Microsoft.Azure.WebJobs.Extensions.Clients/src/WebJobsConfiguration.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,56 @@ | ||
// Copyright (c) Microsoft Corporation. All rights reserved. | ||
// Licensed under the MIT License. | ||
|
||
using System; | ||
using System.Collections.Generic; | ||
using Microsoft.Azure.WebJobs; | ||
using Microsoft.Extensions.Azure; | ||
using Microsoft.Extensions.Configuration; | ||
using Microsoft.Extensions.DependencyInjection; | ||
using Microsoft.Extensions.Primitives; | ||
|
||
namespace Microsoft.Extensions.Hosting | ||
{ | ||
/// <summary> | ||
/// Wraps the <see cref="IConfiguration"/> instance and applies fallback rules similar to https://github.com/Azure/azure-webjobs-sdk/blob/dev/src/Microsoft.Azure.WebJobs.Host/Extensions/IConfigurationExtensions.cs. | ||
/// </summary> | ||
internal class WebJobsConfiguration : IConfiguration | ||
{ | ||
private readonly IConfiguration _configuration; | ||
|
||
public WebJobsConfiguration(IConfiguration configuration) | ||
{ | ||
_configuration = configuration; | ||
} | ||
|
||
private const string DefaultConfigurationRootSectionName = "AzureWebJobs"; | ||
|
||
public string this[string key] | ||
{ | ||
get => _configuration[key]; | ||
set => _configuration[key] = value; | ||
} | ||
|
||
public IEnumerable<IConfigurationSection> GetChildren() => _configuration.GetChildren(); | ||
|
||
public IChangeToken GetReloadToken() => _configuration.GetReloadToken(); | ||
|
||
public IConfigurationSection GetSection(string key) | ||
{ | ||
var section = _configuration.GetSection(key); | ||
if (section.Exists()) | ||
{ | ||
return section; | ||
} | ||
|
||
var prefixedKey = DefaultConfigurationRootSectionName + key; | ||
section = _configuration.GetSection(prefixedKey); | ||
if (section.Exists()) | ||
{ | ||
return section; | ||
} | ||
|
||
return _configuration.GetSection("ConnectionStrings").GetSection(key); | ||
} | ||
} | ||
} |
62 changes: 62 additions & 0 deletions
62
...s/Microsoft.Azure.WebJobs.Extensions.Clients/tests/AzureClientAttributeFunctionalTests.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,62 @@ | ||
// Copyright (c) Microsoft Corporation. All rights reserved. | ||
// Licensed under the MIT License. | ||
|
||
using System.Collections.Generic; | ||
using System.Threading.Tasks; | ||
using Azure.Core; | ||
using Azure.Core.TestFramework; | ||
using Azure.Security.KeyVault.Secrets; | ||
using Microsoft.Azure.WebJobs.Host.TestCommon; | ||
using Microsoft.Extensions.Azure; | ||
using Microsoft.Extensions.Azure.WebJobs.Tests; | ||
using Microsoft.Extensions.Configuration; | ||
using Microsoft.Extensions.Hosting; | ||
|
||
namespace Microsoft.Azure.WebJobs.Extensions.Clients.Tests | ||
{ | ||
public class AzureClientAttributeFunctionalTests : RecordedTestBase<WebJobsTestEnvironment> | ||
{ | ||
public AzureClientAttributeFunctionalTests(bool isAsync) : base(isAsync) | ||
{ | ||
Matcher = new RecordMatcher() | ||
{ | ||
VolatileQueryParameters = | ||
{ | ||
// Ignore KeyVault client API Version when matching | ||
"api-version" | ||
} | ||
}; | ||
} | ||
|
||
[RecordedTest] | ||
public async Task CanInjectKeyVaultClient() | ||
{ | ||
var host = new HostBuilder() | ||
.ConfigureServices(services => services.AddAzureClients(builder => builder | ||
.ConfigureDefaults(options => Recording.InstrumentClientOptions<ClientOptions>(options)) | ||
.UseCredential(TestEnvironment.Credential))) | ||
.ConfigureAppConfiguration(config => | ||
{ | ||
config.AddInMemoryCollection(new Dictionary<string, string> | ||
{ | ||
{ "AzureWebJobsConnection:vaultUri", TestEnvironment.KeyVaultUrl } | ||
}); | ||
}) | ||
.ConfigureDefaultTestHost<FunctionWithAzureClient>(builder => | ||
{ | ||
builder.AddAzureClients(); | ||
}).Build(); | ||
|
||
var jobHost = host.GetJobHost<FunctionWithAzureClient>(); | ||
await jobHost.CallAsync(nameof(FunctionWithAzureClient.Run)); | ||
} | ||
|
||
public class FunctionWithAzureClient | ||
{ | ||
public async Task Run([AzureClient("Connection")] SecretClient keyClient) | ||
{ | ||
await keyClient.SetSecretAsync("TestSecret", "Secret value"); | ||
} | ||
} | ||
} | ||
} |
Oops, something went wrong.