Skip to content

Commit

Permalink
Function: env var renaming to match app configuration
Browse files Browse the repository at this point in the history
  • Loading branch information
mark-szabo committed Nov 6, 2024
1 parent b2235df commit 42b5bc6
Show file tree
Hide file tree
Showing 4 changed files with 10 additions and 9 deletions.
2 changes: 1 addition & 1 deletion CarWash.Functions/EmailExtension.cs
Original file line number Diff line number Diff line change
Expand Up @@ -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);
Expand Down
4 changes: 2 additions & 2 deletions CarWash.Functions/FunctionsDbContext.cs
Original file line number Diff line number Diff line change
Expand Up @@ -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() }));
Expand Down
9 changes: 5 additions & 4 deletions CarWash.Functions/NotificationService.cs
Original file line number Diff line number Diff line change
Expand Up @@ -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());

Expand All @@ -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);
Expand Down
4 changes: 2 additions & 2 deletions CarWash.Functions/ParkIntegrationFunction.cs
Original file line number Diff line number Diff line change
Expand Up @@ -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);

/// <summary>
/// Service Bus queue name for the chat bot's vehicle-arrived notification.
Expand Down

0 comments on commit 42b5bc6

Please sign in to comment.