-
Notifications
You must be signed in to change notification settings - Fork 112
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Add webhook subscription content type and handler.
- Loading branch information
Showing
4 changed files
with
229 additions
and
0 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
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,89 @@ | ||
using SenseNet.ContentRepository; | ||
using SenseNet.ContentRepository.Schema; | ||
using SenseNet.ContentRepository.Storage; | ||
|
||
// ReSharper disable InconsistentNaming | ||
namespace SenseNet.WebHooks | ||
{ | ||
/// <summary> | ||
/// A Content handler that represents a webhook subscription. | ||
/// </summary> | ||
[ContentHandler] | ||
public class WebHookSubscription : GenericContent | ||
{ | ||
/// <summary> | ||
/// Initializes a new instance of the <see cref="WebHookSubscription"/> class. | ||
/// </summary> | ||
/// <param name="parent">The parent.</param> | ||
public WebHookSubscription(Node parent) : this(parent, null) { } | ||
/// <summary> | ||
/// Initializes a new instance of the <see cref="WebHookSubscription"/> class. | ||
/// </summary> | ||
/// <param name="parent">The parent.</param> | ||
/// <param name="nodeTypeName">Name of the node type.</param> | ||
public WebHookSubscription(Node parent, string nodeTypeName) : base(parent, nodeTypeName) { } | ||
/// <summary> | ||
/// Initializes a new instance of the <see cref="WebHookSubscription"/> class during the loading process. | ||
/// Do not use this constructor directly in your code. | ||
/// </summary> | ||
protected WebHookSubscription(NodeToken nt) : base(nt) { } | ||
|
||
private const string UrlPropertyName = "WebHookUrl"; | ||
[RepositoryProperty(UrlPropertyName, RepositoryDataType.String)] | ||
public string Url | ||
{ | ||
get => base.GetProperty<string>(UrlPropertyName); | ||
set => base.SetProperty(UrlPropertyName, value); | ||
} | ||
|
||
private const string HttpMethodPropertyName = "WebHookHttpMethod"; | ||
[RepositoryProperty(HttpMethodPropertyName, RepositoryDataType.String)] | ||
public string HttpMethod | ||
{ | ||
get => base.GetProperty<string>(HttpMethodPropertyName); | ||
set => base.SetProperty(HttpMethodPropertyName, value); | ||
} | ||
|
||
private const string EventTypePropertyName = "WebHookEventType"; | ||
[RepositoryProperty(EventTypePropertyName, RepositoryDataType.String)] | ||
public string EventType | ||
{ | ||
get => base.GetProperty<string>(EventTypePropertyName); | ||
set => base.SetProperty(EventTypePropertyName, value); | ||
} | ||
|
||
// ===================================================================================== Overrides | ||
|
||
/// <inheritdoc /> | ||
public override object GetProperty(string name) | ||
{ | ||
return name switch | ||
{ | ||
UrlPropertyName => this.Url, | ||
HttpMethodPropertyName => this.HttpMethod, | ||
EventTypePropertyName => this.EventType, | ||
_ => base.GetProperty(name), | ||
}; | ||
} | ||
|
||
/// <inheritdoc /> | ||
public override void SetProperty(string name, object value) | ||
{ | ||
switch (name) | ||
{ | ||
case UrlPropertyName: | ||
this.Url = (string)value; | ||
break; | ||
case HttpMethodPropertyName: | ||
this.HttpMethod = (string)value; | ||
break; | ||
case EventTypePropertyName: | ||
this.EventType = (string)value; | ||
break; | ||
default: | ||
base.SetProperty(name, value); | ||
break; | ||
} | ||
} | ||
} | ||
} |
83 changes: 83 additions & 0 deletions
83
...t/snadmin/install-services/importNetCore/Localization/CtdResourcesWebHookSubscription.xml
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,83 @@ | ||
<?xml version="1.0" encoding="utf-8"?> | ||
<Resources> | ||
<ResourceClass name="Ctd-WebHookSubscription"> | ||
<Languages> | ||
<Language cultureName="en"> | ||
<data name="DisplayName" xml:space="preserve"> | ||
<value>WebHook Subscription</value> | ||
</data> | ||
<data name="Description" xml:space="preserve"> | ||
<value>Defines an event and a 3rd party service that should be called when the event is fired.</value> | ||
</data> | ||
<data name="WebHookUrl-DisplayName" xml:space="preserve"> | ||
<value>Url</value> | ||
</data> | ||
<data name="WebHookUrl-Description" xml:space="preserve"> | ||
<value>Target url to call when the webhook is triggered.</value> | ||
</data> | ||
<data name="WebHookHttpMethod-DisplayName" xml:space="preserve"> | ||
<value>HTTP method</value> | ||
</data> | ||
<data name="WebHookHttpMethod-Description" xml:space="preserve"> | ||
<value></value> | ||
</data> | ||
<data name="WebHookEventType-DisplayName" xml:space="preserve"> | ||
<value>Event type</value> | ||
</data> | ||
<data name="WebHookEventType-Description" xml:space="preserve"> | ||
<value></value> | ||
</data> | ||
<data name="WebHookFilter-DisplayName" xml:space="preserve"> | ||
<value>Filter</value> | ||
</data> | ||
<data name="WebHookFilter-Description" xml:space="preserve"> | ||
<value></value> | ||
</data> | ||
<data name="WebHookHeaders-DisplayName" xml:space="preserve"> | ||
<value>HTTP headers</value> | ||
</data> | ||
<data name="WebHookHeaders-Description" xml:space="preserve"> | ||
<value>List of HTTP headers to add when the target service is called.</value> | ||
</data> | ||
</Language> | ||
<Language cultureName="hu"> | ||
<data name="DisplayName" xml:space="preserve"> | ||
<value>WebHook felíratkozás</value> | ||
</data> | ||
<data name="Description" xml:space="preserve"> | ||
<value>Definiál egy eseményt, aminek hatására meghívunk egy külső szolgáltatást.</value> | ||
</data> | ||
<data name="WebHookUrl-DisplayName" xml:space="preserve"> | ||
<value>Url</value> | ||
</data> | ||
<data name="WebHookUrl-Description" xml:space="preserve"> | ||
<value>A meghívandó cél url.</value> | ||
</data> | ||
<data name="WebHookHttpMethod-DisplayName" xml:space="preserve"> | ||
<value>HTTP method</value> | ||
</data> | ||
<data name="WebHookHttpMethod-Description" xml:space="preserve"> | ||
<value></value> | ||
</data> | ||
<data name="WebHookEventType-DisplayName" xml:space="preserve"> | ||
<value>Esemény típusa</value> | ||
</data> | ||
<data name="WebHookEventType-Description" xml:space="preserve"> | ||
<value></value> | ||
</data> | ||
<data name="WebHookFilter-DisplayName" xml:space="preserve"> | ||
<value>Szűrő</value> | ||
</data> | ||
<data name="WebHookFilter-Description" xml:space="preserve"> | ||
<value></value> | ||
</data> | ||
<data name="WebHookHeaders-DisplayName" xml:space="preserve"> | ||
<value>HTTP fejlécek</value> | ||
</data> | ||
<data name="WebHookHeaders-Description" xml:space="preserve"> | ||
<value>HTTP fejlécek listája, amiket hozzá kell tenni a külső szolgáltatás meghívásakor.</value> | ||
</data> | ||
</Language> | ||
</Languages> | ||
</ResourceClass> | ||
</Resources> |
11 changes: 11 additions & 0 deletions
11
...n/install-services/importNetCore/Localization/CtdResourcesWebHookSubscription.xml.Content
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,11 @@ | ||
<?xml version="1.0" encoding="utf-8"?> | ||
<ContentMetaData> | ||
<ContentType>Resource</ContentType> | ||
<ContentName>CtdResourcesWebHookSubscription.xml</ContentName> | ||
<Fields> | ||
<Binary attachment="CtdResourcesWebHookSubscription.xml" /> | ||
</Fields> | ||
<Permissions> | ||
<Clear /> | ||
</Permissions> | ||
</ContentMetaData> |
46 changes: 46 additions & 0 deletions
46
...dmin/install-services/importNetCore/System/Schema/ContentTypes/WebHookSubscriptionCtd.xml
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,46 @@ | ||
<?xml version="1.0" encoding="utf-8"?> | ||
<ContentType name="WebHookSubscription" parentType="GenericContent" handler="SenseNet.WebHooks.WebHookSubscription" xmlns="http://schemas.sensenet.com/SenseNet/ContentRepository/ContentTypeDefinition"> | ||
<DisplayName>$Ctd-WebHookSubscription,DisplayName</DisplayName> | ||
<Description>$Ctd-WebHookSubscription,Description</Description> | ||
<Icon>WebHookSubscription</Icon> | ||
<Fields> | ||
<Field name="WebHookUrl" type="ShortText"> | ||
<DisplayName>$Ctd-WebHookSubscription,WebHookUrl-DisplayName</DisplayName> | ||
<Description>$Ctd-WebHookSubscription,WebHookUrl-Description</Description> | ||
<Configuration> | ||
<Compulsory>true</Compulsory> | ||
<DefaultValue>https://</DefaultValue> | ||
</Configuration> | ||
</Field> | ||
<Field name="WebHookHttpMethod" type="Choice"> | ||
<DisplayName>$Ctd-WebHookSubscription,WebHookHttpMethod-DisplayName</DisplayName> | ||
<Description>$Ctd-WebHookSubscription,WebHookHttpMethod-Description</Description> | ||
<Configuration> | ||
<AllowMultiple>false</AllowMultiple> | ||
<AllowExtraValue>true</AllowExtraValue> | ||
<Options> | ||
<Option value="GET">GET</Option> | ||
<Option value="POST" selected="true">POST</Option> | ||
<Option value="PATCH">PATCH</Option> | ||
<Option value="PUT">PUT</Option> | ||
<Option value="DELETE">DELETE</Option> | ||
</Options> | ||
</Configuration> | ||
</Field> | ||
<Field name="WebHookEventType" type="ShortText"> | ||
<DisplayName>$Ctd-WebHookSubscription,WebHookEventType-DisplayName</DisplayName> | ||
<Description>$Ctd-WebHookSubscription,WebHookEventType-Description</Description> | ||
<Configuration> | ||
<Compulsory>true</Compulsory> | ||
</Configuration> | ||
</Field> | ||
<Field name="WebHookFilter" type="LongText"> | ||
<DisplayName>$Ctd-WebHookSubscription,WebHookFilter-DisplayName</DisplayName> | ||
<Description>$Ctd-WebHookSubscription,WebHookFilter-Description</Description> | ||
</Field> | ||
<Field name="WebHookHeaders" type="LongText"> | ||
<DisplayName>$Ctd-WebHookSubscription,WebHookHeaders-DisplayName</DisplayName> | ||
<Description>$Ctd-WebHookSubscription,WebHookHeaders-Description</Description> | ||
</Field> | ||
</Fields> | ||
</ContentType> |