diff options
| author | JP Dillingham <jpdillingham@gmail.com> | 2021-07-18 17:42:15 -0500 |
|---|---|---|
| committer | JP Dillingham <jpdillingham@gmail.com> | 2021-07-18 17:42:15 -0500 |
| commit | ae0c7e3d0e52e0e301f864bb4f66cffe4f762288 (patch) | |
| tree | bb0b3a0806cd16c8ab51754e25478be2fdebbdc5 /src | |
| parent | aa496feb60f34e7fab5d16314b2852dd640e998a (diff) | |
| download | slskd-ae0c7e3d0e52e0e301f864bb4f66cffe4f762288.tar.gz | |
add Enabled and validator for ProxyOptions
Diffstat (limited to 'src')
| -rw-r--r-- | src/slskd/Options.cs | 27 |
1 files changed, 26 insertions, 1 deletions
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,9 +407,17 @@ namespace slskd /// <summary> /// Connection proxy options. /// </summary> - public class ProxyOptions + public class ProxyOptions : IValidatableObject { /// <summary> + /// Gets a value indicating whether the proxy is enabled. + /// </summary> + [Argument(default, "slsk-proxy")] + [EnvironmentVariable("SLSK_PROXY_ENABLED")] + [Description("enable connection proxy")] + public bool Enabled { get; private set; } = false; + + /// <summary> /// Gets the proxy address. /// </summary> [Argument(default, "slsk-proxy-address")] @@ -444,6 +452,23 @@ namespace slskd [Description("connection proxy password")] [StringLength(255, MinimumLength = 1)] public string Password { get; private set; } + + public IEnumerable<ValidationResult> Validate(ValidationContext validationContext) + { + var results = new List<ValidationResult>(); + + 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; + } } } |
