diff --git a/CarWash.Functions/EmailExtension.cs b/CarWash.Functions/EmailExtension.cs index 2047864..35eb5ce 100644 --- a/CarWash.Functions/EmailExtension.cs +++ b/CarWash.Functions/EmailExtension.cs @@ -20,7 +20,7 @@ public static async Task Send(this Email email) if (email == null) return; // Load connection string from appsettings - var connectionString = Environment.GetEnvironmentVariable("StorageAccount", EnvironmentVariableTarget.Process); + var connectionString = Environment.GetEnvironmentVariable("ConnectionStrings:StorageAccount", EnvironmentVariableTarget.Process); // Parse the connection string and return a reference to the storage account. var storage = new QueueServiceClient(connectionString); diff --git a/CarWash.Functions/FunctionsDbContext.cs b/CarWash.Functions/FunctionsDbContext.cs index 3d08627..1ce9dd7 100644 --- a/CarWash.Functions/FunctionsDbContext.cs +++ b/CarWash.Functions/FunctionsDbContext.cs @@ -10,8 +10,8 @@ internal class FunctionsDbContext : DbContext, IPushDbContext { protected override void OnConfiguring(DbContextOptionsBuilder optionsBuilder) { - var connectionString = Environment.GetEnvironmentVariable("Database", EnvironmentVariableTarget.Process); - if (string.IsNullOrEmpty(connectionString)) throw new Exception("Application setting 'SqlDatabase' was not found. Add it on the Azure portal!"); + var connectionString = Environment.GetEnvironmentVariable("ConnectionStrings:SqlDatabase", EnvironmentVariableTarget.Process); + if (string.IsNullOrEmpty(connectionString)) throw new Exception("Application setting 'ConnectionStrings:SqlDatabase' was not found. Add it on the Azure portal!"); optionsBuilder.UseSqlServer(connectionString); var isDevelopment = Environment.GetEnvironmentVariable("Environment", EnvironmentVariableTarget.Process) == "Development"; if (isDevelopment) optionsBuilder.UseLoggerFactory(new LoggerFactory(new[] { new DebugLoggerProvider() })); diff --git a/CarWash.Functions/NotificationService.cs b/CarWash.Functions/NotificationService.cs index 762c075..456debe 100644 --- a/CarWash.Functions/NotificationService.cs +++ b/CarWash.Functions/NotificationService.cs @@ -21,9 +21,9 @@ public static async Task SendEmailReminder(Reservation reservation, Email email) public static async Task SendPushReminder(Reservation reservation, IPushDbContext context, Notification notification) { - var vapidSubject = Environment.GetEnvironmentVariable("VapidSubject", EnvironmentVariableTarget.Process); - var vapidPublicKey = Environment.GetEnvironmentVariable("VapidPublicKey", EnvironmentVariableTarget.Process); - var vapidPrivateKey = Environment.GetEnvironmentVariable("VapidPrivateKey", EnvironmentVariableTarget.Process); + var vapidSubject = Environment.GetEnvironmentVariable("Vapid:Subject", EnvironmentVariableTarget.Process); + var vapidPublicKey = Environment.GetEnvironmentVariable("Vapid:PublicKey", EnvironmentVariableTarget.Process); + var vapidPrivateKey = Environment.GetEnvironmentVariable("Vapid:PrivateKey", EnvironmentVariableTarget.Process); var pushService = new PushService(context, vapidSubject, vapidPublicKey, vapidPrivateKey, new Microsoft.ApplicationInsights.TelemetryClient()); @@ -36,7 +36,8 @@ public static async Task SendPushReminder(Reservation reservation, IPushDbContex public static async Task SendBotReminderMessage(Reservation reservation, string queueName) { - var connectionString = Environment.GetEnvironmentVariable("ServiceBus", EnvironmentVariableTarget.Process); + var connectionString = Environment.GetEnvironmentVariable("ConnectionStrings:ServiceBus", EnvironmentVariableTarget.Process) ?? + throw new Exception($"Failed to send bot message: ServiceBus connection string is not provided."); // since ServiceBusClient implements IAsyncDisposable we create it with "await using" await using var client = new ServiceBusClient(connectionString); diff --git a/CarWash.Functions/ParkIntegrationFunction.cs b/CarWash.Functions/ParkIntegrationFunction.cs index c4abf7c..22387f1 100644 --- a/CarWash.Functions/ParkIntegrationFunction.cs +++ b/CarWash.Functions/ParkIntegrationFunction.cs @@ -20,8 +20,8 @@ public static class ParkIntegrationFunction { private static readonly HttpClient _client = new HttpClient(); private static readonly FunctionsDbContext _context = new FunctionsDbContext(); - private static readonly string _parkApiEmail = Environment.GetEnvironmentVariable("ParkApiEmail", EnvironmentVariableTarget.Process); - private static readonly string _parkApiPassword = Environment.GetEnvironmentVariable("ParkApiPassword", EnvironmentVariableTarget.Process); + private static readonly string _parkApiEmail = Environment.GetEnvironmentVariable("ParkApi:Email", EnvironmentVariableTarget.Process); + private static readonly string _parkApiPassword = Environment.GetEnvironmentVariable("ParkApi:Password", EnvironmentVariableTarget.Process); /// /// Service Bus queue name for the chat bot's vehicle-arrived notification.