diff --git a/LCU.Webapps.Marketing.SPIT/LCU.Webapps.Marketing.SPIT/LCU.Webapps.Marketing.SPIT/Program.cs b/LCU.Webapps.Marketing.SPIT/LCU.Webapps.Marketing.SPIT/LCU.Webapps.Marketing.SPIT/Program.cs index a0d3799..f5cf7ff 100644 --- a/LCU.Webapps.Marketing.SPIT/LCU.Webapps.Marketing.SPIT/LCU.Webapps.Marketing.SPIT/Program.cs +++ b/LCU.Webapps.Marketing.SPIT/LCU.Webapps.Marketing.SPIT/LCU.Webapps.Marketing.SPIT/Program.cs @@ -1,3 +1,5 @@ +using System.Collections.Generic; +using System.IO; using Microsoft.AspNetCore.Hosting; using Microsoft.Extensions.Configuration; using Microsoft.Extensions.Hosting; @@ -21,10 +23,9 @@ namespace LCU.Webapps.Marketing.SPIT builder.AddJsonFile("/app/config/workload-appsettings/appsettings.json", optional: true, reloadOnChange: true); builder.AddJsonFile("/vault/secrets/spit-seq-api-key.json", optional: true, reloadOnChange: true); builder.AddJsonFile("/vault/secrets/spit-primary-subscription-key.json", optional: true, reloadOnChange: true); - builder.AddJsonFile("/vault/secrets/speech-api-key.json", optional: true, reloadOnChange: true); - builder.AddJsonFile("/vault/secrets/speech-endpoint.json", optional: true, reloadOnChange: true); builder.AddJsonFile("/vault/secrets/spit-azuread-client-id.json", optional: true, reloadOnChange: true); builder.AddJsonFile("/vault/secrets/spit-azuread-client-secret.json", optional: true, reloadOnChange: true); + builder.AddInMemoryCollection(LoadPlainTextSpeechSecrets()); }) .ConfigureWebHostDefaults(webBuilder => { @@ -32,5 +33,30 @@ namespace LCU.Webapps.Marketing.SPIT .UseSetting(WebHostDefaults.DetailedErrorsKey, "true") .UseSerilog(); }); + + private static IDictionary LoadPlainTextSpeechSecrets() + { + var configValues = new Dictionary(); + + AddSecretValue(configValues, "/vault/secrets/speech-api-key.json", "Primary:SpeechApiKey"); + AddSecretValue(configValues, "/vault/secrets/speech-endpoint.json", "Primary:SpeechEndpoint"); + + return configValues; + } + + private static void AddSecretValue(IDictionary configValues, string path, string key) + { + if (!File.Exists(path)) + { + return; + } + + var value = File.ReadAllText(path)?.Trim(); + + if (!string.IsNullOrWhiteSpace(value)) + { + configValues[key] = value; + } + } } }