Skip to content

Commit 730adf3

Browse files
committed
Allow [GeneralWebHook] without a required BodyType
- separate `IWebHookBodyTypeMetadata` and `IWebHookBodyTypeMetadataService` - make `BodyType` nullable in `IWebHookBodyTypeMetadata` - just ignore `IWebHookBodyTypeMetadata` services; can't confuse system - require `IWebHookBodyTypeMetadataService` for all receivers - implement `IWebHookBodyTypeMetadataService` in `WebHookMetadata` (`abstract`ly) - limit GitHub receiver to JSON requests - will add second GitHub attribute and metadata class if we need to support HTML form URL-encoded data - support `IWebHookBodyTypeMetadata` only in `GeneralWebHookAttribute` - i.e. use it only to set model binding information, not at runtime nits: - reword some resources for consistency and to provide more information e.g. the receiver name - remove newly-unused resources - remove `LogCritical(...)` for configuration errors caught during startup - `throw` an `InvalidOperationExcepiton` when a problem is first discovered - reduce severity of other logging e.g. `LogError(...)` for configuration errors caught later - inline type names and other constants - log new warnings in `WebHookModelBindingProvider` - add and update doc comments - fix a few `cref`s to refer to correct classes e.g. in `WebHookModelBindingProvider` - e.g. add more comments about `IApplicationModelProvider.Order` - e.g. add comments about mixing `[WebHookAttribute]` with `[Consumes]` - refactor validity checks out of `WebHookMetadataProvider.Apply(...)` - remove unused parameter from `WebHookRoutingProvider.ChooseTemplate()` - get rid of all unintended (not generated or in test data) excess e.g. two-space whitespace - remove leftover file from solution; add dependencies.props - VS removed byte order marks
1 parent a1dc02c commit 730adf3

File tree

50 files changed

+1313
-562
lines changed

Some content is hidden

Large Commits have some content hidden by default. Use the searchbox below for content that may be hidden.

50 files changed

+1313
-562
lines changed

WebHooks.sln

Lines changed: 2 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -15,18 +15,14 @@ Project("{2150E333-8FDC-42A3-9474-1A3956D46DE8}") = "Test", "Test", "{9575CB90-B
1515
EndProject
1616
Project("{2150E333-8FDC-42A3-9474-1A3956D46DE8}") = "Solution Items", "Solution Items", "{9C98BA1B-1543-45B8-A11D-C31F51C0D22A}"
1717
ProjectSection(SolutionItems) = preProject
18+
build\dependencies.props = build\dependencies.props
1819
Directory.Build.props = Directory.Build.props
1920
Directory.Build.targets = Directory.Build.targets
2021
LICENSE = LICENSE
2122
README.md = README.md
2223
version.xml = version.xml
2324
EndProjectSection
2425
EndProject
25-
Project("{2150E333-8FDC-42A3-9474-1A3956D46DE8}") = ".nuget", ".nuget", "{BA0737AF-7CAE-4F28-B7D8-D99131C076A5}"
26-
ProjectSection(SolutionItems) = preProject
27-
.nuget\packages.config = .nuget\packages.config
28-
EndProjectSection
29-
EndProject
3026
Project("{2150E333-8FDC-42A3-9474-1A3956D46DE8}") = "Samples", "Samples", "{E957C8D9-B4A0-488B-838F-BAB4DE080A76}"
3127
ProjectSection(SolutionItems) = preProject
3228
samples\Directory.Build.props = samples\Directory.Build.props
@@ -276,7 +272,7 @@ Global
276272
{E9E37253-3FE1-44A4-A9E7-A2B6C54EECFE} = {E957C8D9-B4A0-488B-838F-BAB4DE080A76}
277273
EndGlobalSection
278274
GlobalSection(ExtensibilityGlobals) = postSolution
279-
SolutionGuid = {12CE6238-F847-4984-8622-1ED46072150A}
280275
EnterpriseLibraryConfigurationToolBinariesPathV6 = packages\EnterpriseLibrary.TransientFaultHandling.6.0.1304.0\lib\portable-net45+win+wp8;packages\EnterpriseLibrary.TransientFaultHandling.Data.6.0.1304.1\lib\NET45
276+
SolutionGuid = {12CE6238-F847-4984-8622-1ED46072150A}
281277
EndGlobalSection
282278
EndGlobal

build/dependencies.props

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,4 @@
1-
<Project>
1+
<Project>
22
<PropertyGroup>
33
<MSBuildAllProjects>$(MSBuildAllProjects);$(MSBuildThisFileFullPath)</MSBuildAllProjects>
44
</PropertyGroup>

samples/GitHubCoreReceiver/Controllers/GitHubController.cs

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,4 @@
1-
using Microsoft.AspNetCore.Mvc;
1+
using Microsoft.AspNetCore.Mvc;
22
using Microsoft.AspNetCore.WebHooks;
33
using Newtonsoft.Json.Linq;
44

@@ -51,7 +51,7 @@ public IActionResult GitHubHandler(string id, string @event, JObject data)
5151
}
5252

5353
[GeneralWebHook]
54-
public IActionResult FallbackHandler(string receiverName, string id, string eventName, JObject data)
54+
public IActionResult FallbackHandler(string receiverName, string id, string eventName)
5555
{
5656
if (!ModelState.IsValid)
5757
{

samples/PusherCoreReceiver/wwwroot/index.html

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,4 @@
1-
<!DOCTYPE html>
1+
<!DOCTYPE html>
22
<html>
33
<head>
44
<title>Microsoft ASP.NET Core Pusher WebHooks receiver sample</title>

src/Microsoft.AspNetCore.WebHooks.Receivers.AzureAlert/Metadata/AzureAlertMetadata.cs

Lines changed: 3 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -1,16 +1,12 @@
1-
// Copyright (c) .NET Foundation. All rights reserved.
1+
// Copyright (c) .NET Foundation. All rights reserved.
22
// Licensed under the Apache License, Version 2.0. See License.txt in the project root for license information.
33

44
namespace Microsoft.AspNetCore.WebHooks.Metadata
55
{
66
/// <summary>
77
/// An <see cref="IWebHookMetadata"/> service containing metadata about the Azure Alert receiver.
88
/// </summary>
9-
public class AzureAlertMetadata :
10-
WebHookMetadata,
11-
IWebHookBodyTypeMetadataService,
12-
IWebHookEventFromBodyMetadata,
13-
IWebHookVerifyCodeMetadata
9+
public class AzureAlertMetadata : WebHookMetadata, IWebHookEventFromBodyMetadata, IWebHookVerifyCodeMetadata
1410
{
1511
/// <summary>
1612
/// Instantiates a new <see cref="AzureAlertMetadata"/> instance.
@@ -23,7 +19,7 @@ public AzureAlertMetadata()
2319
// IWebHookBodyTypeMetadataService...
2420

2521
/// <inheritdoc />
26-
public WebHookBodyType BodyType => WebHookBodyType.Json;
22+
public override WebHookBodyType BodyType => WebHookBodyType.Json;
2723

2824
// IWebHookEventFromBodyMetadata...
2925

src/Microsoft.AspNetCore.WebHooks.Receivers.BitBucket/Metadata/BitbucketMetadata.cs

Lines changed: 2 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,4 @@
1-
// Copyright (c) .NET Foundation. All rights reserved.
1+
// Copyright (c) .NET Foundation. All rights reserved.
22
// Licensed under the Apache License, Version 2.0. See License.txt in the project root for license information.
33

44
using System.Collections.Generic;
@@ -11,7 +11,6 @@ namespace Microsoft.AspNetCore.WebHooks.Metadata
1111
public class BitbucketMetadata :
1212
WebHookMetadata,
1313
IWebHookBindingMetadata,
14-
IWebHookBodyTypeMetadataService,
1514
IWebHookEventMetadata,
1615
IWebHookVerifyCodeMetadata
1716
{
@@ -43,7 +42,7 @@ public BitbucketMetadata()
4342
// IWebHookBodyTypeMetadataService...
4443

4544
/// <inheritdoc />
46-
public WebHookBodyType BodyType => WebHookBodyType.Json;
45+
public override WebHookBodyType BodyType => WebHookBodyType.Json;
4746

4847
// IWebHookEventMetadata...
4948

src/Microsoft.AspNetCore.WebHooks.Receivers.Dropbox/Metadata/DropboxMetadata.cs

Lines changed: 3 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -1,16 +1,12 @@
1-
// Copyright (c) .NET Foundation. All rights reserved.
1+
// Copyright (c) .NET Foundation. All rights reserved.
22
// Licensed under the Apache License, Version 2.0. See License.txt in the project root for license information.
33

44
namespace Microsoft.AspNetCore.WebHooks.Metadata
55
{
66
/// <summary>
77
/// An <see cref="IWebHookMetadata"/> service containing metadata about the Dropbox receiver.
88
/// </summary>
9-
public class DropboxMetadata :
10-
WebHookMetadata,
11-
IWebHookBodyTypeMetadataService,
12-
IWebHookEventMetadata,
13-
IWebHookGetHeadRequestMetadata
9+
public class DropboxMetadata : WebHookMetadata, IWebHookEventMetadata, IWebHookGetHeadRequestMetadata
1410
{
1511
/// <summary>
1612
/// Instantiates a new <see cref="DropboxMetadata"/> instance.
@@ -23,7 +19,7 @@ public DropboxMetadata()
2319
// IWebHookBodyTypeMetadataService...
2420

2521
/// <inheritdoc />
26-
public WebHookBodyType BodyType => WebHookBodyType.Json;
22+
public override WebHookBodyType BodyType => WebHookBodyType.Json;
2723

2824
// IWebHookEventMetadata...
2925

src/Microsoft.AspNetCore.WebHooks.Receivers.DynamicsCRM/Metadata/DynamicsCRMMetadata.cs

Lines changed: 3 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -1,16 +1,12 @@
1-
// Copyright (c) .NET Foundation. All rights reserved.
1+
// Copyright (c) .NET Foundation. All rights reserved.
22
// Licensed under the Apache License, Version 2.0. See License.txt in the project root for license information.
33

44
namespace Microsoft.AspNetCore.WebHooks.Metadata
55
{
66
/// <summary>
77
/// An <see cref="IWebHookMetadata"/> service containing metadata about the Dynamics CRM receiver.
88
/// </summary>
9-
public class DynamicsCRMMetadata :
10-
WebHookMetadata,
11-
IWebHookBodyTypeMetadataService,
12-
IWebHookEventFromBodyMetadata,
13-
IWebHookVerifyCodeMetadata
9+
public class DynamicsCRMMetadata : WebHookMetadata, IWebHookEventFromBodyMetadata, IWebHookVerifyCodeMetadata
1410
{
1511
/// <summary>
1612
/// Instantiates a new <see cref="DynamicsCRMMetadata"/> instance.
@@ -23,7 +19,7 @@ public DynamicsCRMMetadata()
2319
// IWebHookBodyTypeMetadataService...
2420

2521
/// <inheritdoc />
26-
public WebHookBodyType BodyType => WebHookBodyType.Json;
22+
public override WebHookBodyType BodyType => WebHookBodyType.Json;
2723

2824
// IWebHookEventFromBodyMetadata...
2925

src/Microsoft.AspNetCore.WebHooks.Receivers.GitHub/GitHubWebHookAttribute.cs

Lines changed: 8 additions & 21 deletions
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,4 @@
1-
// Copyright (c) .NET Foundation. All rights reserved.
1+
// Copyright (c) .NET Foundation. All rights reserved.
22
// Licensed under the Apache License, Version 2.0. See License.txt in the project root for license information.
33

44
using System;
@@ -9,19 +9,17 @@ namespace Microsoft.AspNetCore.WebHooks
99
{
1010
/// <summary>
1111
/// <para>
12-
/// An <see cref="Attribute"/> indicating the associated action is a GitHub WebHook endpoint. Specifies whether
13-
/// the action should <see cref="AcceptFormData"/>, optional <see cref="EventName"/>, and optional
14-
/// <see cref="WebHookAttribute.Id"/>. Also adds a <see cref="Filters.WebHookReceiverExistsFilter"/> for the
15-
/// action.
12+
/// An <see cref="Attribute"/> indicating the associated action is a GitHub WebHook endpoint. Specifies the
13+
/// optional <see cref="EventName"/> and optional <see cref="WebHookAttribute.Id"/>. Also adds a
14+
/// <see cref="Filters.WebHookReceiverExistsFilter"/> for the action.
1615
/// </para>
1716
/// <para>
1817
/// The signature of the action should be:
1918
/// <code>
2019
/// Task{IActionResult} ActionName(string id, string @event, TData data)
2120
/// </code>
2221
/// or include the subset of parameters required. <c>TData</c> must be compatible with expected requests e.g.
23-
/// <see cref="Newtonsoft.Json.Linq.JObject"/> or <see cref="Http.IFormCollection"/> (if
24-
/// <see cref="AcceptFormData"/> is <see langword="true"/>).
22+
/// <see cref="Newtonsoft.Json.Linq.JObject"/>.
2523
/// </para>
2624
/// <para>
2725
/// An example GitHub WebHook URI is '<c>https://{host}/api/webhooks/incoming/github/{id}</c>'. See
@@ -40,25 +38,19 @@ namespace Microsoft.AspNetCore.WebHooks
4038
/// <see cref="EventName"/> in a WebHook application.
4139
/// </para>
4240
/// </remarks>
43-
public class GitHubWebHookAttribute : WebHookAttribute, IWebHookBodyTypeMetadata, IWebHookEventSelectorMetadata
41+
public class GitHubWebHookAttribute : WebHookAttribute, IWebHookEventSelectorMetadata
4442
{
4543
private string _eventName;
4644

4745
/// <summary>
48-
/// Instantiates a new <see cref="GitHubWebHookAttribute"/> indicating the associated action is a GitHub
49-
/// WebHook endpoint.
46+
/// Instantiates a new <see cref="GitHubWebHookAttribute"/> instance indicating the associated action is a
47+
/// GitHub WebHook endpoint.
5048
/// </summary>
5149
public GitHubWebHookAttribute()
5250
: base(GitHubConstants.ReceiverName)
5351
{
5452
}
5553

56-
/// <summary>
57-
/// Gets or sets an indication this action expects HTML form URL-encoded data.
58-
/// </summary>
59-
/// <value>Defaults to <see langword="false"/>, indicating this action expects JSON data.</value>
60-
public bool AcceptFormData { get; set; }
61-
6254
/// <summary>
6355
/// Gets or sets the name of the event the associated controller action accepts.
6456
/// </summary>
@@ -79,10 +71,5 @@ public string EventName
7971
_eventName = value;
8072
}
8173
}
82-
83-
/// <inheritdoc />
84-
WebHookBodyType IWebHookBodyTypeMetadata.BodyType => AcceptFormData ?
85-
WebHookBodyType.Form :
86-
WebHookBodyType.Json;
8774
}
8875
}

src/Microsoft.AspNetCore.WebHooks.Receivers.GitHub/Internal/GitHubServiceCollectionSetup.cs

Lines changed: 1 addition & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -28,8 +28,7 @@ public static void AddGitHubServices(IServiceCollection services)
2828
}
2929

3030
services.TryAddEnumerable(ServiceDescriptor.Transient<IConfigureOptions<MvcOptions>, MvcOptionsSetup>());
31-
services.TryAddEnumerable(ServiceDescriptor.Singleton<IWebHookEventMetadata, GitHubMetadata>());
32-
services.TryAddEnumerable(ServiceDescriptor.Singleton<IWebHookPingRequestMetadata, GitHubMetadata>());
31+
WebHookMetadata.Register<GitHubMetadata>(services);
3332

3433
services.TryAddSingleton<GitHubVerifySignatureFilter>();
3534
}

0 commit comments

Comments
 (0)