diff options
| author | JP Dillingham <jp@dillingham.me> | 2023-01-05 19:22:48 -0600 |
|---|---|---|
| committer | JP Dillingham <jp@dillingham.me> | 2023-01-05 19:22:48 -0600 |
| commit | 2d1b24164357af9f15ee0629979035d7c365e94a (patch) | |
| tree | 4dc92b6c05ca2b37eae0d4f6d473307722647d71 /src | |
| parent | 23c9d2fda9125f8bc0b35810521f2d53eead6be6 (diff) | |
| download | slskd-2d1b24164357af9f15ee0629979035d7c365e94a.tar.gz | |
add agent CIDR
Diffstat (limited to 'src')
| -rw-r--r-- | src/slskd/Core/Options.cs | 35 |
1 files changed, 33 insertions, 2 deletions
diff --git a/src/slskd/Core/Options.cs b/src/slskd/Core/Options.cs index bc6f14a6..063da9e6 100644 --- a/src/slskd/Core/Options.cs +++ b/src/slskd/Core/Options.cs @@ -513,15 +513,46 @@ namespace slskd /// <summary> /// Relay agent configuration options. /// </summary> - public class RelayAgentConfigurationOptions + public class RelayAgentConfigurationOptions : IValidatableObject { /// <summary> /// Gets the agent secret. /// </summary> + [Description("shared secret for this agent")] [StringLength(255, MinimumLength = 16)] [NotNullOrWhiteSpace] [Secret] public string Secret { get; init; } + + /// <summary> + /// Gets the comma separated list of CIDRs that are authorized to connect as this agent. + /// </summary> + [Description("optional; comma separated list of CIDRs that are authorized to connect as this agent")] + public string Cidr { get; init; } = "0.0.0.0/0,::/0"; + + /// <summary> + /// Extended validation. + /// </summary> + /// <param name="validationContext"></param> + /// <returns></returns> + public IEnumerable<ValidationResult> Validate(ValidationContext validationContext) + { + var results = new List<ValidationResult>(); + + foreach (var cidr in Cidr.Split(',')) + { + try + { + _ = IPAddressRange.Parse(cidr); + } + catch (Exception ex) + { + results.Add(new ValidationResult($"CIDR {cidr} is invalid: {ex.Message}")); + } + } + + return results; + } } } @@ -1476,7 +1507,7 @@ namespace slskd /// <summary> /// Gets the comma separated list of CIDRs that are authorized to use the key. /// </summary> - [Description("An optional comma separated list of CIDRs that are authorized to use the key")] + [Description("optional; comma separated list of CIDRs that are authorized to use the key")] public string Cidr { get; init; } = "0.0.0.0/0,::/0"; /// <summary> |
