aboutsummaryrefslogtreecommitdiffstats
path: root/src/slskd/Core/Options.cs
diff options
context:
space:
mode:
authorJP Dillingham <jp@dillingham.me>2024-11-08 08:25:26 -0600
committerGitHub <noreply@github.com>2024-11-08 08:25:26 -0600
commitd689ac95d053b0b0d60c0ceb882d10332a40a8cb (patch)
tree2815c3d9eea7a9d27ca1e207c2879235232a7f18 /src/slskd/Core/Options.cs
parentfd179ee6c888f03ffe26288c906a53961808352f (diff)
parente7aefd66f1992dcecd9454df0771e1f29fae2b1d (diff)
downloadslskd-d689ac95d053b0b0d60c0ceb882d10332a40a8cb.tar.gz
Merge branch 'master' into noop
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