From ae0c7e3d0e52e0e301f864bb4f66cffe4f762288 Mon Sep 17 00:00:00 2001 From: JP Dillingham Date: Sun, 18 Jul 2021 17:42:15 -0500 Subject: add Enabled and validator for ProxyOptions --- src/slskd/Options.cs | 27 ++++++++++++++++++++++++++- 1 file changed, 26 insertions(+), 1 deletion(-) (limited to 'src') diff --git a/src/slskd/Options.cs b/src/slskd/Options.cs index f93e5d4a..b2476364 100644 --- a/src/slskd/Options.cs +++ b/src/slskd/Options.cs @@ -407,8 +407,16 @@ namespace slskd /// /// Connection proxy options. /// - public class ProxyOptions + public class ProxyOptions : IValidatableObject { + /// + /// Gets a value indicating whether the proxy is enabled. + /// + [Argument(default, "slsk-proxy")] + [EnvironmentVariable("SLSK_PROXY_ENABLED")] + [Description("enable connection proxy")] + public bool Enabled { get; private set; } = false; + /// /// Gets the proxy address. /// @@ -444,6 +452,23 @@ namespace slskd [Description("connection proxy password")] [StringLength(255, MinimumLength = 1)] public string Password { get; private set; } + + public IEnumerable Validate(ValidationContext validationContext) + { + var results = new List(); + + if (Enabled && string.IsNullOrWhiteSpace(Address)) + { + results.Add(new ValidationResult($"The Enabled field is true, but no Address has been specified.")); + } + + if (Enabled && !Port.HasValue) + { + results.Add(new ValidationResult($"The Enabled field is true, but no Port has been specified.")); + } + + return results; + } } } -- cgit v1.2.3