diff options
Diffstat (limited to 'server')
| -rw-r--r-- | server/src/Services/VaultService.cs | 42 |
1 files changed, 39 insertions, 3 deletions
diff --git a/server/src/Services/VaultService.cs b/server/src/Services/VaultService.cs index a7ae57f..732911a 100644 --- a/server/src/Services/VaultService.cs +++ b/server/src/Services/VaultService.cs @@ -7,9 +7,10 @@ public class VaultService private readonly HttpClient _client; private readonly IMemoryCache _cache; private readonly IConfiguration _configuration; + private readonly ILogger<VaultService> _logger; private int CACHE_TTL { get; set; } - public VaultService(HttpClient client, IConfiguration configuration, IMemoryCache cache) { + public VaultService(HttpClient client, IConfiguration configuration, IMemoryCache cache, ILogger<VaultService> logger) { var token = configuration.GetValue<string>(AppEnvironmentVariables.VAULT_TOKEN); var vaultUrl = configuration.GetValue<string>(AppEnvironmentVariables.VAULT_URL); CACHE_TTL = configuration.GetValue(AppEnvironmentVariables.VAULT_CACHE_TTL, 60 * 60 * 12); @@ -20,12 +21,13 @@ public class VaultService _client = client; _cache = cache; _configuration = configuration; + _logger = logger; } public static object Data { get; set; } public T Get<T>(string path) { - return _cache.GetOrCreate(AppConstants.VAULT_CACHE_KEY, + var result = _cache.GetOrCreate(AppConstants.VAULT_CACHE_KEY, cacheEntry => { cacheEntry.AbsoluteExpirationRelativeToNow = TimeSpan.FromSeconds(CACHE_TTL); var getSecretResponse = _client.GetFromJsonAsync<GetSecretResponse<T>>("/v1/kv/data/" + path).Result; @@ -42,6 +44,7 @@ public class VaultService }); return getSecretResponse.Data.Data ?? default; }); + return result; } public T Refresh<T>(string path) { @@ -64,7 +67,40 @@ public class VaultService public AppConfiguration GetCurrentAppConfiguration() { var path = _configuration.GetValue<string>(AppEnvironmentVariables.MAIN_CONFIG_SHEET); - return Get<AppConfiguration>(path); + var result = Get<AppConfiguration>(path); + var overwrites = new { + DB_HOST = _configuration.GetValue("OVERWRITE_DB_HOST", string.Empty), + DB_PORT = _configuration.GetValue("OVERWRITE_DB_PORT", string.Empty), + DB_USER = _configuration.GetValue("OVERWRITE_DB_USER", string.Empty), + DB_PASSWORD = _configuration.GetValue("OVERWRITE_DB_PASSWORD", string.Empty), + DB_NAME = _configuration.GetValue("OVERWRITE_DB_NAME", string.Empty), + }; + if (overwrites.DB_HOST.HasValue()) { + _logger.LogInformation("OVERWRITE_DB_HOST is specified, using it's value: " + overwrites.DB_HOST); + result.DB_HOST = overwrites.DB_HOST; + } + + if (overwrites.DB_PORT.HasValue()) { + _logger.LogInformation("OVERWRITE_DB_PORT is specified, using it's value: " + overwrites.DB_PORT); + result.DB_PORT = overwrites.DB_PORT; + } + + if (overwrites.DB_USER.HasValue()) { + _logger.LogInformation("OVERWRITE_DB_USER is specified, using it's value: " + overwrites.DB_USER); + result.DB_USER = overwrites.DB_USER; + } + + if (overwrites.DB_PASSWORD.HasValue()) { + _logger.LogInformation("OVERWRITE_DB_PASSWORD is specified, using it's value: " + "(redacted)"); + result.DB_PASSWORD = overwrites.DB_PASSWORD; + } + + if (overwrites.DB_NAME.HasValue()) { + _logger.LogInformation("OVERWRITE_DB_NAME is specified, using it's value: " + overwrites.DB_NAME); + result.DB_NAME = overwrites.DB_NAME; + } + + return result; } public AppConfiguration RefreshCurrentAppConfiguration() { |
