From 55ac6f03a23eca5f5ec9ff57ff4e16e9575770c6 Mon Sep 17 00:00:00 2001 From: ivarlovlie Date: Tue, 29 Nov 2022 13:15:17 +0900 Subject: feat: Use postmarks http api instead of smtp --- code/api/src/Services/VaultService.cs | 61 ++++++++++++----------------------- 1 file changed, 21 insertions(+), 40 deletions(-) (limited to 'code/api/src/Services/VaultService.cs') diff --git a/code/api/src/Services/VaultService.cs b/code/api/src/Services/VaultService.cs index 8139985..d4ac775 100644 --- a/code/api/src/Services/VaultService.cs +++ b/code/api/src/Services/VaultService.cs @@ -10,8 +10,7 @@ public class VaultService private readonly ILogger _logger; private int CACHE_TTL { get; set; } - public VaultService(HttpClient client, IConfiguration configuration, IMemoryCache cache, ILogger logger) - { + public VaultService(HttpClient client, IConfiguration configuration, IMemoryCache cache, ILogger logger) { var token = configuration.GetValue(AppEnvironmentVariables.VAULT_TOKEN); var vaultUrl = configuration.GetValue(AppEnvironmentVariables.VAULT_URL); CACHE_TTL = configuration.GetValue(AppEnvironmentVariables.VAULT_CACHE_TTL, 60 * 60 * 12); @@ -25,20 +24,16 @@ public class VaultService _logger = logger; } - public T Get(string path) - { + public T Get(string path) { var result = _cache.GetOrCreate(AppConstants.VAULT_CACHE_KEY, - cacheEntry => - { + cacheEntry => { cacheEntry.AbsoluteExpirationRelativeToNow = TimeSpan.FromSeconds(CACHE_TTL); var getSecretResponse = _client.GetFromJsonAsync>("/v1/kv/data/" + path).Result; - if (getSecretResponse == null) - { + if (getSecretResponse == null) { return default; } - Log.Debug("Setting new vault cache, " + new - { + Log.Debug("Setting new vault cache, " + new { PATH = path, CACHE_TTL, Data = JsonSerializer.Serialize(getSecretResponse.Data.Data) @@ -48,42 +43,35 @@ public class VaultService return result; } - public T Refresh(string path) - { + public T Refresh(string path) { _cache.Remove(AppConstants.VAULT_CACHE_KEY); CACHE_TTL = _configuration.GetValue(AppEnvironmentVariables.VAULT_CACHE_TTL, 60 * 60 * 12); return Get(path); } - public async Task RenewTokenAsync(string token) - { + public async Task RenewTokenAsync(string token) { var response = await _client.PostAsJsonAsync("v1/auth/token/renew", - new - { + new { Token = token }); - if (response.IsSuccessStatusCode) - { + if (response.IsSuccessStatusCode) { return await response.Content.ReadFromJsonAsync(); } return default; } - public AppConfiguration GetCurrentAppConfiguration() - { + public AppConfiguration GetCurrentAppConfiguration() { #if DEBUG var isInFlightMode = true; - if (isInFlightMode) - { - return new AppConfiguration() - { - EMAIL_FROM_ADDRESS = "local@dev", - EMAIL_FROM_DISPLAY_NAME = "Friendly neighbourhood developer", + if (isInFlightMode) { + return new AppConfiguration() { + EMAIL_FROM_ADDRESS = "heydev@greatoffice.life", DB_HOST = "localhost", DB_PORT = "5432", DB_NAME = "greatoffice_ivar_dev", DB_PASSWORD = "ivar123", + POSTMARK_TOKEN = "b530c311-45c7-43e5-aa48-f2c992886e51", DB_USER = "postgres", QUARTZ_DB_HOST = "localhost", QUARTZ_DB_PORT = "5432", @@ -97,8 +85,7 @@ public class VaultService var path = _configuration.GetValue(AppEnvironmentVariables.MAIN_CONFIG_SHEET); var result = Get(path); - var overwrites = new - { + 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), @@ -106,32 +93,27 @@ public class VaultService DB_NAME = _configuration.GetValue("OVERWRITE_DB_NAME", string.Empty), }; - if (overwrites.DB_HOST.HasValue()) - { + if (overwrites.DB_HOST.HasValue()) { _logger.LogInformation("OVERWRITE_DB_HOST is specified, using it's value: {DB_HOST}", overwrites.DB_HOST); result.DB_HOST = overwrites.DB_HOST; } - if (overwrites.DB_PORT.HasValue()) - { + if (overwrites.DB_PORT.HasValue()) { _logger.LogInformation("OVERWRITE_DB_PORT is specified, using it's value: {DB_PORT}", overwrites.DB_PORT); result.DB_PORT = overwrites.DB_PORT; } - if (overwrites.DB_USER.HasValue()) - { + if (overwrites.DB_USER.HasValue()) { _logger.LogInformation("OVERWRITE_DB_USER is specified, using it's value: {DB_USER}", overwrites.DB_USER); result.DB_USER = overwrites.DB_USER; } - if (overwrites.DB_PASSWORD.HasValue()) - { + 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()) - { + if (overwrites.DB_NAME.HasValue()) { _logger.LogInformation("OVERWRITE_DB_NAME is specified, using it's value: {DB_NAME}", overwrites.DB_NAME); result.DB_NAME = overwrites.DB_NAME; } @@ -139,8 +121,7 @@ public class VaultService return result; } - public AppConfiguration RefreshCurrentAppConfiguration() - { + public AppConfiguration RefreshCurrentAppConfiguration() { var path = _configuration.GetValue(AppEnvironmentVariables.MAIN_CONFIG_SHEET); return Refresh(path); } -- cgit v1.3