diff options
| author | JP Dillingham <jpdillingham@gmail.com> | 2021-11-08 18:56:26 -0600 |
|---|---|---|
| committer | JP Dillingham <jpdillingham@gmail.com> | 2021-11-08 18:56:26 -0600 |
| commit | 7d936c12da1587961c22caf5dded805bcbba53de (patch) | |
| tree | 1b49aa2e41a2d00164f373585798f4d9f486bf3d /src | |
| parent | d0ef56835155e0c93393eee660297cddfb3f9cca (diff) | |
| download | slskd-7d936c12da1587961c22caf5dded805bcbba53de.tar.gz | |
tweak options for yaml compatibility
Diffstat (limited to 'src')
| -rw-r--r-- | src/slskd/Integrations/FTP/FTPClientFactory.cs | 8 | ||||
| -rw-r--r-- | src/slskd/Integrations/FTP/FTPService.cs | 20 | ||||
| -rw-r--r-- | src/slskd/Options.cs | 29 | ||||
| -rw-r--r-- | src/slskd/Transfers/API/Controllers/TransfersController.cs | 2 |
4 files changed, 32 insertions, 27 deletions
diff --git a/src/slskd/Integrations/FTP/FTPClientFactory.cs b/src/slskd/Integrations/FTP/FTPClientFactory.cs index e9ee0721..2e41ab03 100644 --- a/src/slskd/Integrations/FTP/FTPClientFactory.cs +++ b/src/slskd/Integrations/FTP/FTPClientFactory.cs @@ -37,7 +37,7 @@ namespace slskd.Integrations.FTP OptionsMonitor = optionsMonitor; } - private FTPOptions FTPOptions => OptionsMonitor.CurrentValue.Integration.FTP; + private FtpOptions FtpOptions => OptionsMonitor.CurrentValue.Integration.Ftp; private IOptionsMonitor<Options> OptionsMonitor { get; set; } /// <summary> @@ -46,9 +46,9 @@ namespace slskd.Integrations.FTP /// <returns>The created instance.</returns> public FtpClient CreateFtpClient() { - var client = new FtpClient(FTPOptions.Address, FTPOptions.Port, FTPOptions.Username, FTPOptions.Password); - client.EncryptionMode = ParseFtpEncryptionMode(FTPOptions.EncryptionMode); - client.ValidateAnyCertificate = FTPOptions.IgnoreCertificateErrors; + var client = new FtpClient(FtpOptions.Address, FtpOptions.Port, FtpOptions.Username, FtpOptions.Password); + client.EncryptionMode = ParseFtpEncryptionMode(FtpOptions.EncryptionMode); + client.ValidateAnyCertificate = FtpOptions.IgnoreCertificateErrors; return client; } diff --git a/src/slskd/Integrations/FTP/FTPService.cs b/src/slskd/Integrations/FTP/FTPService.cs index becf1a12..dd1b340f 100644 --- a/src/slskd/Integrations/FTP/FTPService.cs +++ b/src/slskd/Integrations/FTP/FTPService.cs @@ -49,7 +49,7 @@ namespace slskd.Integrations.FTP } private IFTPClientFactory Factory { get; set; } - private FTPOptions FTPOptions => OptionsMonitor.CurrentValue.Integration.FTP; + private FtpOptions FtpOptions => OptionsMonitor.CurrentValue.Integration.Ftp; private ILogger<FTPService> Log { get; set; } private IOptionsMonitor<Options> OptionsMonitor { get; } @@ -60,7 +60,7 @@ namespace slskd.Integrations.FTP /// <returns>The operation context.</returns> public async Task UploadAsync(string filename) { - if (!FTPOptions.Enabled) + if (!FtpOptions.Enabled) { Log.LogDebug("Skipping FTP upload of {filename}; FTP integration is disabled"); return; @@ -74,7 +74,7 @@ namespace slskd.Integrations.FTP task: () => AttemptUploadAsync(filename), isRetryable: (attempts, ex) => true, onFailure: (attempts, ex) => Log.LogInformation("Failed attempt {Attempts} to upload {Filename} to FTP: {Message}", attempts, fileAndParentDirectory, ex.Message), - maxAttempts: FTPOptions.RetryAttempts, + maxAttempts: FtpOptions.RetryAttempts, maxDelayInMilliseconds: 30000); } catch (RetryException ex) @@ -84,7 +84,7 @@ namespace slskd.Integrations.FTP } catch (Exception ex) { - Log.LogWarning("Failed to upload {Filename} to FTP after {Attempts} attempts: {Message}", fileAndParentDirectory, FTPOptions.RetryAttempts, ex.Message); + Log.LogWarning("Failed to upload {Filename} to FTP after {Attempts} attempts: {Message}", fileAndParentDirectory, FtpOptions.RetryAttempts, ex.Message); throw; } } @@ -92,15 +92,15 @@ namespace slskd.Integrations.FTP private async Task AttemptUploadAsync(string filename) { var fileAndParentDirectory = GetFileAndParentDirectoryFromFilename(filename); - var remotePath = FTPOptions.RemotePath.TrimEnd('/').TrimEnd('\\'); + var remotePath = FtpOptions.RemotePath.TrimEnd('/').TrimEnd('\\'); var remoteFilename = $"{remotePath}/{fileAndParentDirectory}"; - var existsMode = FTPOptions.OverwriteExisting ? FtpRemoteExists.Overwrite : FtpRemoteExists.Skip; + var existsMode = FtpOptions.OverwriteExisting ? FtpRemoteExists.Overwrite : FtpRemoteExists.Skip; using var client = Factory.CreateFtpClient(); var timeoutTaskCompletionSource = new TaskCompletionSource<bool>(TaskCreationOptions.RunContinuationsAsynchronously); - using var timeoutCancellationTokenSource = new CancellationTokenSource(TimeSpan.FromMilliseconds(FTPOptions.ConnectionTimeout)); + using var timeoutCancellationTokenSource = new CancellationTokenSource(TimeSpan.FromMilliseconds(FtpOptions.ConnectionTimeout)); using var timeoutCancellationTokenRegistration = timeoutCancellationTokenSource.Token.Register(() => timeoutTaskCompletionSource.TrySetResult(true)); @@ -111,7 +111,7 @@ namespace slskd.Integrations.FTP if (completedTask == timeoutTaskCompletionSource.Task) { - throw new TimeoutException($"Failed to connect to server after {FTPOptions.ConnectionTimeout}ms"); + throw new TimeoutException($"Failed to connect to server after {FtpOptions.ConnectionTimeout}ms"); } if (connectTask.Exception != null) @@ -119,7 +119,7 @@ namespace slskd.Integrations.FTP throw connectTask.Exception; } - Log.LogInformation("Uploading {Filename} to FTP {Address}:{Port} as {RemoteFilename}", fileAndParentDirectory, FTPOptions.Address, FTPOptions.Port, remoteFilename); + Log.LogInformation("Uploading {Filename} to FTP {Address}:{Port} as {RemoteFilename}", fileAndParentDirectory, FtpOptions.Address, FtpOptions.Port, remoteFilename); var status = await client.UploadFileAsync(filename, remoteFilename, existsMode, createRemoteDir: true); if (status == FtpStatus.Failed) @@ -127,7 +127,7 @@ namespace slskd.Integrations.FTP throw new FtpException("FTP client reported a failed transfer"); } - Log.LogInformation("FTP upload of {Filename} to {Address}:{Port} complete", fileAndParentDirectory, FTPOptions.Address, FTPOptions.Port); + Log.LogInformation("FTP upload of {Filename} to {Address}:{Port} complete", fileAndParentDirectory, FtpOptions.Address, FtpOptions.Port); } private string GetFileAndParentDirectoryFromFilename(string filename) diff --git a/src/slskd/Options.cs b/src/slskd/Options.cs index 875b3e69..71c341e9 100644 --- a/src/slskd/Options.cs +++ b/src/slskd/Options.cs @@ -34,6 +34,7 @@ namespace slskd using Soulseek.Diagnostics; using Utility.CommandLine; using Utility.EnvironmentVariables; + using YamlDotNet.Serialization; /// <summary> /// Disambiguates options derived at startup from options that may update at run time. @@ -92,6 +93,7 @@ namespace slskd [Argument('v', "version")] [Description("display version information")] [Obsolete("Used only for documentation; see Program for actual implementation")] + [YamlIgnore] public bool ShowVersion { get; private set; } = false; /// <summary> @@ -100,6 +102,7 @@ namespace slskd [Argument('h', "help")] [Description("display command line usage")] [Obsolete("Used only for documentation; see Program for actual implementation")] + [YamlIgnore] public bool ShowHelp { get; private set; } = false; /// <summary> @@ -108,6 +111,7 @@ namespace slskd [Argument('e', "envars")] [Description("display environment variables")] [Obsolete("Used only for documentation; see Program for actual implementation")] + [YamlIgnore] public bool ShowEnvironmentVariables { get; private set; } = false; /// <summary> @@ -116,19 +120,10 @@ namespace slskd [Argument('g', "generate-cert")] [Description("generate X509 certificate and password for HTTPs")] [Obsolete("Used only for documentation; see Program for actual implementation")] + [YamlIgnore] public bool GenerateCertificate { get; private set; } = false; /// <summary> - /// Gets the path where application data is saved. - /// </summary> - [Argument(default, "appdir")] - [EnvironmentVariable("APP_DIR")] - [Description("path where application data is saved")] - [Obsolete("Used only for documentation; see Program for actual implementation")] - public string AppDirectory { get; private set; } = Program.DefaultAppDirectory; - - - /// <summary> /// Gets a value indicating whether the application should run in debug mode. /// </summary> [Argument('d', "debug")] @@ -192,6 +187,16 @@ namespace slskd public string InstanceName { get; private set; } = "default"; /// <summary> + /// Gets the path where application data is saved. + /// </summary> + [Argument(default, "app")] + [EnvironmentVariable("APP_DIR")] + [Description("path where application data is saved")] + [Obsolete("Used only for documentation; see Program for actual implementation")] + [YamlIgnore] + public string AppDirectory { get; private set; } = Program.DefaultAppDirectory; + + /// <summary> /// Gets directory options. /// </summary> [Validate] @@ -828,7 +833,7 @@ namespace slskd /// Gets FTP options. /// </summary> [Validate] - public FTPOptions FTP { get; private set; } = new FTPOptions(); + public FtpOptions Ftp { get; private set; } = new FtpOptions(); /// <summary> /// Gets Pushbullet options. @@ -839,7 +844,7 @@ namespace slskd /// <summary> /// FTP options. /// </summary> - public class FTPOptions : IValidatableObject + public class FtpOptions : IValidatableObject { /// <summary> /// Gets a value indicating whether the FTP integration is enabled. diff --git a/src/slskd/Transfers/API/Controllers/TransfersController.cs b/src/slskd/Transfers/API/Controllers/TransfersController.cs index b912bbda..12d6bfcf 100644 --- a/src/slskd/Transfers/API/Controllers/TransfersController.cs +++ b/src/slskd/Transfers/API/Controllers/TransfersController.cs @@ -137,7 +137,7 @@ namespace slskd.Transfers.API MoveFile(request.Filename, Options.Directories.Incomplete, Options.Directories.Downloads); - if (Options.Integration.FTP.Enabled) + if (Options.Integration.Ftp.Enabled) { _ = FTP.UploadAsync(request.Filename.ToLocalFilename(Options.Directories.Downloads)); } |
