diff options
| author | JP Dillingham <jp@dillingham.me> | 2022-10-04 19:36:10 -0500 |
|---|---|---|
| committer | JP Dillingham <jp@dillingham.me> | 2022-10-04 19:36:10 -0500 |
| commit | 6155ff6cabf276ea084e5641b8a8ea1abe07b81c (patch) | |
| tree | 946e2b46e8328ab4d18db25a5da31310d415b592 /src/slskd/Core/Options.cs | |
| parent | 6e89d7d39b35735857f8f88555b6efe440b54b1c (diff) | |
| download | slskd-6155ff6cabf276ea084e5641b8a8ea1abe07b81c.tar.gz | |
add network options
Diffstat (limited to 'src/slskd/Core/Options.cs')
| -rw-r--r-- | src/slskd/Core/Options.cs | 85 |
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 |
