From e21eb94376f242145b07b49c923f2f997d83611c Mon Sep 17 00:00:00 2001 From: JP Dillingham Date: Mon, 28 Oct 2024 18:35:52 -0500 Subject: stub webhook configuration --- src/slskd/Core/Options.cs | 66 +++++++++++++++++++++++++++++++++++++++++++++++ 1 file changed, 66 insertions(+) (limited to 'src/slskd/Core/Options.cs') diff --git a/src/slskd/Core/Options.cs b/src/slskd/Core/Options.cs index 306f9b87..cca24ee9 100644 --- a/src/slskd/Core/Options.cs +++ b/src/slskd/Core/Options.cs @@ -2005,6 +2005,12 @@ namespace slskd /// public class IntegrationOptions { + /// + /// Gets webhook configuration. + /// + [Validate] + public Dictionary Webhooks { get; init; } = []; + /// /// Gets script configuration. /// @@ -2023,6 +2029,66 @@ namespace slskd [Validate] public PushbulletOptions Pushbullet { get; init; } = new PushbulletOptions(); + /// + /// Webhook configuration. + /// + public class WebhookOptions + { + /// + /// Gets the list of Event types that trigger the webhook. + /// + [Enum(typeof(EventType))] + public string[] On { get; init; } = Array.Empty(); + + /// + /// Gets details about the webhook call. + /// + [Validate] + public WebhookDetails Call { get; init; } = new WebhookDetails(); + } + + /// + /// Webhook details. + /// + public class WebhookDetails : IValidatableObject + { + /// + /// Gets the fully qualified URL for the webhook. + /// + [NotNullOrWhiteSpace] + public string Url { get; init; } + + /// + /// Gets the HTTP headers to include with the webhook. + /// + [Validate] + public IEnumerable Headers { get; init; } = []; + + /// + /// Gets a value indicating whether HTTPS certificate errors should be ignored. + /// + public bool IgnoreCertificateErrors { get; init; } = false; + + public IEnumerable Validate(ValidationContext validationContext) + { + var results = new List(); + + if (!Url.StartsWith("http://", StringComparison.OrdinalIgnoreCase) && !Url.StartsWith("https://", StringComparison.OrdinalIgnoreCase)) + { + results.Add(new ValidationResult($"The {nameof(Url)} field must contain a fully qualified URL, including protocol (e.g. http:// or https://)")); + } + + return results; + } + } + + public class WebhookDetailHeader + { + [NotNullOrWhiteSpace] + public string Name { get; init; } + public string Value { get; init; } + } + /// /// Script configuration. /// -- cgit v1.2.3 From b94dfe45ad62b3fa6cad0e6358e5fcba49ff7d37 Mon Sep 17 00:00:00 2001 From: JP Dillingham Date: Mon, 28 Oct 2024 20:18:57 -0500 Subject: use an array for headers or everything breaks --- src/slskd/Core/Options.cs | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) (limited to 'src/slskd/Core/Options.cs') diff --git a/src/slskd/Core/Options.cs b/src/slskd/Core/Options.cs index cca24ee9..a9d6aeb8 100644 --- a/src/slskd/Core/Options.cs +++ b/src/slskd/Core/Options.cs @@ -2062,7 +2062,7 @@ namespace slskd /// Gets the HTTP headers to include with the webhook. /// [Validate] - public IEnumerable Headers { get; init; } = []; + public WebhookDetailHeader[] Headers { get; init; } = []; /// /// Gets a value indicating whether HTTPS certificate errors should be ignored. -- cgit v1.2.3 From 28e7090da1ec2a3711f660263edf37f78506a68b Mon Sep 17 00:00:00 2001 From: JP Dillingham Date: Sat, 2 Nov 2024 20:08:36 -0500 Subject: add timeout and retry options for webhooks --- src/slskd/Core/Options.cs | 44 +++++++++++++++++++++++++++++++++++++++----- 1 file changed, 39 insertions(+), 5 deletions(-) (limited to 'src/slskd/Core/Options.cs') diff --git a/src/slskd/Core/Options.cs b/src/slskd/Core/Options.cs index a9d6aeb8..e5f16b1e 100644 --- a/src/slskd/Core/Options.cs +++ b/src/slskd/Core/Options.cs @@ -2044,13 +2044,25 @@ namespace slskd /// Gets details about the webhook call. /// [Validate] - public WebhookDetails Call { get; init; } = new WebhookDetails(); + public WebhookHttpOptions Call { get; init; } = new WebhookHttpOptions(); + + /// + /// Gets the time to wait before timing out, in milliseconds. + /// + [Range(500, int.MaxValue)] + public int Timeout { get; init; } = 5000; + + /// + /// Gets the retry configuration. + /// + [Validate] + public RetryOptions Retry { get; init; } = new RetryOptions(); } /// - /// Webhook details. + /// Webhook HTTP options. /// - public class WebhookDetails : IValidatableObject + public class WebhookHttpOptions : IValidatableObject { /// /// Gets the fully qualified URL for the webhook. @@ -2062,7 +2074,7 @@ namespace slskd /// Gets the HTTP headers to include with the webhook. /// [Validate] - public WebhookDetailHeader[] Headers { get; init; } = []; + public WebhookHttpHeader[] Headers { get; init; } = []; /// /// Gets a value indicating whether HTTPS certificate errors should be ignored. @@ -2082,13 +2094,35 @@ namespace slskd } } - public class WebhookDetailHeader + /// + /// Webhook HTTP header configuration. + /// + public class WebhookHttpHeader { + /// + /// Gets the name of the header. + /// [NotNullOrWhiteSpace] public string Name { get; init; } + + /// + /// Gets the header's value. + /// public string Value { get; init; } } + /// + /// Retry configuration. + /// + public class RetryOptions + { + /// + /// Gets the number of attempts to make before failing. + /// + [Range(1, int.MaxValue)] + public int Attempts { get; init; } = 1; + } + /// /// Script configuration. /// -- cgit v1.2.3