mirror of
https://github.com/Stone-Red-Code/RemoteExec.git
synced 2026-09-04 09:06:20 +02:00
Add authentication and improve server side configuration
This commit is contained in:
@@ -22,21 +22,13 @@ public partial class RemoteExecutor : IAsyncDisposable
|
||||
private CancellationTokenSource distributorCts = new();
|
||||
private Task? distributorTask;
|
||||
|
||||
private readonly RemoteExecutorOptions options = new();
|
||||
private readonly RemoteExecutorOptions options;
|
||||
private readonly ILogger logger;
|
||||
|
||||
private bool disposedValue;
|
||||
|
||||
public event EventHandler<ServerMetricsUpdatedEventArgs>? MetricsUpdated;
|
||||
|
||||
public RemoteExecutor(string url) : this([url], new RemoteExecutorOptions(), NullLogger.Instance)
|
||||
{
|
||||
}
|
||||
|
||||
public RemoteExecutor(string url, ILogger logger) : this([url], new RemoteExecutorOptions(), logger)
|
||||
{
|
||||
}
|
||||
|
||||
public RemoteExecutor(string url, Action<RemoteExecutorOptions> configure) : this([url], NullLogger.Instance, configure)
|
||||
{
|
||||
}
|
||||
@@ -45,14 +37,6 @@ public partial class RemoteExecutor : IAsyncDisposable
|
||||
{
|
||||
}
|
||||
|
||||
public RemoteExecutor(string[] urls) : this(urls, new RemoteExecutorOptions(), NullLogger.Instance)
|
||||
{
|
||||
}
|
||||
|
||||
public RemoteExecutor(string[] urls, ILogger logger) : this(urls, new RemoteExecutorOptions(), logger)
|
||||
{
|
||||
}
|
||||
|
||||
public RemoteExecutor(string[] urls, Action<RemoteExecutorOptions> configure) : this(urls, NullLogger.Instance, configure)
|
||||
{
|
||||
}
|
||||
@@ -81,13 +65,21 @@ public partial class RemoteExecutor : IAsyncDisposable
|
||||
|
||||
private void InitializeServers(string[] urls)
|
||||
{
|
||||
if (string.IsNullOrWhiteSpace(options.ApiKey))
|
||||
{
|
||||
throw new InvalidOperationException("API Key is required. Configure it in RemoteExecutorOptions.");
|
||||
}
|
||||
|
||||
foreach (string url in urls)
|
||||
{
|
||||
Uri baseUri = new(url);
|
||||
Uri signalRUri = new(baseUri, "/remote");
|
||||
|
||||
HubConnection connection = new HubConnectionBuilder()
|
||||
.WithUrl(signalRUri)
|
||||
.WithUrl(signalRUri, httpOptions =>
|
||||
{
|
||||
httpOptions.Headers["X-API-Key"] = options.ApiKey;
|
||||
})
|
||||
.ConfigureLogging(logging =>
|
||||
{
|
||||
_ = logging.AddProvider(new RemoteExecLoggerProvider(logger));
|
||||
@@ -99,6 +91,8 @@ public partial class RemoteExecutor : IAsyncDisposable
|
||||
BaseAddress = baseUri
|
||||
};
|
||||
|
||||
httpClient.DefaultRequestHeaders.Add("X-API-Key", options.ApiKey);
|
||||
|
||||
ServerConnection serverConnection = new ServerConnection(connection, httpClient);
|
||||
servers.Add(serverConnection);
|
||||
serverAssignedTasks[serverConnection] = new ConcurrentDictionary<Guid, PendingTask>();
|
||||
|
||||
@@ -6,6 +6,8 @@ public class RemoteExecutorOptions
|
||||
{
|
||||
public ILoadBalancingStrategy Strategy { get; set; } = new ResourceAwareStrategy();
|
||||
|
||||
public string ApiKey { get; set; } = string.Empty;
|
||||
|
||||
// How long to wait for a result before throwing a TimeoutException
|
||||
public TimeSpan ExecutionTimeout { get; set; } = TimeSpan.FromMinutes(5);
|
||||
|
||||
|
||||
Reference in New Issue
Block a user