aboutsummaryrefslogtreecommitdiffstats
path: root/src/slskd/Common/Options
diff options
context:
space:
mode:
authorJP Dillingham <jpdillingham@gmail.com>2021-01-23 00:39:50 -0600
committerJP Dillingham <jpdillingham@gmail.com>2021-01-23 00:39:50 -0600
commitff3b1fe36885442a6e40cac23ec8b186ef416e77 (patch)
tree5e15c163d6179fd1f6d5129b97c458fda588c1e1 /src/slskd/Common/Options
parentfc9a1aacfb9c4e005fd482ba37394840865e9e61 (diff)
downloadslskd-ff3b1fe36885442a6e40cac23ec8b186ef416e77.tar.gz
broken wip
Diffstat (limited to 'src/slskd/Common/Options')
-rw-r--r--src/slskd/Common/Options/InstanceOptions.cs125
-rw-r--r--src/slskd/Common/Options/RuntimeOptions.cs97
2 files changed, 167 insertions, 55 deletions
diff --git a/src/slskd/Common/Options/InstanceOptions.cs b/src/slskd/Common/Options/InstanceOptions.cs
index 09431956..52b46722 100644
--- a/src/slskd/Common/Options/InstanceOptions.cs
+++ b/src/slskd/Common/Options/InstanceOptions.cs
@@ -6,7 +6,6 @@
using System.Linq;
using Utility.CommandLine;
using Utility.EnvironmentVariables;
- using Utility.Extensions.Configuration.Yaml;
public class InstanceOptions
{
@@ -17,32 +16,32 @@
public static bool ShowVersion { get; private set; }
[EnvironmentVariable("SLSKD_DEBUG")]
- [Configuration("slskd:options:debug")]
+ [Configuration("slskd:debug")]
[Argument('d', "debug", "run in debug mode")]
public static bool Debug { get; private set; }
[EnvironmentVariable("SLSKD_NO_LOGO")]
- [Configuration("slskd:options:no_logo")]
+ [Configuration("slskd:no_logo")]
[Argument('n', "no-logo", "suppress logo on startup")]
public static bool DisableLogo { get; private set; }
[EnvironmentVariable("SLSKD_NO_AUTH")]
- [Configuration("slskd:options:no_auth")]
+ [Configuration("slskd:no_auth")]
[Argument('x', "no-auth", "disable authentication for web requests")]
public static bool DisableAuthentication { get; private set; }
[EnvironmentVariable("SLSKD_INSTANCE_NAME")]
- [Configuration("slskd:options:instance_name")]
+ [Configuration("slskd:instance_name")]
[Argument('i', "instance-name", "optional; a unique name for this instance")]
public static string InstanceName { get; private set; } = "default";
- [EnvironmentVariable("SLSKD_PROMETHEUS")]
- [Configuration("slskd:options:prometheus")]
+ [EnvironmentVariable("SLSKD_FEATURE_PROMETHEUS")]
+ [Configuration("slskd:feature:prometheus")]
[Argument('m', "prometheus", "enable collection and publish of prometheus metrics")]
public static bool EnablePrometheus { get; private set; }
- [EnvironmentVariable("SLSKD_SWAGGER")]
- [Configuration("slskd:options:swagger")]
+ [EnvironmentVariable("SLSKD_FEATURE_SWAGGER")]
+ [Configuration("slskd:feature:swagger")]
[Argument('s', "swagger", "enable swagger documentation")]
public static bool EnableSwagger { get; private set; }
@@ -83,52 +82,68 @@
public static bool EnableLoki { get; private set; }
- public static void Populate(string configurationFile = null, bool argumentsOnly = false)
- {
- if (!argumentsOnly)
- {
- try
- {
- EnvironmentVariables.Populate(typeof(InstanceOptions));
- }
- catch (Exception ex)
- {
- Console.WriteLine($"Error parsing environment variables: {ex.Message}");
- return;
- }
-
- try
- {
- var config = new ConfigurationBuilder()
- .SetBasePath(Directory.GetCurrentDirectory())
- .AddYamlFile(configurationFile, optional: true, reloadOnChange: false)
- .Build();
-
- Console.WriteLine(config.GetDebugView());
-
- config.Populate(typeof(InstanceOptions));
- }
- catch (Exception ex)
- {
- Console.WriteLine($"Error parsing configuration file '{configurationFile}': {ex.Message}");
- return;
- }
- }
-
- try
- {
- Arguments.Populate(typeof(InstanceOptions), clearExistingValues: false);
- }
- catch (Exception ex)
- {
- Console.WriteLine($"Error parsing command line input: {ex.Message}");
- return;
- }
-
- EnableLoki = !string.IsNullOrEmpty(LokiUrl);
- UrlBase = UrlBase.StartsWith("/") ? UrlBase : "/" + UrlBase;
- ContentPath = Path.GetFullPath(ContentPath);
- }
+ //public static void Populate(string configurationFile = null, bool argumentsOnly = false)
+ //{
+ // if (!argumentsOnly)
+ // {
+ // try
+ // {
+ // EnvironmentVariables.Populate(typeof(InstanceOptions));
+ // }
+ // catch (Exception ex)
+ // {
+ // Console.WriteLine($"Error parsing environment variables: {ex.Message}");
+ // return;
+ // }
+
+ // try
+ // {
+ // var config = new ConfigurationBuilder()
+ // .SetBasePath(Directory.GetCurrentDirectory())
+ // .AddMapping(new[]
+ // {
+ // new OptionMap {
+ // Description = "run in debug mode",
+ // EnvironmentVariable = "SLSK_DEBUG",
+ // ShortName = 'd',
+ // LongName = "debug",
+ // Key = "slskd:debug"
+ // },
+ // new OptionMap {
+ // Description = "optional; a unique name for this instance",
+ // EnvironmentVariable = "SLSK_INSTANCE_NAME",
+ // ShortName = 'i',
+ // LongName = "instance-name",
+ // Key = "slskd:instancename"
+ // }
+ // }, Environment.CommandLine, configurationFile, optional: true, reloadOnChange: false)
+ // .Build();
+
+ // Console.WriteLine(config.GetDebugView());
+
+ // config.Populate(typeof(InstanceOptions));
+ // }
+ // catch (Exception ex)
+ // {
+ // Console.WriteLine($"Error parsing configuration file '{configurationFile}': {ex.Message}");
+ // return;
+ // }
+ // }
+
+ // try
+ // {
+ // Arguments.Populate(typeof(InstanceOptions), clearExistingValues: false);
+ // }
+ // catch (Exception ex)
+ // {
+ // Console.WriteLine($"Error parsing command line input: {ex.Message}");
+ // return;
+ // }
+
+ // EnableLoki = !string.IsNullOrEmpty(LokiUrl);
+ // UrlBase = UrlBase.StartsWith("/") ? UrlBase : "/" + UrlBase;
+ // ContentPath = Path.GetFullPath(ContentPath);
+ //}
public static void PrintHelp()
{
diff --git a/src/slskd/Common/Options/RuntimeOptions.cs b/src/slskd/Common/Options/RuntimeOptions.cs
index d0c28e75..cded2334 100644
--- a/src/slskd/Common/Options/RuntimeOptions.cs
+++ b/src/slskd/Common/Options/RuntimeOptions.cs
@@ -1,9 +1,106 @@
namespace slskd
{
+ using System;
using System.Collections.Generic;
public class RuntimeOptions
{
+ public static IEnumerable<EnvironmentVariable> EnvironmentVariableMap => new[]
+ {
+ new EnvironmentVariable {
+ Description = "run in debug mode",
+ Name = "SLSK_DEBUG",
+ Key = "slskd:debug"
+ },
+ new EnvironmentVariable {
+ Description = "optional; a unique name for this instance",
+ Name = "SLSK_INSTANCE_NAME",
+ Key = "slskd:instancename"
+ },
+ new EnvironmentVariable {
+ Description = "enable collection and publish of prometheus metrics",
+ Name = "SLSK_PROMETHEUS",
+ Key = "slskd:feature:prometheus"
+ },
+ new EnvironmentVariable {
+ Description = "enable swagger documentation",
+ Name = "SLSK_SWAGGER",
+ Key = "slskd:feature:swagger"
+ },
+ new EnvironmentVariable {
+ Description = "jwt signing key",
+ Name = "SLSKD_JWT_KEY",
+ Key = "slskd:web:jwt:key"
+ }
+ };
+
+ public static IEnumerable<Argument> ArgumentMap => new[]
+ {
+ new Argument
+ {
+ Description = "print usage",
+ ShortName = 'h',
+ LongName = "help",
+ Key = "slskd:showhelp"
+ },
+ new Argument {
+ Description = "display version information",
+ ShortName = 'v',
+ LongName = "version",
+ Key = "slskd:showversion"
+ },
+ new Argument {
+ Description = "run in debug mode",
+ ShortName = 'd',
+ LongName = "debug",
+ Key = "slskd:debug"
+ },
+ new Argument
+ {
+ Description = "",
+ ShortName = 'i',
+ LongName = "instance-name",
+ Key = "slskd:instancename"
+ }
+ };
+
+ public class slskd
+ {
+ public bool ShowHelp { get; private set; } = false;
+ public bool ShowVersion { get; private set; } = false;
+ 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 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 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 JwtOptions
+ {
+ public int TTL { get; private set; } = 1234567890;
+ public string Key { get; private set; } = Guid.NewGuid().ToString();
+ }
+ }
+ }
+
public class Soulseek
{
public string Username { get; set; } = InstanceOptions.Username;