aboutsummaryrefslogtreecommitdiffstats
path: root/src/slskd/Configuration.cs
blob: c09896a579f1c95de6988b17f1bf8a87b99a8931 (plain) (blame)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
namespace slskd
{
    using System;
    using System.Collections.Generic;
    
    public record Option(char ShortName, string LongName, string EnvironmentVariable, Type Type, string Key, string Description = null);

    public static class Configuration
    {
        public static EnvironmentVariable ToEnvironmentVariable(this Option option) 
            => new EnvironmentVariable(option.EnvironmentVariable, option.Type, option.Key, option.Description);

        public static CommandLineArgument ToCommandLineArgument(this Option option)
            => new CommandLineArgument(option.ShortName, option.LongName, option.Type, option.Key, option.Description);

        public static IEnumerable<Option> Map => new Option[]
        {
            new(
                ShortName: 'v',
                LongName: "version",
                EnvironmentVariable: null,
                Type: typeof(bool),
                Key: null,
                Description: "display version information"),
            new(
                ShortName: 'h',
                LongName: "help",
                EnvironmentVariable: null,
                Type: typeof(bool),
                Key: null,
                Description: "display command line usage"),
            new(
                ShortName: 'e',
                LongName: "envars",
                EnvironmentVariable: null,
                Type: typeof(bool),
                Key: null,
                Description: "display environment variables"),
            new(
                ShortName: 'd',
                LongName: "debug",
                EnvironmentVariable: "DEBUG",
                Type: typeof(bool),
                Key: "slskd:debug",
                Description: "run in debug mode"),
            new(
                ShortName: 'n',
                LongName: "no-logo",
                EnvironmentVariable: "NO_LOGO",
                Type: typeof(bool),
                Key: "slskd:nologo",
                Description: "suppress logo on startup"),
            new(
                ShortName: 'x',
                LongName: "no-auth",
                EnvironmentVariable: "NO_AUTH",
                Type: typeof(bool),
                Key: "slskd:noauth",
                Description: "disable authentication for web requests"),
            new(
                ShortName: 'i',
                LongName: "instance-name",
                EnvironmentVariable: "INSTANCE_NAME",
                Type: typeof(string),
                Key: "slskd:instancename",
                Description: "optional; a unique name for this instance"),
            new(
                ShortName: 'm',
                LongName: "prometheus",
                EnvironmentVariable: "PROMETHEUS",
                Type: typeof(bool),
                Key:  "slskd:feature:prometheus",
                Description: "enable collection and publishing of prometheus metrics"),
            new(
                ShortName: 's',
                LongName: "swagger",
                EnvironmentVariable: "SWAGGER",
                Type: typeof(bool),
                Key: "slskd:feature:swagger",
                Description: "enable swagger documentation and UI"),
            new(
                ShortName: 'l',
                LongName: "loki",
                EnvironmentVariable: "LOKI",
                Type: typeof(string),
                Key: "slskd:logger:loki",
                Description: "optional; the url to a Grafana Loki instance to which to log"),
            new(
                ShortName: 'b',
                LongName: "url-base",
                EnvironmentVariable: "URL_BASE",
                Type: typeof(string),
                Key: "slskd:web:urlbase",
                Description: "base url for web requests"),
            new(
                ShortName: 'c', 
                LongName: "content-path", 
                EnvironmentVariable: "CONTENT_PATH",
                Type: typeof(string), 
                Key: "slskd:web:contentpath", 
                Description: "path to static web content"),
            new(
                ShortName: 'k', 
                LongName: "jwt-key", 
                EnvironmentVariable: "JWT_KEY",
                Type: typeof(string), 
                Key: "slskd:web:jwt:key", 
                Description: "the key with which to sign JWTs"),
            new(
                ShortName: 't', 
                LongName: "jwt-ttl", 
                EnvironmentVariable: "JWT_TTL",
                Type: typeof(int), 
                Key: "slskd:web:jwt:ttl", 
                Description: "the TTL for JWTs"),
            new(
                ShortName: 'u', 
                LongName: "username", 
                EnvironmentVariable: "USERNAME",
                Type: typeof(string), 
                Key: "soulseek:username", 
                Description: "the username for the Soulseek network"),
            new(
                ShortName: 'p', 
                LongName: "password", 
                EnvironmentVariable: "PASSWORD",
                Type: typeof(string), 
                Key: "soulseek:password", 
                Description: "the password for the Soulseek network")
        };

        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 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; }
            public string Password { get; set; }
            public int ListenPort { get; set; } = 50000;
            public DistributedNetworkOptions DistributedNetwork { get; set; }
            public ConnectionOptions Connection { get; set; }

            public class DistributedNetworkOptions
            {
                public bool Enabled { get; set; } = true;
                public int ChildLimit { get; set; } = 10;
            }

            public class ConnectionOptions
            {
                public TimeoutOptions Timeout { get; set; }
                public BufferOptions Buffer { get; set; }

                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 class Authentication
        {
            public IEnumerable<User> Users { get; set; }
            public IEnumerable<ApiKey> ApiKeys { get; set; }

            public class User
            {
                public string Name { get; set; }
                public string Password { get; set; }
                public Role Role { get; set; }
            }

            public class ApiKey
            {
                public string Key { get; set; }
                public Role Role { get; set; }
            }
        }
    }
}