aboutsummaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
authorJP Dillingham <jp@dillingham.me>2023-03-21 09:37:02 -0500
committerJP Dillingham <jp@dillingham.me>2023-03-21 09:37:02 -0500
commit199d24e28b860b3a042d2a569cdfebd066e41be0 (patch)
tree2e827ba6bded60757dd13745af2422334af02c4b
parentc82edcd0d4819f359df0c763dcf69a457d35f8a8 (diff)
downloadslskd-199d24e28b860b3a042d2a569cdfebd066e41be0.tar.gz
fetch agent config by InstanceName property instead of key
-rw-r--r--src/slskd/Relay/API/Hubs/RelayHub.cs19
1 files changed, 17 insertions, 2 deletions
diff --git a/src/slskd/Relay/API/Hubs/RelayHub.cs b/src/slskd/Relay/API/Hubs/RelayHub.cs
index 48d03c90..11410804 100644
--- a/src/slskd/Relay/API/Hubs/RelayHub.cs
+++ b/src/slskd/Relay/API/Hubs/RelayHub.cs
@@ -138,9 +138,24 @@ namespace slskd.Relay
/// <exception cref="UnauthorizedAccessException">Thrown when the challenge response is invalid.</exception>
public void Login(string agent, string challengeResponse)
{
- OptionsMonitor.CurrentValue.Relay.Agents.TryGetValue(agent, out var agentOptions);
+ bool TryGetAgentConfig(string agent, out Options.RelayOptions.RelayAgentConfigurationOptions options)
+ {
+ var agentOptions = OptionsMonitor.CurrentValue.Relay.Agents;
+ var found = agentOptions.Values.SingleOrDefault(a => a.InstanceName == agent);
+
+ if (found != default)
+ {
+ options = found;
+ return true;
+ }
+
+ Log.Warning("Unable to locate Agent config for '{Agent}' (configured Agents: {Agents})", agent, string.Join(", ", agentOptions.Values.Select(a => a.InstanceName)));
+
+ options = null;
+ return false;
+ }
- if (agentOptions == default)
+ if (!TryGetAgentConfig(agent, out var agentOptions))
{
Log.Warning("Unauthorized login attempt from unknown Agent {Agent} (connection {Id}) from {IP}", agent, Context.ConnectionId, RemoteIpAddress);
throw new UnauthorizedAccessException();