aboutsummaryrefslogtreecommitdiffstats
path: root/src/slskd/Core/Options.cs
diff options
context:
space:
mode:
authorJP Dillingham <jp@dillingham.me>2022-10-30 18:50:33 -0500
committerGitHub <noreply@github.com>2022-10-30 18:50:33 -0500
commitea845d19fd3bf1acca08f1062526d1cfe90716f9 (patch)
tree238f9ebc9215dddb0517b2311372ce25f17aff85 /src/slskd/Core/Options.cs
parent5c19d4fd6a7eb98d83a5f8c7e2c3092cb2b3b62a (diff)
parent093763beaea0f891410f83febea67b22005bd406 (diff)
downloadslskd-ea845d19fd3bf1acca08f1062526d1cfe90716f9.tar.gz
Merge pull request #717 from slskd/tls
Rework API authentication
Diffstat (limited to 'src/slskd/Core/Options.cs')
-rw-r--r--src/slskd/Core/Options.cs26
1 files changed, 23 insertions, 3 deletions
diff --git a/src/slskd/Core/Options.cs b/src/slskd/Core/Options.cs
index f4ca99e5..a1591923 100644
--- a/src/slskd/Core/Options.cs
+++ b/src/slskd/Core/Options.cs
@@ -29,6 +29,7 @@ namespace slskd
using System.Text.RegularExpressions;
using FluentFTP;
using NetTools;
+ using slskd.Authentication;
using slskd.Configuration;
using slskd.Cryptography;
using slskd.Network;
@@ -296,7 +297,7 @@ namespace slskd
{
var results = new List<ValidationResult>();
- if (InstanceName == "local" && Network.OperationMode.ToEnum<OperationMode>() == OperationMode.Agent)
+ if (InstanceName == "local" && Network.Mode.ToEnum<OperationMode>() == OperationMode.Agent)
{
results.Add(new ValidationResult("Instance name must be something other than 'local' when operating in Network Agent mode"));
}
@@ -395,7 +396,7 @@ namespace slskd
[Description("network operation mode; controller, agent")]
[RequiresRestart]
[Enum(typeof(OperationMode))]
- public string OperationMode { get; init; } = slskd.Network.OperationMode.Controller.ToString().ToLowerInvariant();
+ public string Mode { get; init; } = slskd.Network.OperationMode.Controller.ToString().ToLowerInvariant();
/// <summary>
/// Gets the controller configuration.
@@ -409,7 +410,7 @@ namespace slskd
public IEnumerable<ValidationResult> Validate(ValidationContext validationContext)
{
- var mode = OperationMode.ToEnum<OperationMode>();
+ var mode = Mode.ToEnum<OperationMode>();
var results = new List<ValidationResult>();
var modeResults = new List<ValidationResult>();
@@ -461,10 +462,22 @@ namespace slskd
public bool IgnoreCertificateErrors { get; init; } = false;
/// <summary>
+ /// Gets the controller API key.
+ /// </summary>
+ [Argument(default, "controller-api-key")]
+ [EnvironmentVariable("CONTROLLER_API_KEY")]
+ [Description("controller api key")]
+ [StringLength(255, MinimumLength = 16)]
+ [NotNullOrWhiteSpace]
+ [Secret]
+ public string ApiKey { get; init; }
+
+ /// <summary>
/// Gets the controller secret.
/// </summary>
[Argument(default, "controller-secret")]
[EnvironmentVariable("CONTROLLER_SECRET")]
+ [Description("shared secret")]
[StringLength(255, MinimumLength = 16)]
[NotNullOrWhiteSpace]
[Secret]
@@ -1412,6 +1425,13 @@ namespace slskd
public string Key { get; init; }
/// <summary>
+ /// Gets the role for the key.
+ /// </summary>
+ [Description("user role for the key; readonly, readwrite, administrator")]
+ [Enum(typeof(Role))]
+ public string Role { get; init; } = slskd.Authentication.Role.ReadOnly.ToString();
+
+ /// <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")]