aboutsummaryrefslogtreecommitdiffstats
path: root/src
diff options
context:
space:
mode:
authorJP Dillingham <jp@dillingham.me>2026-02-14 16:02:49 -0600
committerJP Dillingham <jp@dillingham.me>2026-02-14 16:02:49 -0600
commite187c78dbc9587cf70a4fdd51bc6056eac65d0c0 (patch)
tree76e1dbe165494146691e146f2e5bbf6e6dfa288f /src
parent0db63596ea564976022a891d4b54815bdfbe4198 (diff)
downloadslskd-e187c78dbc9587cf70a4fdd51bc6056eac65d0c0.tar.gz
require gluetun url if enabled, auto negotiate auth
Diffstat (limited to 'src')
-rw-r--r--src/slskd/Core/Options.cs68
1 files changed, 36 insertions, 32 deletions
diff --git a/src/slskd/Core/Options.cs b/src/slskd/Core/Options.cs
index a0b5f954..cc4c367a 100644
--- a/src/slskd/Core/Options.cs
+++ b/src/slskd/Core/Options.cs
@@ -2308,22 +2308,31 @@ namespace slskd
/// <summary>
/// VPN options.
/// </summary>
- public class VpnOptions
+ public class VpnOptions : IValidatableObject
{
/// <summary>
/// Gets a value indicating whether the VPN integration is enabled.
/// </summary>
+ [Argument(default, "vpn")]
+ [EnvironmentVariable("VPN")]
+ [Description("enable VPN integration")]
[RequiresRestart]
public bool Enabled { get; init; } = false;
/// <summary>
- /// Gets a value indicating whether the configured VPN supports port forwarding.
+ /// Gets a value indicating whether the configured VPN supports dynamic port forwarding.
/// </summary>
+ [Argument(default, "vpn-port-forwarding")]
+ [EnvironmentVariable("VPN_PORT_FORWARDING")]
+ [Description("VPN supports dynamic port forwarding")]
public bool PortForwarding { get; init; } = false;
/// <summary>
/// Gets the rate at which to poll the configured VPN client for status updates, in milliseconds.
/// </summary>
+ [Argument(default, "vpn-polling-interval")]
+ [EnvironmentVariable("VPN_POLLING_INTERVAL")]
+ [Description("VPN client status polling interval")]
[Range(500, int.MaxValue)]
[RequiresRestart]
public int PollingInterval { get; init; } = 2500;
@@ -2334,10 +2343,19 @@ namespace slskd
[Validate]
public GluetunVpnOptions Gluetun { get; init; } = new GluetunVpnOptions();
+ public IEnumerable<ValidationResult> Validate(ValidationContext validationContext)
+ {
+ // as/if more VPN clients are added, update this logic to ensure that exactly one is configured
+ if (Enabled && string.IsNullOrWhiteSpace(Gluetun?.Url))
+ {
+ yield return new ValidationResult("VPN is enabled but no client is configured");
+ }
+ }
+
/// <summary>
/// Gluetun options.
/// </summary>
- public class GluetunVpnOptions : IValidatableObject
+ public class GluetunVpnOptions
{
/// <summary>
/// Gets the Gluetun integration version.
@@ -2351,58 +2369,44 @@ namespace slskd
/// <summary>
/// Gets the fully qualified root URL for the Gluetun control server.
/// </summary>
+ [Argument(default, "vpn-gluetun-url")]
+ [EnvironmentVariable("VPN_GLUETUN_URL")]
+ [Description("URL for gluetun control server")]
[NotNullOrWhiteSpace]
public string Url { get; init; }
/// <summary>
/// Gets the timeout for HTTP requests to the Gluetun control server, in milliseconds.
/// </summary>
+ [Argument(default, "vpn-gluetun-timeout")]
+ [EnvironmentVariable("VPN_GLUETUN_TIMEOUT")]
+ [Description("timeout for HTTP requests to gluetun control server")]
[Range(500, 10_000)]
public int Timeout { get; init; } = 1000;
/// <summary>
- /// Gets the Gluetun control server authentication method.
- /// </summary>
- [Enum(typeof(GluetunClientAuthenticationMethod), ignoreCase: true)]
- public string Auth { get; init; } = GluetunClientAuthenticationMethod.None.ToString();
-
- /// <summary>
/// Gets the username used for basic auth.
/// </summary>
+ [Argument(default, "vpn-gluetun-username")]
+ [EnvironmentVariable("VPN_GLUETUN_USERNAME")]
+ [Description("username for gluetun control server")]
public string Username { get; init; }
/// <summary>
/// Gets the password used for basic auth.
/// </summary>
+ [Argument(default, "vpn-gluetun-password")]
+ [EnvironmentVariable("VPN_GLUETUN_PASSWORD")]
+ [Description("password for gluetun control server")]
public string Password { get; init; }
/// <summary>
/// Gets the API key used for API key auth.
/// </summary>
+ [Argument(default, "vpn-gluetun-api-key")]
+ [EnvironmentVariable("VPN_GLUETUN_API_KEY")]
+ [Description("API key for gluetun control server")]
public string ApiKey { get; init; }
-
- public IEnumerable<ValidationResult> Validate(ValidationContext validationContext)
- {
- var results = new List<ValidationResult>();
-
- if (string.Equals(Auth, GluetunClientAuthenticationMethod.Basic.ToString(), StringComparison.OrdinalIgnoreCase))
- {
- if (string.IsNullOrWhiteSpace(Username) || string.IsNullOrWhiteSpace(Password))
- {
- results.Add(new ValidationResult("Username and Password are required when using Basic auth"));
- }
- }
-
- if (string.Equals(Auth, GluetunClientAuthenticationMethod.ApiKey.ToString(), StringComparison.OrdinalIgnoreCase))
- {
- if (string.IsNullOrWhiteSpace(ApiKey))
- {
- results.Add(new ValidationResult("ApiKey is required when using ApiKey auth"));
- }
- }
-
- return results;
- }
}
}