aboutsummaryrefslogtreecommitdiffstats
path: root/src/slskd/Core/Options.cs
diff options
context:
space:
mode:
authorJP Dillingham <jp@dillingham.me>2024-11-04 08:21:43 -0600
committerGitHub <noreply@github.com>2024-11-04 08:21:43 -0600
commite7aefd66f1992dcecd9454df0771e1f29fae2b1d (patch)
tree14da14b514ab3755d03e025f95903eda47c789e0 /src/slskd/Core/Options.cs
parent5ebb679f4f7a24649e5117931e06138a9375110f (diff)
parent7f9a694da61bb046343d9f98ec2b5cd8b444e56b (diff)
downloadslskd-e7aefd66f1992dcecd9454df0771e1f29fae2b1d.tar.gz
Merge pull request #1238 from slskd/webhooks
Add the ability to call HTTP endpoints (webhooks) when application events are raised
Diffstat (limited to 'src/slskd/Core/Options.cs')
-rw-r--r--src/slskd/Core/Options.cs100
1 files changed, 100 insertions, 0 deletions
diff --git a/src/slskd/Core/Options.cs b/src/slskd/Core/Options.cs
index 306f9b87..e5f16b1e 100644
--- a/src/slskd/Core/Options.cs
+++ b/src/slskd/Core/Options.cs
@@ -2006,6 +2006,12 @@ namespace slskd
public class IntegrationOptions
{
/// <summary>
+ /// Gets webhook configuration.
+ /// </summary>
+ [Validate]
+ public Dictionary<string, WebhookOptions> Webhooks { get; init; } = [];
+
+ /// <summary>
/// Gets script configuration.
/// </summary>
[Validate]
@@ -2024,6 +2030,100 @@ namespace slskd
public PushbulletOptions Pushbullet { get; init; } = new PushbulletOptions();
/// <summary>
+ /// Webhook configuration.
+ /// </summary>
+ public class WebhookOptions
+ {
+ /// <summary>
+ /// Gets the list of Event types that trigger the webhook.
+ /// </summary>
+ [Enum(typeof(EventType))]
+ public string[] On { get; init; } = Array.Empty<string>();
+
+ /// <summary>
+ /// Gets details about the webhook call.
+ /// </summary>
+ [Validate]
+ public WebhookHttpOptions Call { get; init; } = new WebhookHttpOptions();
+
+ /// <summary>
+ /// Gets the time to wait before timing out, in milliseconds.
+ /// </summary>
+ [Range(500, int.MaxValue)]
+ public int Timeout { get; init; } = 5000;
+
+ /// <summary>
+ /// Gets the retry configuration.
+ /// </summary>
+ [Validate]
+ public RetryOptions Retry { get; init; } = new RetryOptions();
+ }
+
+ /// <summary>
+ /// Webhook HTTP options.
+ /// </summary>
+ public class WebhookHttpOptions : IValidatableObject
+ {
+ /// <summary>
+ /// Gets the fully qualified URL for the webhook.
+ /// </summary>
+ [NotNullOrWhiteSpace]
+ public string Url { get; init; }
+
+ /// <summary>
+ /// Gets the HTTP headers to include with the webhook.
+ /// </summary>
+ [Validate]
+ public WebhookHttpHeader[] Headers { get; init; } = [];
+
+ /// <summary>
+ /// Gets a value indicating whether HTTPS certificate errors should be ignored.
+ /// </summary>
+ public bool IgnoreCertificateErrors { get; init; } = false;
+
+ public IEnumerable<ValidationResult> Validate(ValidationContext validationContext)
+ {
+ var results = new List<ValidationResult>();
+
+ 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;
+ }
+ }
+
+ /// <summary>
+ /// Webhook HTTP header configuration.
+ /// </summary>
+ public class WebhookHttpHeader
+ {
+ /// <summary>
+ /// Gets the name of the header.
+ /// </summary>
+ [NotNullOrWhiteSpace]
+ public string Name { get; init; }
+
+ /// <summary>
+ /// Gets the header's value.
+ /// </summary>
+ public string Value { get; init; }
+ }
+
+ /// <summary>
+ /// Retry configuration.
+ /// </summary>
+ public class RetryOptions
+ {
+ /// <summary>
+ /// Gets the number of attempts to make before failing.
+ /// </summary>
+ [Range(1, int.MaxValue)]
+ public int Attempts { get; init; } = 1;
+ }
+
+ /// <summary>
/// Script configuration.
/// </summary>
public class ScriptOptions