Skip to content

Commit 8d58b42

Browse files
authored
Adding a web app custom handler configuration profile. (#11447)
* Adding a web app custom handler configuration profile. * Minor PR feedback updates
1 parent 19c738d commit 8d58b42

File tree

3 files changed

+28
-21
lines changed

3 files changed

+28
-21
lines changed

release_notes.md

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -2,4 +2,5 @@
22

33
<!-- Please add your release notes in the following format:
44
- My change description (#PR)
5-
-->
5+
-->
6+
- Adding a "web app" configuration profile (#11447)

src/WebJobs.Script/Config/HostConfigurationProfile.cs

Lines changed: 18 additions & 15 deletions
Original file line numberDiff line numberDiff line change
@@ -3,36 +3,37 @@
33

44
using System;
55
using System.Collections.Generic;
6-
using System.Linq;
76
using Microsoft.Extensions.Configuration;
87

98
namespace Microsoft.Azure.WebJobs.Script.Configuration
109
{
1110
public sealed class HostConfigurationProfile
1211
{
13-
public const string SectionKey = "configurationProfile";
12+
private const string SectionKey = "configurationProfile";
1413

1514
// note: profile name consts are intentionally private.
1615
// This ensures tests will fail if these values are changed without updating the test also.
1716
private const string DefaultProfile = "default";
1817

19-
private const string McpCustomerHandlerProfile = "mcp-custom-handler";
18+
private const string McpCustomHandlerProfile = "mcp-custom-handler";
19+
20+
private const string WebAppCustomHandlerProfile = "web-app-custom-handler";
2021

2122
// Make sure to update this as new profiles are added.
22-
private const string SupportedValues = $"'', '{DefaultProfile}', '{McpCustomerHandlerProfile}'";
23+
private const string SupportedValues = $"'', '{DefaultProfile}', '{McpCustomHandlerProfile}', '{WebAppCustomHandlerProfile}'";
24+
25+
private static readonly Dictionary<string, string> CommonHttpCustomHandlerConfiguration = new()
26+
{
27+
[ConfigurationPath.Combine(ConfigurationSectionNames.CustomHandler, ScriptConstants.EnableProxyingHttpRequest)] = "true",
28+
[ConfigurationPath.Combine(ConfigurationSectionNames.Http, "routePrefix")] = string.Empty,
29+
[ConfigurationPath.Combine(ConfigurationSectionNames.CustomHandler, "http", "routes", "0", "route")] = "{*route}"
30+
};
2331

2432
public static readonly HostConfigurationProfile Default = new(DefaultProfile, []);
2533

26-
public static readonly HostConfigurationProfile McpCustomHandler = new(
27-
McpCustomerHandlerProfile,
28-
[
29-
KeyValuePair.Create(ConfigurationPath.Combine(
30-
ConfigurationSectionNames.CustomHandler, ScriptConstants.EnableProxyingHttpRequest), "true"),
31-
KeyValuePair.Create(ConfigurationPath.Combine(
32-
ConfigurationSectionNames.Http, "routePrefix"), string.Empty),
33-
KeyValuePair.Create(ConfigurationPath.Combine(
34-
ConfigurationSectionNames.CustomHandler, "http", "routes", "0", "route"), "{*route}"),
35-
]);
34+
public static readonly HostConfigurationProfile McpCustomHandler = new(McpCustomHandlerProfile, CommonHttpCustomHandlerConfiguration);
35+
36+
public static readonly HostConfigurationProfile WebAppCustomHandler = new(WebAppCustomHandlerProfile, CommonHttpCustomHandlerConfiguration);
3637

3738
private HostConfigurationProfile(
3839
string name,
@@ -49,9 +50,11 @@ private HostConfigurationProfile(
4950
public static HostConfigurationProfile Get(string name)
5051
{
5152
ArgumentNullException.ThrowIfNull(name);
53+
5254
return name.ToLowerInvariant() switch
5355
{
54-
McpCustomerHandlerProfile => McpCustomHandler,
56+
McpCustomHandlerProfile => McpCustomHandler,
57+
WebAppCustomHandlerProfile => WebAppCustomHandler,
5558
"" or DefaultProfile => Default,
5659
_ => throw new NotSupportedException(
5760
$"Configuration profile '{name}' is not supported. Supported values: {SupportedValues}."),

test/WebJobs.Script.Tests/Configuration/HostConfigurationProfileTests.cs

Lines changed: 8 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -29,15 +29,18 @@ public void Get_Default_ReturnsExpectedProfile(string name)
2929
[Theory]
3030
[InlineData("mcp-custom-handler")]
3131
[InlineData("MCP-Custom-Handler")]
32-
public void Get_Mcp_ReturnsExpectedProfile(string name)
32+
[InlineData("web-app-Custom-Handler")]
33+
[InlineData("WEB-App-Custom-Handler")]
34+
public void Get_HttpBasedHandler_ReturnsExpectedProfile(string name)
3335
{
34-
HostConfigurationProfile profile = HostConfigurationProfile.Get(name);
36+
var expectedProfileName = name.ToLowerInvariant();
3537

38+
HostConfigurationProfile profile = HostConfigurationProfile.Get(name);
3639
Dictionary<string, string> configDict = new(profile.Configuration);
37-
profile.Name.Should().Be("mcp-custom-handler");
40+
profile.Name.Should().Be(expectedProfileName);
3841
configDict.Should().HaveCount(4);
3942
configDict.Should().ContainKey("configurationProfile")
40-
.WhoseValue.Should().Be("mcp-custom-handler");
43+
.WhoseValue.Should().Be(expectedProfileName);
4144
configDict.Should().ContainKey("customHandler:enableProxyingHttpRequest")
4245
.WhoseValue.Should().Be("true");
4346
configDict.Should().ContainKey("extensions:http:routePrefix")
@@ -60,7 +63,7 @@ public void Get_InvalidName_Throws()
6063

6164
action.Should()
6265
.ThrowExactly<NotSupportedException>()
63-
.WithMessage("Configuration profile 'invalid' is not supported. Supported values: '', 'default', 'mcp-custom-handler'.");
66+
.WithMessage("Configuration profile 'invalid' is not supported. Supported values: '', 'default', 'mcp-custom-handler', 'web-app-custom-handler'.");
6467
}
6568
}
6669
}

0 commit comments

Comments
 (0)