aboutsummaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
authorJP Dillingham <jpdillingham@gmail.com>2021-01-30 16:50:42 -0600
committerJP Dillingham <jpdillingham@gmail.com>2021-01-30 16:50:42 -0600
commitae0d355d117e80506ec2f4f52c57b8805aa16d5e (patch)
tree2fa794feed5596cd82cb7e8c40b9408af760be3a
parent3f9685270f9f8cfb17ef52a6859e209ba8de1712 (diff)
downloadslskd-ae0d355d117e80506ec2f4f52c57b8805aa16d5e.tar.gz
rename Configuration to Options, refactor
-rw-r--r--src/slskd/Options.cs (renamed from src/slskd/Configuration.cs)187
-rw-r--r--src/slskd/config.yml30
-rw-r--r--src/slskd/slskd.csproj8
3 files changed, 92 insertions, 133 deletions
diff --git a/src/slskd/Configuration.cs b/src/slskd/Options.cs
index 2fe81dfb..9e6e6713 100644
--- a/src/slskd/Configuration.cs
+++ b/src/slskd/Options.cs
@@ -2,18 +2,20 @@
{
using System;
using System.Collections.Generic;
- using System.Linq;
+ using System.Diagnostics;
+ using YamlDotNet.Serialization;
- public record Option(char ShortName, string LongName, string EnvironmentVariable, Type Type, string Key, string Description = null);
-
- public static class Configuration
+ public record Option(char ShortName, string LongName, string EnvironmentVariable, Type Type, string Key, string Description = null)
{
- public static EnvironmentVariable ToEnvironmentVariable(this Option option)
- => new EnvironmentVariable(option.EnvironmentVariable, option.Type, option.Key, option.Description);
+ public CommandLineArgument ToCommandLineArgument()
+ => new CommandLineArgument(ShortName, LongName, Type, Key, Description);
- public static CommandLineArgument ToCommandLineArgument(this Option option)
- => new CommandLineArgument(option.ShortName, option.LongName, option.Type, option.Key, option.Description);
+ public EnvironmentVariable ToEnvironmentVariable()
+ => new EnvironmentVariable(EnvironmentVariable, Type, Key, Description);
+ }
+ public class Options
+ {
public static IEnumerable<Option> Map => new Option[]
{
new(
@@ -56,7 +58,7 @@
LongName: "no-auth",
EnvironmentVariable: "NO_AUTH",
Type: typeof(bool),
- Key: "slskd:noauth",
+ Key: "slskd:web:noauth",
Description: "disable authentication for web requests"),
new(
ShortName: 'i',
@@ -66,6 +68,13 @@
Key: "slskd:instancename",
Description: "optional; a unique name for this instance"),
new(
+ ShortName: 'o',
+ LongName: "port",
+ EnvironmentVariable: "PORT",
+ Type: typeof(string),
+ Key: "slskd:web:port",
+ Description: "listen port for web server"),
+ new(
ShortName: 'b',
LongName: "url-base",
EnvironmentVariable: "URL_BASE",
@@ -73,39 +82,39 @@
Key: "slskd:web:urlbase",
Description: "base url for web requests"),
new(
- ShortName: 'c',
- LongName: "content-path",
+ ShortName: 'c',
+ LongName: "content-path",
EnvironmentVariable: "CONTENT_PATH",
- Type: typeof(string),
- Key: "slskd:web:contentpath",
+ Type: typeof(string),
+ Key: "slskd:web:contentpath",
Description: "path to static web content"),
new(
- ShortName: 'k',
- LongName: "jwt-key",
+ ShortName: 'k',
+ LongName: "jwt-key",
EnvironmentVariable: "JWT_KEY",
- Type: typeof(string),
- Key: "slskd:web:jwt:key",
+ Type: typeof(string),
+ Key: "slskd:web:jwt:key",
Description: "the key with which to sign JWTs"),
new(
- ShortName: 't',
- LongName: "jwt-ttl",
+ ShortName: 't',
+ LongName: "jwt-ttl",
EnvironmentVariable: "JWT_TTL",
- Type: typeof(int),
- Key: "slskd:web:jwt:ttl",
+ Type: typeof(int),
+ Key: "slskd:web:jwt:ttl",
Description: "the TTL for JWTs"),
new(
- ShortName: 'u',
- LongName: "username",
+ ShortName: 'u',
+ LongName: "username",
EnvironmentVariable: "USERNAME",
- Type: typeof(string),
- Key: "slskd:soulseek:username",
+ Type: typeof(string),
+ Key: "slskd:soulseek:username",
Description: "the username for the Soulseek network"),
new(
- ShortName: 'p',
- LongName: "password",
+ ShortName: 'p',
+ LongName: "password",
EnvironmentVariable: "PASSWORD",
- Type: typeof(string),
- Key: "slskd:soulseek:password",
+ Type: typeof(string),
+ Key: "slskd:soulseek:password",
Description: "the password for the Soulseek network"),
new(
ShortName: 'l',
@@ -151,93 +160,75 @@
Description: "optional; the url to a Grafana Loki instance to which to log"),
};
- public class Program
- {
- public bool Debug { get; private set; } = false;
- public bool NoLogo { get; private set; } = false;
- public bool NoAuth { get; private set; } = false;
- public string InstanceName { get; private set; } = "default";
- public FeatureOptions Feature { get; private set; } = new FeatureOptions();
- public LoggerOptions Logger { get; private set; } = new LoggerOptions();
- public WebOptions Web { get; private set; } = new WebOptions();
- public SoulseekOptions Soulseek { get; private set; } = new SoulseekOptions();
+ [YamlIgnore]
+ public bool IsUsingDefaultCredentials => Username == Password && Password == "slskd";
- public class FeatureOptions
- {
- public bool Prometheus { get; private set; } = false;
- public bool Swagger { get; private set; } = false;
- }
-
- public class LoggerOptions
- {
- public string Loki { get; private set; } = null;
- }
+ public string Username { get; private set; } = "slskd";
+ public string Password { get; private set; } = "slskd";
+ public string InstanceName { get; private set; } = "default";
+ public bool Debug { get; private set; } = Debugger.IsAttached;
+ public bool NoLogo { get; private set; } = false;
+ public WebOptions Web { get; private set; } = new WebOptions();
+ public SoulseekOptions Soulseek { get; private set; } = new SoulseekOptions();
+ public FeatureOptions Feature { get; private set; } = new FeatureOptions();
+ public LoggerOptions Logger { get; private set; } = new LoggerOptions();
- public class WebOptions
- {
- public string UrlBase { get; private set; } = "/";
- public string ContentPath { get; private set; } = "wwwroot";
- public JwtOptions Jwt { get; private set; } = new JwtOptions();
+ public class FeatureOptions
+ {
+ public bool Prometheus { get; private set; } = false;
+ public bool Swagger { get; private set; } = false;
+ }
- public class JwtOptions
- {
- public int TTL { get; private set; } = 1234567890;
- public string Key { get; private set; } = Guid.NewGuid().ToString();
- }
- }
+ public class LoggerOptions
+ {
+ public string Loki { get; private set; } = null;
+ }
+ public class SoulseekOptions
+ {
+ public ConnectionOptions Connection { get; set; } = new ConnectionOptions();
+ public DistributedNetworkOptions DistributedNetwork { get; set; } = new DistributedNetworkOptions();
+ public int? ListenPort { get; set; } = 50000;
+ public string Password { get; set; }
+ public string Username { get; set; }
- public class SoulseekOptions
+ public class ConnectionOptions
{
- public string Username { get; set; }
- public string Password { get; set; }
- public int? ListenPort { get; set; } = 50000;
- public DistributedNetworkOptions DistributedNetwork { get; set; } = new DistributedNetworkOptions();
- public ConnectionOptions Connection { get; set; } = new ConnectionOptions();
+ public TimeoutOptions Timeout { get; set; } = new TimeoutOptions();
+ public BufferOptions Buffer { get; set; } = new BufferOptions();
- public class DistributedNetworkOptions
+ public class BufferOptions
{
- public bool Enabled { get; set; } = true;
- public int ChildLimit { get; set; } = 10;
+ public int Read { get; set; } = 16384;
+ public int Write { get; set; } = 16384;
}
- public class ConnectionOptions
+ public class TimeoutOptions
{
- public TimeoutOptions Timeout { get; set; } = new TimeoutOptions();
- public BufferOptions Buffer { get; set; } = new BufferOptions();
-
- public class TimeoutOptions
- {
- public int Connect { get; set; } = 5000;
- public int Inactivity { get; set; } = 15000;
- }
-
- public class BufferOptions
- {
- public int Read { get; set; } = 16384;
- public int Write { get; set; } = 16384;
- }
+ public int Connect { get; set; } = 5000;
+ public int Inactivity { get; set; } = 15000;
}
}
- }
-
- public class Authentication
- {
- public IEnumerable<User> Users { get; set; } = Enumerable.Empty<User>();
- public IEnumerable<ApiKey> ApiKeys { get; set; } = Enumerable.Empty<ApiKey>();
- public class User
+ public class DistributedNetworkOptions
{
- public string Name { get; set; }
- public string Password { get; set; }
- public Role Role { get; set; }
+ public bool Enabled { get; set; } = true;
+ public int ChildLimit { get; set; } = 10;
}
+ }
+
+ public class WebOptions
+ {
+ public bool NoAuth { get; private set; } = false;
+ public string UrlBase { get; private set; } = "/";
+ public string ContentPath { get; private set; } = "wwwroot";
+ public JwtOptions Jwt { get; private set; } = new JwtOptions();
- public class ApiKey
+ public class JwtOptions
{
- public string Key { get; set; }
- public Role Role { get; set; }
+ public string Key { get; private set; } = Guid.NewGuid().ToString();
+ public int Ttl { get; private set; } = 604800000;
}
}
}
-}
+} \ No newline at end of file
diff --git a/src/slskd/config.yml b/src/slskd/config.yml
deleted file mode 100644
index 9a19f276..00000000
--- a/src/slskd/config.yml
+++ /dev/null
@@ -1,30 +0,0 @@
-slskd:
- debug: false
- no_logo: false
- no_auth: false
- instance_name: FromYAML
- feature:
- prometheus: true
- swagger: true
- logger:
- loki: http://192.168.1.60:3101
- web:
- url_base: /
- content_path: wwwroot
- jwt:
- ttl: 604800000
- key: ~
- soulseek:
- username: ~
- password: ~
- listen_port: 50000
- distributed_network:
- enabled: true
- child_limit: 10
- connection:
- timeout:
- connect: 5000
- inactivity: 15000
- buffer:
- read: 16384
- write: 16384 \ No newline at end of file
diff --git a/src/slskd/slskd.csproj b/src/slskd/slskd.csproj
index 83efa132..c177f6f7 100644
--- a/src/slskd/slskd.csproj
+++ b/src/slskd/slskd.csproj
@@ -23,11 +23,9 @@
</PropertyGroup>
<ItemGroup>
- <None Remove="config.yml" />
- </ItemGroup>
-
- <ItemGroup>
- <Content Include="config.yml" />
+ <Content Include="slskd.yml">
+ <CopyToOutputDirectory>Always</CopyToOutputDirectory>
+ </Content>
</ItemGroup>
<ItemGroup>