aboutsummaryrefslogtreecommitdiffstats
path: root/src/slskd/Core/Options.cs
diff options
context:
space:
mode:
Diffstat (limited to 'src/slskd/Core/Options.cs')
-rw-r--r--src/slskd/Core/Options.cs85
1 files changed, 85 insertions, 0 deletions
diff --git a/src/slskd/Core/Options.cs b/src/slskd/Core/Options.cs
index 4c146d32..7debb525 100644
--- a/src/slskd/Core/Options.cs
+++ b/src/slskd/Core/Options.cs
@@ -201,6 +201,12 @@ namespace slskd
public string ConfigurationFile { get; init; } = Program.DefaultConfigurationFile;
/// <summary>
+ /// Gets network options.
+ /// </summary>
+ [Validate]
+ public NetworkOptions Network { get; init; } = new NetworkOptions();
+
+ /// <summary>
/// Gets directory options.
/// </summary>
[Validate]
@@ -348,6 +354,85 @@ namespace slskd
}
/// <summary>
+ /// Network options.
+ /// </summary>
+ public class NetworkOptions : IValidatableObject
+ {
+ /// <summary>
+ /// Gets the application operation mode.
+ /// </summary>
+ [Argument('m', "network-operation-mode")]
+ [EnvironmentVariable("NETWORK_OPERATION_MODE")]
+ [Description("network operation mode; controller, agent")]
+ [RequiresRestart]
+ [Enum(typeof(NetworkOperationMode))]
+ public string OperationMode { get; init; } = NetworkOperationMode.Controller.ToString().ToLowerInvariant();
+
+ /// <summary>
+ /// Gets the controller configuration.
+ /// </summary>
+ public NetworkControllerConfigurationOptions Controller { get; init; } = new NetworkControllerConfigurationOptions();
+
+ /// <summary>
+ /// Gets the agent configuration.
+ /// </summary>
+ public Dictionary<string, NetworkAgentConfigurationOptions> Agents { get; init; } = new();
+
+ public IEnumerable<ValidationResult> Validate(ValidationContext validationContext)
+ {
+ var results = new List<ValidationResult>();
+ var controllerResults = new List<ValidationResult>();
+ var agentResults = new List<ValidationResult>();
+
+ if (OperationMode.ToEnum<NetworkOperationMode>() == NetworkOperationMode.Agent && !Validator.TryValidateObject(Controller, validationContext, controllerResults))
+ {
+ results.AddRange(controllerResults);
+ }
+ else if (!Validator.TryValidateObject(Agents, validationContext, results))
+ {
+ results.AddRange(agentResults);
+ }
+
+ return results;
+ }
+
+ /// <summary>
+ /// Network controller configuration options.
+ /// </summary>
+ public class NetworkControllerConfigurationOptions
+ {
+ /// <summary>
+ /// Gets the controller address.
+ /// </summary>
+ [Argument(default, "controller-address")]
+ [EnvironmentVariable("CONTROLLER_ADDRESS")]
+ public string Address { get; init; }
+
+ /// <summary>
+ /// Gets the controller secret.
+ /// </summary>
+ [Argument(default, "controller-secret")]
+ [EnvironmentVariable("CONTROLLER_SECRET")]
+ [StringLength(255, MinimumLength = 32)]
+ [Secret]
+ public string Secret { get; init; }
+ }
+
+ /// <summary>
+ /// Network agent configuration options.
+ /// </summary>
+ public class NetworkAgentConfigurationOptions
+ {
+ /// <summary>
+ /// Gets the agent secret.
+ /// </summary>
+ [StringLength(255, MinimumLength = 32)]
+ [Secret]
+ public string Secret { get; init; }
+ }
+ }
+
+ /// <summary>
/// Directory options.
/// </summary>
public class DirectoriesOptions