-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathAppSettings.cs
More file actions
122 lines (101 loc) · 5.11 KB
/
Copy pathAppSettings.cs
File metadata and controls
122 lines (101 loc) · 5.11 KB
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
using System.Reflection;
/// <summary>
/// The application settings
/// These are loaded from the environment variables.
/// You can inherit this class and expand your own settings.
/// </summary>
public class BaseAppSettings
{
/// <summary>
/// Gets a value indicating whether verbose debugging is enabled.
/// </summary>
public bool Debug { get; init; } = Convert.ToBoolean(Environment.GetEnvironmentVariable("DEBUG") ?? "False");
/// <summary>
/// Gets the NATS server URL.
/// </summary>
public string NatsURL { get; init; } = Environment.GetEnvironmentVariable("NATS_URL") ?? "nats://localhost:4222";
/// <summary>
/// Gets the NATS credentials content.
/// </summary>
public string NatsCreds { get; init; } = Environment.GetEnvironmentVariable("NATS_CREDS") ?? "";
/// <summary>
/// Gets the assembly name reported by the application.
/// </summary>
public string AssemblyName { get; init; } = Assembly.GetEntryAssembly()?.GetName().Name ?? AppDomain.CurrentDomain.FriendlyName ?? "unknown";
/// <summary>
/// Gets the OpenTelemetry endpoint for CCNP.
/// </summary>
public string OtelEndpoint { get; init; } = Environment.GetEnvironmentVariable("OTELENDPOINT") ?? "";
/// <summary>
/// Gets the OpenTelemetry headers for CCNP.
/// </summary>
public string OtelHeaders { get; init; } = Environment.GetEnvironmentVariable("OTELHEADERS") ?? "";
/// <summary>
/// Gets the cluster name the service targets.
/// </summary>
public string Cluster { get; init; } = Environment.GetEnvironmentVariable("CLUSTER") ?? "ccnp";
/// <summary>
/// Gets the SQL connection string.
/// </summary>
public string ConnectionString { get; init; } = Environment.GetEnvironmentVariable("CNSTR") ?? "";
/// <summary>
/// Gets the Redis connection string used by distributed caching.
/// </summary>
public string RedisConnectionString { get; init; } = Environment.GetEnvironmentVariable("REDIS_CONNECTION_STRING") ?? "";
/// <summary>
/// Gets the optional Redis instance name prefix used by distributed caching.
/// </summary>
public string RedisInstanceName { get; init; } = Environment.GetEnvironmentVariable("REDIS_INSTANCE_NAME") ?? "";
/// <summary>
/// Gets a value indicating whether NATS consumers should run.
/// </summary>
public bool EnableNatsConsumers { get; init; } = Convert.ToBoolean(Environment.GetEnvironmentVariable("ENABLE_NATS_CONSUMERS") ?? "False");
/// <summary>
/// Gets a value indicating whether database migrations should run when a migrations directory is present.
/// </summary>
public bool EnableMigrations { get; init; } = Convert.ToBoolean(Environment.GetEnvironmentVariable("ENABLE_MIGRATIONS") ?? "True");
/// <summary>
/// Gets a value indicating whether REST endpoints should run.
/// </summary>
public bool EnableRestEndpoints { get; init; } = Convert.ToBoolean(Environment.GetEnvironmentVariable("ENABLE_REST_ENDPOINTS") ?? "True");
/// <summary>
/// Gets the port used by the lightweight REST endpoint server.
/// </summary>
public int RestPort { get; init; } = int.TryParse(Environment.GetEnvironmentVariable("REST_PORT"), out var restPort) ? restPort : 8080;
/// <summary>
/// Gets the shared secret required by REST endpoints marked as auth-required.
/// </summary>
public string RestApiSecret { get; init; } = Environment.GetEnvironmentVariable("REST_API_SECRET") ?? "";
/// <summary>
/// Gets the comma-separated TigerBeetle address list. e.g. 127.0.0.1:3000,127.0.0.1:3001
/// </summary>
public String TigerBeetleAddresses { get; init; } = Environment.GetEnvironmentVariable("TB_ADDRESSES") ?? "";
/// <summary>
/// Gets the TigerBeetle cluster ID. Defaults to 0 if TB_CLUSTER_ID is missing or invalid.
/// </summary>
public ulong TigerBeetleClusterId { get; init; } = ParseTigerBeetleClusterId();
/// <summary>
/// Gets a value indicating whether Snowflake ID generation (IdGen) is enabled.
/// When enabled, <see cref="SnowflakeGeneratorId"/> must be set to a unique,
/// stable per-node value or the application will error out at startup.
/// </summary>
public bool EnableSnowflakeId { get; init; } = Convert.ToBoolean(Environment.GetEnvironmentVariable("ENABLE_SNOWFLAKE_ID") ?? "False");
/// <summary>
/// Gets the Snowflake generator (node) id used by IdGen. Returns <c>-1</c> when
/// SNOWFLAKE_GENERATOR_ID is missing or invalid so the host can distinguish
/// "not configured" from a legitimate <c>0</c> and fail fast at startup.
/// </summary>
public int SnowflakeGeneratorId { get; init; } = ParseSnowflakeGeneratorId();
private static ulong ParseTigerBeetleClusterId()
{
return ulong.TryParse(Environment.GetEnvironmentVariable("TB_CLUSTER_ID"), out var clusterId)
? clusterId
: 0;
}
private static int ParseSnowflakeGeneratorId()
{
return int.TryParse(Environment.GetEnvironmentVariable("SNOWFLAKE_GENERATOR_ID"), out var generatorId)
? generatorId
: -1;
}
}