diff options
| author | JP Dillingham <jp@dillingham.me> | 2026-02-14 16:03:15 -0600 |
|---|---|---|
| committer | JP Dillingham <jp@dillingham.me> | 2026-02-14 16:03:15 -0600 |
| commit | b11904bb36d0ae868b69773ac5efe44646da4116 (patch) | |
| tree | 641c68f141a986b76ff05a9bf0fd93ca860245d2 /src/slskd/Integrations | |
| parent | e187c78dbc9587cf70a4fdd51bc6056eac65d0c0 (diff) | |
| download | slskd-b11904bb36d0ae868b69773ac5efe44646da4116.tar.gz | |
negotiate gluetun auth from config
Diffstat (limited to 'src/slskd/Integrations')
| -rw-r--r-- | src/slskd/Integrations/VPN/Clients/Gluetun.cs | 31 |
1 files changed, 5 insertions, 26 deletions
diff --git a/src/slskd/Integrations/VPN/Clients/Gluetun.cs b/src/slskd/Integrations/VPN/Clients/Gluetun.cs index 8c134599..d22c15f7 100644 --- a/src/slskd/Integrations/VPN/Clients/Gluetun.cs +++ b/src/slskd/Integrations/VPN/Clients/Gluetun.cs @@ -29,27 +29,6 @@ using Serilog; using static slskd.Options.IntegrationOptions.VpnOptions; /// <summary> -/// Gluetun VPN client authentication methods. -/// </summary> -public enum GluetunClientAuthenticationMethod -{ - /// <summary> - /// The Gluetun control server allows unauthenticated requests. - /// </summary> - None, - - /// <summary> - /// The Glueton control server is configured to use HTTP Basic authentication; username and password are required. - /// </summary> - Basic, - - /// <summary> - /// The Gluetun control server is configured to use API key authentication; apiKey is required. - /// </summary> - ApiKey, -} - -/// <summary> /// Gluetun VPN client. /// </summary> public class Gluetun : IVPNClient @@ -80,14 +59,14 @@ public class Gluetun : IVPNClient http.Timeout = TimeSpan.FromMilliseconds(Options.Timeout); - if (Options.Auth.Equals(GluetunClientAuthenticationMethod.Basic.ToString(), StringComparison.OrdinalIgnoreCase)) + if (!string.IsNullOrWhiteSpace(Options.ApiKey)) { - var creds = $"{Options.Username}:{Options.Password}".ToBase64(); - http.DefaultRequestHeaders.TryAddWithoutValidation("Authorization", $"Basic {creds}"); + http.DefaultRequestHeaders.TryAddWithoutValidation("X-API-Key", Options.ApiKey); } - else if (Options.Auth.Equals(GluetunClientAuthenticationMethod.ApiKey.ToString(), StringComparison.OrdinalIgnoreCase)) + else if (!string.IsNullOrWhiteSpace(Options.Username)) { - http.DefaultRequestHeaders.TryAddWithoutValidation("X-API-Key", Options.ApiKey); + var creds = $"{Options.Username}:{Options.Password}".ToBase64(); + http.DefaultRequestHeaders.TryAddWithoutValidation("Authorization", $"Basic {creds}"); } else { |
