blob: 948ca91a2685e736d3d6f686a764aed6188d655c (
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
|
using System.Text.Json.Serialization;
namespace Spacebar.ConfigModel;
public class Config
{
[JsonPropertyName("admin")] public EndpointConfig Admin { get; set; } = null!;
[JsonPropertyName("api")] public EndpointConfig Api { get; set; } = null!;
[JsonPropertyName("gateway")] public EndpointConfig Gateway { get; set; } = null!;
[JsonPropertyName("cdn")] public EndpointConfig Cdn { get; set; } = null!;
public Config ReadFromKv(Dictionary<string, object?> kv)
{
// to object
foreach (var (key, value) in kv)
{
switch (key.Split('_', 2)[0])
{
default:
Console.WriteLine($"Unrecognized config key prefix: {key}");
continue;
}
}
return this;
}
}
public class EndpointConfig
{
[JsonPropertyName("endpointPrivate")] public string? EndpointPrivate { get; set; }
[JsonPropertyName("endpointPublic")] public string? EndpointPublic { get; set; }
public EndpointConfig ReadFromKv(Dictionary<string, object?> kv, string prefix)
{
foreach (var (key, value) in kv)
{
if (!key.StartsWith(prefix + "_")) continue;
var subKey = key[(prefix + "_").Length..];
switch (subKey)
{
case "ENDPOINT_PRIVATE":
EndpointPrivate = value?.ToString();
break;
case "ENDPOINT_PUBLIC":
EndpointPublic = value?.ToString();
break;
default:
Console.WriteLine($"Unrecognized config key: {key}");
break;
}
}
return this;
}
}
public class ApiConfig : EndpointConfig
{
[JsonPropertyName("activeVersions")] public List<string> ActiveVersions { get; set; } = null!;
[JsonPropertyName("defaultVersion")] public string DefaultVersion { get; set; } = null!;
}
|