From f585c9c63c7d97a751a0f8d4658696053c3d0262 Mon Sep 17 00:00:00 2001 From: JP Dillingham Date: Sun, 30 Oct 2022 13:31:54 -0500 Subject: add api key --- src/slskd/Core/Options.cs | 18 +++++++++++++++--- 1 file changed, 15 insertions(+), 3 deletions(-) (limited to 'src/slskd/Core/Options.cs') diff --git a/src/slskd/Core/Options.cs b/src/slskd/Core/Options.cs index f4ca99e5..765ba6e9 100644 --- a/src/slskd/Core/Options.cs +++ b/src/slskd/Core/Options.cs @@ -296,7 +296,7 @@ namespace slskd { var results = new List(); - if (InstanceName == "local" && Network.OperationMode.ToEnum() == OperationMode.Agent) + if (InstanceName == "local" && Network.Mode.ToEnum() == OperationMode.Agent) { results.Add(new ValidationResult("Instance name must be something other than 'local' when operating in Network Agent mode")); } @@ -395,7 +395,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(); /// /// Gets the controller configuration. @@ -409,7 +409,7 @@ namespace slskd public IEnumerable Validate(ValidationContext validationContext) { - var mode = OperationMode.ToEnum(); + var mode = Mode.ToEnum(); var results = new List(); var modeResults = new List(); @@ -460,11 +460,23 @@ namespace slskd [Description("ignore controller certificate errors")] public bool IgnoreCertificateErrors { get; init; } = false; + /// + /// Gets the controller API key. + /// + [Argument(default, "controller-api-key")] + [EnvironmentVariable("CONTROLLER_API_KEY")] + [Description("controller api key")] + [StringLength(255, MinimumLength = 16)] + [NotNullOrWhiteSpace] + [Secret] + public string ApiKey { get; init; } + /// /// Gets the controller secret. /// [Argument(default, "controller-secret")] [EnvironmentVariable("CONTROLLER_SECRET")] + [Description("shared secret")] [StringLength(255, MinimumLength = 16)] [NotNullOrWhiteSpace] [Secret] -- cgit v1.2.3 From 8d1ae7b3357cc7d10b86940d98b22d072bbdbe8c Mon Sep 17 00:00:00 2001 From: JP Dillingham Date: Sun, 30 Oct 2022 15:18:31 -0500 Subject: add Role to API key options --- config/slskd.example.yml | 1 + src/slskd/Core/Options.cs | 8 ++++++++ 2 files changed, 9 insertions(+) (limited to 'src/slskd/Core/Options.cs') diff --git a/config/slskd.example.yml b/config/slskd.example.yml index 5939fb58..10c59288 100644 --- a/config/slskd.example.yml +++ b/config/slskd.example.yml @@ -97,6 +97,7 @@ # api_keys: # my_api_key: # key: +# role: readonly # readonly, readwrite, administrator # cidr: 0.0.0.0/0,::/0 # logger: # loki: ~ diff --git a/src/slskd/Core/Options.cs b/src/slskd/Core/Options.cs index 765ba6e9..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; @@ -1423,6 +1424,13 @@ namespace slskd [Secret] public string Key { get; init; } + /// + /// Gets the role for the key. + /// + [Description("user role for the key; readonly, readwrite, administrator")] + [Enum(typeof(Role))] + public string Role { get; init; } = slskd.Authentication.Role.ReadOnly.ToString(); + /// /// Gets the comma separated list of CIDRs that are authorized to use the key. /// -- cgit v1.2.3