diff options
Diffstat (limited to 'src')
| -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 { |
