diff options
| author | JP Dillingham <jp@dillingham.me> | 2025-12-13 11:48:45 -0600 |
|---|---|---|
| committer | JP Dillingham <jp@dillingham.me> | 2025-12-13 11:48:45 -0600 |
| commit | 8fadf7bdd6b253895a273fe6ffc8bd4943f07ee9 (patch) | |
| tree | 08e64d64b9e6c2b37477b00ccbb7d9aff5c22cbe /src | |
| parent | 99d8285e53764420cfb44147ea7bc069d1729ca0 (diff) | |
| download | slskd-8fadf7bdd6b253895a273fe6ffc8bd4943f07ee9.tar.gz | |
tweak validation
Diffstat (limited to 'src')
| -rw-r--r-- | src/slskd/Core/Options.cs | 14 |
1 files changed, 12 insertions, 2 deletions
diff --git a/src/slskd/Core/Options.cs b/src/slskd/Core/Options.cs index ced7c96f..43363654 100644 --- a/src/slskd/Core/Options.cs +++ b/src/slskd/Core/Options.cs @@ -1944,6 +1944,8 @@ namespace slskd /// Gets the primary API key. Defaults to 'Administrator' role and CIDR '0.0.0.0/0,::/0'. /// role and CIDR can be supplied by prefixing the key with 'role=[role];cidr=[cidrs];[key]'. /// </summary> + [Argument('k', "api-key")] + [EnvironmentVariable("API_KEY")] [Description("Administrative API key value")] [Secret] [RequiresRestart] @@ -1957,7 +1959,6 @@ namespace slskd public IEnumerable<ValidationResult> Validate(ValidationContext validationContext) { - // TODO: test me! var results = new List<ValidationResult>(); if (string.IsNullOrWhiteSpace(ApiKey)) @@ -1976,15 +1977,24 @@ namespace slskd { results.Add(new ValidationResult("API key must be between 16 and 255 characters")); } + + return results; } + /* + if multiple tuples are supplied, verify that: + + * if a tuple starts with 'role=', it's defining a role and it must match one of the Role enum values + * if a tuple starts with 'cidr=', it's defining a list of CIDRs which need to be valid + * if a tuple doesn't start with a prefix, it's the API key itself and it must be between 16 and 255 characters + */ foreach (var tuple in tuples) { if (tuple.StartsWith("role=", StringComparison.OrdinalIgnoreCase)) { var role = tuple.Split('=').LastOrDefault(); - if (!Enum.TryParse(typeof(Role), role, out _)) + if (!Enum.TryParse(typeof(Role), value: role, ignoreCase: true, out _)) { results.Add(new ValidationResult($"API key role must be one of: {string.Join(", ", Enum.GetNames(typeof(Role)))}")); } |
