aboutsummaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
authorJP Dillingham <jpdillingham@gmail.com>2021-01-20 22:26:31 -0600
committerJP Dillingham <jpdillingham@gmail.com>2021-01-20 22:26:31 -0600
commit4876d4a5f024e2223312e95999f9be12bd8511fc (patch)
treefe0e16fa2f4bb3873f321f9d5da244b0d2473a44
parentcec869b9456cf6fe5597847948b2d75b9846755a (diff)
downloadslskd-4876d4a5f024e2223312e95999f9be12bd8511fc.tar.gz
wip
-rw-r--r--src/slskd/Options.cs52
-rw-r--r--src/slskd/Program.cs15
-rw-r--r--src/slskd/Roles.cs9
-rw-r--r--src/slskd/Startup.cs34
-rw-r--r--src/slskd/config.yml25
-rw-r--r--src/slskd/slskd.csproj10
6 files changed, 134 insertions, 11 deletions
diff --git a/src/slskd/Options.cs b/src/slskd/Options.cs
new file mode 100644
index 00000000..f02f4d49
--- /dev/null
+++ b/src/slskd/Options.cs
@@ -0,0 +1,52 @@
+using System;
+using System.Collections.Generic;
+using System.ComponentModel.DataAnnotations;
+using System.Linq;
+using System.Threading.Tasks;
+
+namespace slskd
+{
+ public class Options
+ {
+ public class slskd
+ {
+ public Soulseek Soulseek { get; set; }
+ public IEnumerable<User> Users { get; set; }
+ public IEnumerable<ApiKey> ApiKeys { get; set; }
+ }
+
+ public class Soulseek
+ {
+ public SoulseekCredentials Credentials { get; set; }
+ public SoulseekDistributedNetwork DistributedNetwork { get; set; }
+
+ [Range(1024, 65535)]
+ public int ListenPort { get; set; }
+
+ public class SoulseekCredentials
+ {
+ public string Username { get; set; }
+ public string Password { get; set; }
+ }
+
+ public class SoulseekDistributedNetwork
+ {
+ public bool Enable { get; set; }
+ public int ChildLimit { get; set; }
+ }
+ }
+
+ public class User
+ {
+ public string Username { get; set; }
+ public string PasswordHash { get; set; }
+ public Roles Role { get; set; }
+ }
+
+ public class ApiKey
+ {
+ public string Key { get; set; }
+ public Roles Role { get; set; }
+ }
+ }
+}
diff --git a/src/slskd/Program.cs b/src/slskd/Program.cs
index dc3b7c05..1b08b918 100644
--- a/src/slskd/Program.cs
+++ b/src/slskd/Program.cs
@@ -13,6 +13,7 @@
using System.Reflection;
using Utility.CommandLine;
using Utility.EnvironmentVariables;
+ using Utility.Extensions.Configuration.Yaml;
public class Program
{
@@ -93,7 +94,7 @@
{
if (!DisableLogo)
{
- PrintBanner(Version);
+ PrintLogo(Version);
}
PrintHelp();
@@ -155,7 +156,7 @@
if (!DisableLogo)
{
- PrintBanner(Version);
+ PrintLogo(Version);
}
var logger = Log.ForContext<Program>();
@@ -209,12 +210,12 @@
.ConfigureAppConfiguration((hostingContext, config) =>
{
config.AddEnvironmentVariables(prefix: "SLSK_");
- config.AddJsonFile("config.json", optional: true, reloadOnChange: false);
+ config.AddYamlFile("config.yml", optional: true, reloadOnChange: true);
})
.UseSerilog()
.UseStartup<Startup>();
- public static void PrintBanner(string version)
+ private static void PrintLogo(string version)
{
var padding = 56 - version.Length;
var paddingLeft = padding / 2;
@@ -237,13 +238,13 @@
Console.WriteLine(banner);
}
- public static void PrintHelp()
+ private static void PrintHelp()
{
PrintArguments();
PrintEnvironmentVariables();
}
- public static void PrintArguments()
+ private static void PrintArguments()
{
static string GetLongName(ArgumentInfo info)
=> info.Property.PropertyType == typeof(bool) ? info.LongName : $"{info.LongName} <{info.Property.PropertyType.Name.ToLowerInvariant()}>";
@@ -267,7 +268,7 @@
}
}
- public static void PrintEnvironmentVariables()
+ private static void PrintEnvironmentVariables()
{
static string GetEnvironmentVariableName(ArgumentInfo info, bool includeType = false)
=> info.Property.CustomAttributes
diff --git a/src/slskd/Roles.cs b/src/slskd/Roles.cs
new file mode 100644
index 00000000..5ddee6d8
--- /dev/null
+++ b/src/slskd/Roles.cs
@@ -0,0 +1,9 @@
+namespace slskd
+{
+ public enum Roles
+ {
+ ReadOnly = 0,
+ User = 1,
+ Administrator = 2
+ }
+}
diff --git a/src/slskd/Startup.cs b/src/slskd/Startup.cs
index 37a3c7cd..9dd9f52d 100644
--- a/src/slskd/Startup.cs
+++ b/src/slskd/Startup.cs
@@ -32,6 +32,7 @@
using Microsoft.Extensions.Logging;
using Prometheus;
using Prometheus.SystemMetrics;
+ using Microsoft.Extensions.Options;
public class Startup
{
@@ -101,6 +102,20 @@
public void ConfigureServices(IServiceCollection services)
{
+ services.AddOptions<Options.Soulseek>()
+ .Bind(Configuration.GetSection("soulseek"));
+
+ services.PostConfigure<List<Options.User>>(slskd =>
+ {
+ Console.WriteLine($"config updated");
+ Console.WriteLine(JsonSerializer.Serialize(slskd));
+ });
+
+ services.AddOptions<List<string>>().Bind(Configuration.GetSection("sparse"));
+ services.PostConfigure<List<string>>(s => Console.WriteLine(JsonSerializer.Serialize(s)));
+
+ services.AddOptions<List<Options.User>>().Bind(Configuration.GetSection("users"));
+
services.AddCors(options => options.AddPolicy("AllowAll", builder => builder.AllowAnyOrigin().AllowAnyMethod().AllowAnyHeader()));
if (!Program.DisableAuthentication)
@@ -184,6 +199,9 @@
ITransferTracker tracker,
IBrowseTracker browseTracker,
IConversationTracker conversationTracker,
+ IOptionsMonitor<Options.Soulseek> optionsAccessor,
+ IOptionsMonitor<List<Options.User>> users,
+ IOptionsMonitor<List<string>> sparse,
IRoomTracker roomTracker)
{
if (!env.IsDevelopment())
@@ -191,6 +209,14 @@
app.UseHsts();
}
+ optionsAccessor.OnChange(options =>
+ {
+ Console.WriteLine(JsonSerializer.Serialize(optionsAccessor));
+ });
+
+ sparse.OnChange(v => Console.WriteLine(JsonSerializer.Serialize(v)));
+ users.OnChange(users => Console.WriteLine(JsonSerializer.Serialize(users)));
+
app.UseCors("AllowAll");
app.UsePathBase(BasePath);
@@ -395,10 +421,10 @@
}
};
- Task.Run(async () =>
- {
- await Client.ConnectAsync(Username, Password);
- }).GetAwaiter().GetResult();
+ //Task.Run(async () =>
+ //{
+ // await Client.ConnectAsync(Username, Password);
+ //}).GetAwaiter().GetResult();
logger.LogInformation("Connected and logged in as {Username}", Username);
}
diff --git a/src/slskd/config.yml b/src/slskd/config.yml
new file mode 100644
index 00000000..266ab9da
--- /dev/null
+++ b/src/slskd/config.yml
@@ -0,0 +1,25 @@
+soulseek:
+ credentials:
+ username: foo
+ password: bar
+ listenPort: 500
+ distributedNetwork:
+ enable: true
+ childLimit: 100
+users:
+- username: admin
+ passwordHash: abc
+ role: Administrators
+- username: user
+ passwordHash: xyz
+ role: User
+apiKeys:
+- key: '1234567890'
+ role: ReadOnly
+sparse:
+ - ~
+ - 2nd entry
+ -
+ - 4th entry
+ - Null
+ - tests \ No newline at end of file
diff --git a/src/slskd/slskd.csproj b/src/slskd/slskd.csproj
index 7377ea60..4e1d9994 100644
--- a/src/slskd/slskd.csproj
+++ b/src/slskd/slskd.csproj
@@ -23,6 +23,14 @@
</PropertyGroup>
<ItemGroup>
+ <None Remove="config.yml" />
+ </ItemGroup>
+
+ <ItemGroup>
+ <Content Include="config.yml" />
+ </ItemGroup>
+
+ <ItemGroup>
<PackageReference Include="Microsoft.AspNetCore.Authentication.JwtBearer" Version="5.0.2" />
<PackageReference Include="Microsoft.AspNetCore.Mvc.Versioning.ApiExplorer" Version="4.2.0" />
<PackageReference Include="Microsoft.Data.Sqlite" Version="5.0.2" />
@@ -43,6 +51,8 @@
<PackageReference Include="System.IdentityModel.Tokens.Jwt" Version="6.8.0" />
<PackageReference Include="Utility.CommandLine.Arguments" Version="5.0.0" />
<PackageReference Include="Utility.EnvironmentVariables" Version="1.0.3" />
+ <PackageReference Include="Utility.Extensions.Configuration.Yaml" Version="1.0.0" />
+ <PackageReference Include="YamlDotNet" Version="9.1.4" />
</ItemGroup>
<ItemGroup>