aboutsummaryrefslogtreecommitdiffstats
path: root/src
diff options
context:
space:
mode:
authorJP Dillingham <jpdillingham@gmail.com>2021-07-12 20:41:44 -0500
committerJP Dillingham <jpdillingham@gmail.com>2021-07-12 20:41:44 -0500
commit99954b32edd7fb6e4edc69557649758360c03647 (patch)
tree3288d094c7487eb0608c4819b7af32abe62f2dcb /src
parent07133bd2a51acf5275578b7d4167dd3b9f689d7f (diff)
parent373b2974614171f5492d2e36899a7c0a67fa4395 (diff)
downloadslskd-99954b32edd7fb6e4edc69557649758360c03647.tar.gz
Merge branch 'options' of https://github.com/slskd/slskd into options
Diffstat (limited to 'src')
-rw-r--r--src/slskd/Application/Management/API/Controllers/OptionsController.cs8
-rw-r--r--src/slskd/Application/Management/API/Controllers/SessionController.cs4
-rw-r--r--src/slskd/Application/Management/IManagementService.cs2
-rw-r--r--src/slskd/Application/Management/ManagementService.cs8
-rw-r--r--src/slskd/Application/Service.cs66
-rw-r--r--src/slskd/Application/Transfer/API/Controllers/TransfersController.cs4
-rw-r--r--src/slskd/Common/Validation/Extensions.cs6
-rw-r--r--src/slskd/Common/Validation/X509CertificateAttribute.cs2
-rw-r--r--src/slskd/Configuration.cs (renamed from src/slskd/Options.cs)4
-rw-r--r--src/slskd/Integrations/FTP/FTPClientFactory.cs6
-rw-r--r--src/slskd/Integrations/FTP/FTPService.cs6
-rw-r--r--src/slskd/Integrations/Pushbullet/PushbulletService.cs6
-rw-r--r--src/slskd/Program.cs72
-rw-r--r--src/slskd/Startup.cs44
14 files changed, 119 insertions, 119 deletions
diff --git a/src/slskd/Application/Management/API/Controllers/OptionsController.cs b/src/slskd/Application/Management/API/Controllers/OptionsController.cs
index b75adc97..578b6b4c 100644
--- a/src/slskd/Application/Management/API/Controllers/OptionsController.cs
+++ b/src/slskd/Application/Management/API/Controllers/OptionsController.cs
@@ -30,13 +30,13 @@ namespace slskd.Management.API
[Consumes("application/json")]
public class OptionsController : ControllerBase
{
- public OptionsController(Microsoft.Extensions.Options.IOptionsMonitor<Options> optionsMonitor)
+ public OptionsController(Microsoft.Extensions.Options.IOptionsMonitor<Configuration> optionsMonitor)
{
OptionsMonitor = optionsMonitor;
}
- private Microsoft.Extensions.Options.IOptionsMonitor<Options> OptionsMonitor { get; }
- private Options Options => OptionsMonitor.CurrentValue;
+ private Microsoft.Extensions.Options.IOptionsMonitor<Configuration> OptionsMonitor { get; }
+ private Configuration Options => OptionsMonitor.CurrentValue;
/// <summary>
/// Gets the current application options.
@@ -44,7 +44,7 @@ namespace slskd.Management.API
/// <returns></returns>
[HttpGet]
[Authorize]
- [ProducesResponseType(typeof(Options), 200)]
+ [ProducesResponseType(typeof(Configuration), 200)]
public IActionResult Get()
{
return Ok(Options);
diff --git a/src/slskd/Application/Management/API/Controllers/SessionController.cs b/src/slskd/Application/Management/API/Controllers/SessionController.cs
index 09a95c24..1721f3f2 100644
--- a/src/slskd/Application/Management/API/Controllers/SessionController.cs
+++ b/src/slskd/Application/Management/API/Controllers/SessionController.cs
@@ -37,7 +37,7 @@ namespace slskd.Management.API
public class SessionController : ControllerBase
{
public SessionController(
- Microsoft.Extensions.Options.IOptionsSnapshot<Options> optionsSnapshot,
+ Microsoft.Extensions.Options.IOptionsSnapshot<Configuration> optionsSnapshot,
SymmetricSecurityKey jwtSigningKey)
{
Options = optionsSnapshot.Value;
@@ -45,7 +45,7 @@ namespace slskd.Management.API
}
private SymmetricSecurityKey JwtSigningKey { get; set; }
- private Options Options { get; set; }
+ private Configuration Options { get; set; }
/// <summary>
/// Checks whether the provided authentication is valid.
diff --git a/src/slskd/Application/Management/IManagementService.cs b/src/slskd/Application/Management/IManagementService.cs
index 5ece698b..d4f7ff51 100644
--- a/src/slskd/Application/Management/IManagementService.cs
+++ b/src/slskd/Application/Management/IManagementService.cs
@@ -42,7 +42,7 @@ namespace slskd.Management
/// Gets the current application options.
/// </summary>
/// <returns></returns>
- Options GetOptions();
+ Configuration GetOptions();
/// <summary>
/// Gets the current state of the connection to the Soulseek server.
diff --git a/src/slskd/Application/Management/ManagementService.cs b/src/slskd/Application/Management/ManagementService.cs
index 4a385cff..a1d807a0 100644
--- a/src/slskd/Application/Management/ManagementService.cs
+++ b/src/slskd/Application/Management/ManagementService.cs
@@ -32,7 +32,7 @@ namespace slskd.Management
/// <param name="optionsMonitor">The options monitor used to derive application options.</param>
/// <param name="soulseekClient">The Soulseek client.</param>
public ManagementService(
- Microsoft.Extensions.Options.IOptionsMonitor<Options> optionsMonitor,
+ Microsoft.Extensions.Options.IOptionsMonitor<Configuration> optionsMonitor,
ISoulseekClient soulseekClient)
{
OptionsMonitor = optionsMonitor;
@@ -40,8 +40,8 @@ namespace slskd.Management
}
private ISoulseekClient Client { get; }
- private Options Options => OptionsMonitor.CurrentValue;
- private Microsoft.Extensions.Options.IOptionsMonitor<Options> OptionsMonitor { get; }
+ private Configuration Options => OptionsMonitor.CurrentValue;
+ private Microsoft.Extensions.Options.IOptionsMonitor<Configuration> OptionsMonitor { get; }
/// <summary>
/// Connects the Soulseek client to the server using the configured username and password.
@@ -62,7 +62,7 @@ namespace slskd.Management
/// Gets the current application options.
/// </summary>
/// <returns></returns>
- public Options GetOptions() => Options;
+ public Configuration GetOptions() => Options;
/// <summary>
/// Gets the current state of the connection to the Soulseek server.
diff --git a/src/slskd/Application/Service.cs b/src/slskd/Application/Service.cs
index d9b682fc..9a65ae37 100644
--- a/src/slskd/Application/Service.cs
+++ b/src/slskd/Application/Service.cs
@@ -44,7 +44,7 @@ namespace slskd
private (int Directories, int Files) sharedCounts = (0, 0);
public Service(
- IOptionsMonitor<Options> optionMonitor,
+ IOptionsMonitor<Configuration> optionMonitor,
ITransferTracker transferTracker,
IBrowseTracker browseTracker,
IConversationTracker conversationTracker,
@@ -55,7 +55,7 @@ namespace slskd
OptionsMonitor = optionMonitor;
OptionsMonitor.OnChange(options => OptionsChanged(options));
- Options = OptionsMonitor.CurrentValue;
+ Configuration = OptionsMonitor.CurrentValue;
TransferTracker = transferTracker;
BrowseTracker = browseTracker;
@@ -69,26 +69,26 @@ namespace slskd
if (UsingProxy)
{
proxyOptions = new ProxyOptions(
- address: Options.Soulseek.Connection.Proxy.Address,
- port: Options.Soulseek.Connection.Proxy.Port.Value,
- username: Options.Soulseek.Connection.Proxy.Username,
- password: Options.Soulseek.Connection.Proxy.Password);
+ address: Configuration.Soulseek.Connection.Proxy.Address,
+ port: Configuration.Soulseek.Connection.Proxy.Port.Value,
+ username: Configuration.Soulseek.Connection.Proxy.Username,
+ password: Configuration.Soulseek.Connection.Proxy.Password);
}
var connectionOptions = new ConnectionOptions(
- readBufferSize: Options.Soulseek.Connection.Buffer.Read,
- writeBufferSize: Options.Soulseek.Connection.Buffer.Write,
- connectTimeout: Options.Soulseek.Connection.Timeout.Connect,
- inactivityTimeout: Options.Soulseek.Connection.Timeout.Inactivity,
+ readBufferSize: Configuration.Soulseek.Connection.Buffer.Read,
+ writeBufferSize: Configuration.Soulseek.Connection.Buffer.Write,
+ connectTimeout: Configuration.Soulseek.Connection.Timeout.Connect,
+ inactivityTimeout: Configuration.Soulseek.Connection.Timeout.Inactivity,
proxyOptions: proxyOptions);
var clientOptions = new SoulseekClientOptions(
- listenPort: Options.Soulseek.ListenPort,
+ listenPort: Configuration.Soulseek.ListenPort,
enableListener: true,
userEndPointCache: new UserEndPointCache(),
- distributedChildLimit: Options.Soulseek.DistributedNetwork.ChildLimit,
- enableDistributedNetwork: !Options.Soulseek.DistributedNetwork.Disabled,
- minimumDiagnosticLevel: Options.Soulseek.DiagnosticLevel,
+ distributedChildLimit: Configuration.Soulseek.DistributedNetwork.ChildLimit,
+ enableDistributedNetwork: !Configuration.Soulseek.DistributedNetwork.Disabled,
+ minimumDiagnosticLevel: Configuration.Soulseek.DiagnosticLevel,
autoAcknowledgePrivateMessages: false,
acceptPrivateRoomInvitations: true,
serverConnectionOptions: connectionOptions,
@@ -137,31 +137,31 @@ namespace slskd
private IConversationTracker ConversationTracker { get; set; }
private ILogger Logger { get; set; } = Log.ForContext<Service>();
private ConcurrentDictionary<string, ILogger> Loggers { get; } = new ConcurrentDictionary<string, ILogger>();
- private IOptionsMonitor<Options> OptionsMonitor { get; set; }
- private Options Options { get; set; }
+ private IOptionsMonitor<Configuration> OptionsMonitor { get; set; }
+ private Configuration Configuration { get; set; }
private IRoomTracker RoomTracker { get; set; }
private ISharedFileCache SharedFileCache { get; set; }
private ITransferTracker TransferTracker { get; set; }
- private bool UsingProxy => !string.IsNullOrWhiteSpace(Options.Soulseek.Connection.Proxy.Address) && Options.Soulseek.Connection.Proxy.Port.HasValue;
+ private bool UsingProxy => !string.IsNullOrWhiteSpace(Configuration.Soulseek.Connection.Proxy.Address) && Configuration.Soulseek.Connection.Proxy.Port.HasValue;
private IPushbulletService Pushbullet { get; }
public async Task StartAsync(CancellationToken cancellationToken)
{
if (UsingProxy)
{
- Logger.Information($"Using Proxy {Options.Soulseek.Connection.Proxy.Address}:{Options.Soulseek.Connection.Proxy.Port}");
+ Logger.Information($"Using Proxy {Configuration.Soulseek.Connection.Proxy.Address}:{Configuration.Soulseek.Connection.Proxy.Port}");
}
Logger.Information("Client started");
- Logger.Information("Listening on port {Port}", Options.Soulseek.ListenPort);
+ Logger.Information("Listening on port {Port}", Configuration.Soulseek.ListenPort);
- if (string.IsNullOrEmpty(Options.Soulseek.Username) || string.IsNullOrEmpty(Options.Soulseek.Password))
+ if (string.IsNullOrEmpty(Configuration.Soulseek.Username) || string.IsNullOrEmpty(Configuration.Soulseek.Password))
{
Logger.Warning($"Not connecting to the Soulseek server; username and/or password invalid. Specify valid credentials and manually connect, or update config and restart.");
}
else
{
- await Client.ConnectAsync(Options.Soulseek.Username, Options.Soulseek.Password).ConfigureAwait(false);
+ await Client.ConnectAsync(Configuration.Soulseek.Username, Configuration.Soulseek.Password).ConfigureAwait(false);
}
}
@@ -173,12 +173,12 @@ namespace slskd
return Task.CompletedTask;
}
- private void OptionsChanged(Options options)
+ private void OptionsChanged(Configuration configuration)
{
Console.WriteLine($"Options changed. Old options:");
- Console.WriteLine(JsonSerializer.Serialize(Options));
+ Console.WriteLine(JsonSerializer.Serialize(Configuration));
Console.WriteLine($"\tNew options:");
- Console.WriteLine(JsonSerializer.Serialize(options));
+ Console.WriteLine(JsonSerializer.Serialize(configuration));
// todo: did options really change?
// todo: if options did change, create a patch and ReconfigureOptionsAsync
// todo: if ReconfigureOptionsAsync = true, find some way to let the user know a reconnect is pending
@@ -202,7 +202,7 @@ namespace slskd
private Task<BrowseResponse> BrowseResponseResolver(string username, IPEndPoint endpoint)
{
var directories = System.IO.Directory
- .GetDirectories(Options.Directories.Shared, "*", SearchOption.AllDirectories)
+ .GetDirectories(Configuration.Directories.Shared, "*", SearchOption.AllDirectories)
.Select(dir => new Soulseek.Directory(dir.Replace("/", @"\"), System.IO.Directory.GetFiles(dir)
.Select(f => new Soulseek.File(1, Path.GetFileName(f), new FileInfo(f).Length, Path.GetExtension(f)))));
@@ -237,7 +237,7 @@ namespace slskd
private void Client_LoggedIn(object sender, EventArgs e)
{
- Logger.Information("Logged in to the Soulseek server as {Username}", Options.Soulseek.Username);
+ Logger.Information("Logged in to the Soulseek server as {Username}", Configuration.Soulseek.Username);
}
private async void Client_Disconnected(object sender, SoulseekClientDisconnectedEventArgs args)
@@ -256,13 +256,13 @@ namespace slskd
}
else if (args.Exception is KickedFromServerException)
{
- Logger.Error("Disconnected from the Soulseek server: another client logged in using the username {Username}", Options.Soulseek.Username);
+ Logger.Error("Disconnected from the Soulseek server: another client logged in using the username {Username}", Configuration.Soulseek.Username);
}
else
{
Logger.Error("Disconnected from the Soulseek server: {Message}", args.Exception?.Message ?? args.Message);
- if (string.IsNullOrEmpty(Options.Soulseek.Username) || string.IsNullOrEmpty(Options.Soulseek.Password))
+ if (string.IsNullOrEmpty(Configuration.Soulseek.Username) || string.IsNullOrEmpty(Configuration.Soulseek.Password))
{
Logger.Warning($"Not reconnecting to the Soulseek server; username and/or password invalid. Specify valid credentials and manually connect, or update config and restart.");
return;
@@ -284,7 +284,7 @@ namespace slskd
try
{
- await Client.ConnectAsync(Options.Soulseek.Username, Options.Soulseek.Password);
+ await Client.ConnectAsync(Configuration.Soulseek.Username, Configuration.Soulseek.Password);
break;
}
catch (Exception ex)
@@ -300,7 +300,7 @@ namespace slskd
{
ConversationTracker.AddOrUpdate(args.Username, PrivateMessage.FromEventArgs(args));
- if (Options.Integration.Pushbullet.Enabled && !args.Replayed)
+ if (Configuration.Integration.Pushbullet.Enabled && !args.Replayed)
{
Console.WriteLine("Pushing...");
_ = Pushbullet.PushAsync($"Private Message from {args.Username}", args.Username, args.Message);
@@ -311,7 +311,7 @@ namespace slskd
{
Console.WriteLine($"[PUBLIC CHAT] [{args.RoomName}] [{args.Username}]: {args.Message}");
- if (Options.Integration.Pushbullet.Enabled && args.Message.Contains(Client.Username))
+ if (Configuration.Integration.Pushbullet.Enabled && args.Message.Contains(Client.Username))
{
_ = Pushbullet.PushAsync($"Room Mention by {args.Username} in {args.RoomName}", args.RoomName, args.Message);
}
@@ -320,7 +320,7 @@ namespace slskd
private void Client_RoomJoined(object sender, RoomJoinedEventArgs args)
{
// this will fire when we join a room; track that through the join operation.
- if (args.Username != Options.Soulseek.Username)
+ if (args.Username != Configuration.Soulseek.Username)
{
RoomTracker.TryAddUser(args.RoomName, args.UserData);
}
@@ -336,7 +336,7 @@ namespace slskd
var message = RoomMessage.FromEventArgs(args, DateTime.UtcNow);
RoomTracker.AddOrUpdateMessage(args.RoomName, message);
- if (Options.Integration.Pushbullet.Enabled && message.Message.Contains(Client.Username))
+ if (Configuration.Integration.Pushbullet.Enabled && message.Message.Contains(Client.Username))
{
_ = Pushbullet.PushAsync($"Room Mention by {message.Username} in {message.RoomName}", message.RoomName, message.Message);
}
diff --git a/src/slskd/Application/Transfer/API/Controllers/TransfersController.cs b/src/slskd/Application/Transfer/API/Controllers/TransfersController.cs
index 97b86689..b28e5b1a 100644
--- a/src/slskd/Application/Transfer/API/Controllers/TransfersController.cs
+++ b/src/slskd/Application/Transfer/API/Controllers/TransfersController.cs
@@ -46,7 +46,7 @@ namespace slskd.Transfer.API
/// <param name="tracker"></param>
/// <param name="ftpClient"></param>
public TransfersController(
- Microsoft.Extensions.Options.IOptionsSnapshot<Options> options,
+ Microsoft.Extensions.Options.IOptionsSnapshot<Configuration> options,
ISoulseekClient client,
ITransferTracker tracker,
IFTPService ftpClient)
@@ -57,7 +57,7 @@ namespace slskd.Transfer.API
FTP = ftpClient;
}
- private Options Options { get; }
+ private Configuration Options { get; }
private ISoulseekClient Client { get; }
private ITransferTracker Tracker { get; }
private IFTPService FTP { get; }
diff --git a/src/slskd/Common/Validation/Extensions.cs b/src/slskd/Common/Validation/Extensions.cs
index b7e396a3..cc2e3c12 100644
--- a/src/slskd/Common/Validation/Extensions.cs
+++ b/src/slskd/Common/Validation/Extensions.cs
@@ -28,15 +28,15 @@ namespace slskd.Validation
/// <summary>
/// Validates options.
/// </summary>
- /// <param name="options">The options instance to validate.</param>
+ /// <param name="configuration">The configuration instance to validate.</param>
/// <param name="result">The result of the validation, if invalid.</param>
/// <returns>A value indicating whether the instance is valid.</returns>
- public static bool TryValidate(this Options options, out CompositeValidationResult result)
+ public static bool TryValidate(this Configuration configuration, out CompositeValidationResult result)
{
result = null;
var results = new List<ValidationResult>();
- if (!Validator.TryValidateObject(options, new ValidationContext(options), results, true))
+ if (!Validator.TryValidateObject(configuration, new ValidationContext(configuration), results, true))
{
result = new CompositeValidationResult("Invalid configuration", results);
return false;
diff --git a/src/slskd/Common/Validation/X509CertificateAttribute.cs b/src/slskd/Common/Validation/X509CertificateAttribute.cs
index 7a080882..87cd776b 100644
--- a/src/slskd/Common/Validation/X509CertificateAttribute.cs
+++ b/src/slskd/Common/Validation/X509CertificateAttribute.cs
@@ -19,7 +19,7 @@ namespace slskd.Validation
{
using System.ComponentModel.DataAnnotations;
using slskd.Cryptography;
- using static slskd.Options.WebOptions.HttpsOptions;
+ using static slskd.Configuration.WebOptions.HttpsOptions;
/// <summary>
/// Validates X509 certificate parameters specified through <see cref="CertificateOptions"/>.
diff --git a/src/slskd/Options.cs b/src/slskd/Configuration.cs
index 2ff0df97..237b3caa 100644
--- a/src/slskd/Options.cs
+++ b/src/slskd/Configuration.cs
@@ -1,4 +1,4 @@
-// <copyright file="Options.cs" company="slskd Team">
+// <copyright file="Configuration.cs" company="slskd Team">
// Copyright (c) slskd Team. All rights reserved.
//
// This program is free software: you can redistribute it and/or modify
@@ -32,7 +32,7 @@ namespace slskd
/// <summary>
/// Application options.
/// </summary>
- public class Options
+ public class Configuration
{
/// <summary>
/// Gets a value indicating whether to display the application version.
diff --git a/src/slskd/Integrations/FTP/FTPClientFactory.cs b/src/slskd/Integrations/FTP/FTPClientFactory.cs
index cc076ca1..5b8639dc 100644
--- a/src/slskd/Integrations/FTP/FTPClientFactory.cs
+++ b/src/slskd/Integrations/FTP/FTPClientFactory.cs
@@ -19,7 +19,7 @@ namespace slskd.Integrations.FTP
{
using System;
using FluentFTP;
- using static slskd.Options.IntegrationOptions;
+ using static slskd.Configuration.IntegrationOptions;
/// <summary>
/// FTP client factory.
@@ -30,7 +30,7 @@ namespace slskd.Integrations.FTP
/// Initializes a new instance of the <see cref="FTPClientFactory"/> class.
/// </summary>
/// <param name="optionsMonitor">The options monitor used to derive application options.</param>
- public FTPClientFactory(Microsoft.Extensions.Options.IOptionsMonitor<Options> optionsMonitor)
+ public FTPClientFactory(Microsoft.Extensions.Options.IOptionsMonitor<Configuration> optionsMonitor)
{
Options = optionsMonitor.CurrentValue;
@@ -48,7 +48,7 @@ namespace slskd.Integrations.FTP
private FtpEncryptionMode EncryptionMode { get; set; }
private FTPOptions FTPOptions => Options.Integration.FTP;
- private Options Options { get; set; }
+ private Configuration Options { get; set; }
/// <summary>
/// Creates an instance of <see cref="FtpClient"/>.
diff --git a/src/slskd/Integrations/FTP/FTPService.cs b/src/slskd/Integrations/FTP/FTPService.cs
index a5fe6a8f..f7fd1ddd 100644
--- a/src/slskd/Integrations/FTP/FTPService.cs
+++ b/src/slskd/Integrations/FTP/FTPService.cs
@@ -23,7 +23,7 @@ namespace slskd.Integrations.FTP
using System.Threading.Tasks;
using FluentFTP;
using Microsoft.Extensions.Logging;
- using static slskd.Options.IntegrationOptions;
+ using static slskd.Configuration.IntegrationOptions;
/// <summary>
/// FTP Integration service.
@@ -38,7 +38,7 @@ namespace slskd.Integrations.FTP
/// <param name="log">The logger.</param>
public FTPService(
IFTPClientFactory ftpClientFactory,
- Microsoft.Extensions.Options.IOptionsMonitor<Options> optionsMonitor,
+ Microsoft.Extensions.Options.IOptionsMonitor<Configuration> optionsMonitor,
ILogger<FTPService> log)
{
Factory = ftpClientFactory;
@@ -49,7 +49,7 @@ namespace slskd.Integrations.FTP
private IFTPClientFactory Factory { get; set; }
private FTPOptions FTPOptions => Options.Integration.FTP;
private ILogger<FTPService> Log { get; set; }
- private Options Options { get; }
+ private Configuration Options { get; }
/// <summary>
/// Uploads the specified <paramref name="filename"/> to the configured FTP server.
diff --git a/src/slskd/Integrations/Pushbullet/PushbulletService.cs b/src/slskd/Integrations/Pushbullet/PushbulletService.cs
index cb31e6dc..8bf94af9 100644
--- a/src/slskd/Integrations/Pushbullet/PushbulletService.cs
+++ b/src/slskd/Integrations/Pushbullet/PushbulletService.cs
@@ -24,7 +24,7 @@ namespace slskd.Integrations.Pushbullet
using System.Threading.Tasks;
using Microsoft.Extensions.Caching.Memory;
using Microsoft.Extensions.Logging;
- using static slskd.Options.IntegrationOptions;
+ using static slskd.Configuration.IntegrationOptions;
/// <summary>
/// Pushbullet integration service.
@@ -41,7 +41,7 @@ namespace slskd.Integrations.Pushbullet
/// <param name="log">The logger.</param>
public PushbulletService(
IHttpClientFactory httpClientFactory,
- Microsoft.Extensions.Options.IOptionsMonitor<Options> optionsMonitor,
+ Microsoft.Extensions.Options.IOptionsMonitor<Configuration> optionsMonitor,
ILogger<PushbulletService> log)
{
HttpClientFactory = httpClientFactory;
@@ -52,7 +52,7 @@ namespace slskd.Integrations.Pushbullet
}
private IHttpClientFactory HttpClientFactory { get; }
- private Options Options { get; }
+ private Configuration Options { get; }
private ILogger<PushbulletService> Log { get; }
private PushbulletOptions PushbulletOptions => Options.Integration.Pushbullet;
private IMemoryCache RecentlySent { get; }
diff --git a/src/slskd/Program.cs b/src/slskd/Program.cs
index 2ce98454..e022237b 100644
--- a/src/slskd/Program.cs
+++ b/src/slskd/Program.cs
@@ -119,8 +119,8 @@ namespace slskd
/// </summary>
public static string Version { get; } = $"{AssemblyVersion} ({InformationalVersion})";
- private static IConfigurationRoot Configuration { get; set; }
- private static Options Options { get; } = new Options();
+ private static IConfigurationRoot ConfigurationRoot { get; set; }
+ private static Configuration Configuration { get; } = new Configuration();
[EnvironmentVariable("CONFIG")]
[Argument('c', "config", "path to configuration file")]
@@ -167,12 +167,12 @@ namespace slskd
if (ShowHelp)
{
- PrintCommandLineArguments(typeof(Options));
+ PrintCommandLineArguments(typeof(Configuration));
}
if (ShowEnvironmentVariables)
{
- PrintEnvironmentVariables(typeof(Options), EnvironmentVariablePrefix);
+ PrintEnvironmentVariables(typeof(Configuration), EnvironmentVariablePrefix);
}
return;
@@ -188,19 +188,19 @@ namespace slskd
// with bootstrapping.
try
{
- Configuration = new ConfigurationBuilder()
+ ConfigurationRoot = new ConfigurationBuilder()
.AddConfigurationProviders(EnvironmentVariablePrefix, ConfigurationFile)
.Build();
- Configuration.GetSection(AppName)
- .Bind(Options, (o) => { o.BindNonPublicProperties = true; });
+ ConfigurationRoot.GetSection(AppName)
+ .Bind(Configuration, (o) => { o.BindNonPublicProperties = true; });
- if (Options.Debug)
+ if (Configuration.Debug)
{
- Console.WriteLine($"Configuration:\n{Configuration.GetDebugView()}");
+ Console.WriteLine($"Configuration:\n{ConfigurationRoot.GetDebugView()}");
}
- if (!Options.TryValidate(out var result))
+ if (!Configuration.TryValidate(out var result))
{
Console.WriteLine(result.GetResultView());
return;
@@ -208,16 +208,16 @@ namespace slskd
}
catch (Exception ex)
{
- Console.WriteLine($"Invalid configuration: {(!Options.Debug ? ex : ex.Message)}");
+ Console.WriteLine($"Invalid configuration: {(!Configuration.Debug ? ex : ex.Message)}");
return;
}
try
{
- VerifyOrCreateDirectory(Options.Directories.App);
- VerifyOrCreateDirectory(Options.Directories.Incomplete);
- VerifyOrCreateDirectory(Options.Directories.Downloads);
- VerifyOrCreateDirectory(Options.Directories.Shared, verifyWriteable: false);
+ VerifyOrCreateDirectory(Configuration.Directories.App);
+ VerifyOrCreateDirectory(Configuration.Directories.Incomplete);
+ VerifyOrCreateDirectory(Configuration.Directories.Downloads);
+ VerifyOrCreateDirectory(Configuration.Directories.Shared, verifyWriteable: false);
}
catch (Exception ex)
{
@@ -225,31 +225,31 @@ namespace slskd
return;
}
- Log.Logger = (Options.Debug ? new LoggerConfiguration().MinimumLevel.Debug() : new LoggerConfiguration().MinimumLevel.Information())
+ Log.Logger = (Configuration.Debug ? new LoggerConfiguration().MinimumLevel.Debug() : new LoggerConfiguration().MinimumLevel.Information())
.MinimumLevel.Override("Microsoft", LogEventLevel.Warning)
.MinimumLevel.Override("slskd.API.Authentication.PassthroughAuthenticationHandler", LogEventLevel.Information)
.Enrich.WithProperty("Version", Version)
- .Enrich.WithProperty("InstanceName", Options.InstanceName)
+ .Enrich.WithProperty("InstanceName", Configuration.InstanceName)
.Enrich.WithProperty("InvocationId", InvocationId)
.Enrich.WithProperty("ProcessId", ProcessId)
.Enrich.FromLogContext()
.WriteTo.Console(
- outputTemplate: (Options.Debug ? "[{SourceContext}] [{SoulseekContext}] " : string.Empty) + "[{Timestamp:HH:mm:ss} {Level:u3}] {Message:lj}{NewLine}{Exception}")
+ outputTemplate: (Configuration.Debug ? "[{SourceContext}] [{SoulseekContext}] " : string.Empty) + "[{Timestamp:HH:mm:ss} {Level:u3}] {Message:lj}{NewLine}{Exception}")
.WriteTo.Async(config =>
config.File(
Path.Combine(AppContext.BaseDirectory, "logs", $"{AppName}-.log"),
- outputTemplate: (Options.Debug ? "[{SourceContext}] " : string.Empty) + "[{Timestamp:HH:mm:ss} {Level:u3}] {Message:lj}{NewLine}{Exception}",
+ outputTemplate: (Configuration.Debug ? "[{SourceContext}] " : string.Empty) + "[{Timestamp:HH:mm:ss} {Level:u3}] {Message:lj}{NewLine}{Exception}",
rollingInterval: RollingInterval.Day))
.WriteTo.Conditional(
- e => !string.IsNullOrEmpty(Options.Logger.Loki),
+ e => !string.IsNullOrEmpty(Configuration.Logger.Loki),
config => config.GrafanaLoki(
- Options.Logger.Loki ?? string.Empty,
+ Configuration.Logger.Loki ?? string.Empty,
outputTemplate: "[{Timestamp:HH:mm:ss} {Level:u3}] {Message:lj}{NewLine}{Exception}"))
.CreateLogger();
var logger = Log.ForContext(typeof(Program));
- if (!Options.NoLogo)
+ if (!Configuration.NoLogo)
{
PrintLogo(Version);
}
@@ -260,18 +260,18 @@ namespace slskd
}
logger.Information("Version: {Version}", Version);
- logger.Information("Instance Name: {InstanceName}", Options.InstanceName);
+ logger.Information("Instance Name: {InstanceName}", Configuration.InstanceName);
logger.Information("Invocation ID: {InvocationId}", InvocationId);
logger.Information("Process ID: {ProcessId}", ProcessId);
- if (!string.IsNullOrEmpty(Options.Logger.Loki))
+ if (!string.IsNullOrEmpty(Configuration.Logger.Loki))
{
- logger.Information("Forwarding logs to Grafana Loki instance at {LoggerLokiUrl}", Options.Logger.Loki);
+ logger.Information("Forwarding logs to Grafana Loki instance at {LoggerLokiUrl}", Configuration.Logger.Loki);
}
try
{
- if (Options.Feature.Prometheus)
+ if (Configuration.Feature.Prometheus)
{
using var runtimeMetrics = DotNetRuntimeStatsBuilder.Default().StartCollecting();
}
@@ -287,13 +287,13 @@ namespace slskd
.UseUrls()
.UseKestrel(options =>
{
- logger.Information($"Listening for HTTP requests at http://{IPAddress.Any}:{Options.Web.Port}/");
- options.Listen(IPAddress.Any, Options.Web.Port);
+ logger.Information($"Listening for HTTP requests at http://{IPAddress.Any}:{Configuration.Web.Port}/");
+ options.Listen(IPAddress.Any, Configuration.Web.Port);
- logger.Information($"Listening for HTTPS requests at https://{IPAddress.Any}:{Options.Web.Https.Port}/");
- options.Listen(IPAddress.Any, Options.Web.Https.Port, listenOptions =>
+ logger.Information($"Listening for HTTPS requests at https://{IPAddress.Any}:{Configuration.Web.Https.Port}/");
+ options.Listen(IPAddress.Any, Configuration.Web.Https.Port, listenOptions =>
{
- var cert = Options.Web.Https.Certificate;
+ var cert = Configuration.Web.Https.Certificate;
if (!string.IsNullOrEmpty(cert.Pfx))
{
@@ -310,7 +310,7 @@ namespace slskd
.UseStartup<Startup>()
.Build();
- if (Options.NoStart)
+ if (Configuration.NoStart)
{
logger.Information("Qutting because 'no-start' option is enabled");
return;
@@ -334,18 +334,18 @@ namespace slskd
return builder
.AddDefaultValues(
- targetType: typeof(Options))
+ targetType: typeof(Configuration))
.AddEnvironmentVariables(
- targetType: typeof(Options),
+ targetType: typeof(Configuration),
prefix: environmentVariablePrefix)
.AddYamlFile(
path: Path.GetFileName(configurationFile),
- targetType: typeof(Options),
+ targetType: typeof(Configuration),
optional: true,
reloadOnChange: true,
provider: new PhysicalFileProvider(Path.GetDirectoryName(configurationFile), ExclusionFilters.None)) // required for locations outside of the app directory
.AddCommandLine(
- targetType: typeof(Options),
+ targetType: typeof(Configuration),
commandLine: Environment.CommandLine);
}
diff --git a/src/slskd/Startup.cs b/src/slskd/Startup.cs
index 635a6890..07216937 100644
--- a/src/slskd/Startup.cs
+++ b/src/slskd/Startup.cs
@@ -51,29 +51,29 @@ namespace slskd
/// <summary>
/// Initializes a new instance of the <see cref="Startup"/> class.
/// </summary>
- /// <param name="configuration">The application configuration.</param>
- public Startup(IConfiguration configuration)
+ /// <param name="configuration">The application configuration root.</param>
+ public Startup(IConfiguration configurationRoot)
{
- Configuration = configuration;
+ ConfigurationRoot = configurationRoot;
- Options = new Options();
- Configuration.GetSection(Program.AppName).Bind(Options, (o) =>
+ Configuration = new Configuration();
+ ConfigurationRoot.GetSection(Program.AppName).Bind(Configuration, (o) =>
{
o.BindNonPublicProperties = true;
});
- UrlBase = Options.Web.UrlBase;
+ UrlBase = Configuration.Web.UrlBase;
UrlBase = UrlBase.StartsWith("/") ? UrlBase : "/" + UrlBase;
- ContentPath = Path.GetFullPath(Options.Web.ContentPath);
+ ContentPath = Path.GetFullPath(Configuration.Web.ContentPath);
- JwtSigningKey = new SymmetricSecurityKey(Pbkdf2.GetKey(Options.Web.Authentication.Jwt.Key));
+ JwtSigningKey = new SymmetricSecurityKey(Pbkdf2.GetKey(Configuration.Web.Authentication.Jwt.Key));
}
- private IConfiguration Configuration { get; }
+ private IConfiguration ConfigurationRoot { get; }
private string ContentPath { get; set; }
private SymmetricSecurityKey JwtSigningKey { get; set; }
- private Options Options { get; }
+ private Configuration Configuration { get; }
private string UrlBase { get; set; }
/// <summary>
@@ -84,14 +84,14 @@ namespace slskd
{
var logger = Log.ForContext<Startup>();
- services.AddOptions<Options>()
- .Bind(Configuration.GetSection(Program.AppName), o => { o.BindNonPublicProperties = true; });
+ services.AddOptions<Configuration>()
+ .Bind(ConfigurationRoot.GetSection(Program.AppName), o => { o.BindNonPublicProperties = true; });
services.AddCors(options => options.AddPolicy("AllowAll", builder => builder.AllowAnyOrigin().AllowAnyMethod().AllowAnyHeader()));
services.AddSingleton(JwtSigningKey);
- if (!Options.Web.Authentication.Disable)
+ if (!Configuration.Web.Authentication.Disable)
{
services.AddAuthentication(JwtBearerDefaults.AuthenticationScheme)
.AddJwtBearer(options =>
@@ -139,7 +139,7 @@ namespace slskd
options.SubstituteApiVersionInUrl = true;
});
- if (Options.Feature.Swagger)
+ if (Configuration.Feature.Swagger)
{
services.AddSwaggerGen(options =>
{
@@ -163,19 +163,19 @@ namespace slskd
});
}
- if (Options.Feature.Prometheus)
+ if (Configuration.Feature.Prometheus)
{
services.AddSystemMetrics();
}
services.AddDbContextFactory<SearchDbContext>(options =>
{
- options.UseSqlite($"Data Source={Path.Combine(Options.Directories.App, "search.db")}");
+ options.UseSqlite($"Data Source={Path.Combine(Configuration.Directories.App, "search.db")}");
});
services.AddDbContextFactory<PeerDbContext>(options =>
{
- options.UseSqlite($"Data Source={Path.Combine(Options.Directories.App, "peer.db")}");
+ options.UseSqlite($"Data Source={Path.Combine(Configuration.Directories.App, "peer.db")}");
});
services.AddHttpClient();
@@ -185,7 +185,7 @@ namespace slskd
services.AddSingleton<IConversationTracker, ConversationTracker>();
services.AddSingleton<IRoomTracker, RoomTracker>(_ => new RoomTracker(messageLimit: 250));
services.AddSingleton<ISharedFileCache>(_ =>
- new SharedFileCache(Options.Directories.Shared, 3600000));
+ new SharedFileCache(Configuration.Directories.Shared, 3600000));
services.AddSingleton<ISearchService, SearchService>();
services.AddSingleton<IPeerService, PeerService>();
@@ -213,7 +213,7 @@ namespace slskd
app.UseCors("AllowAll");
- if (Options.Web.Https.Force)
+ if (Configuration.Web.Https.Force)
{
app.UseHttpsRedirection();
app.UseHsts();
@@ -258,7 +258,7 @@ namespace slskd
logger.Information("Serving static content from {ContentPath}", ContentPath);
}
- if (Options.Feature.Prometheus)
+ if (Configuration.Feature.Prometheus)
{
app.UseHttpMetrics();
logger.Information("Publishing Prometheus metrics to /metrics");
@@ -275,13 +275,13 @@ namespace slskd
endpoints.MapControllers();
endpoints.MapHealthChecks("/health");
- if (Options.Feature.Prometheus)
+ if (Configuration.Feature.Prometheus)
{
endpoints.MapMetrics();
}
});
- if (Options.Feature.Swagger)
+ if (Configuration.Feature.Swagger)
{
app.UseSwagger();
app.UseSwaggerUI(options => apiVersionDescriptionProvider.ApiVersionDescriptions.ToList()