mirror of
https://github.com/aaronpo97/the-biergarten-app.git
synced 2026-10-14 17:54:42 +00:00
* Remove restating comments in backend * Remove restating comments in frontend stories * Remove restating comments in pipeline * Remove restating comments in pipeline scripts * Restore location-clear comment in BreweryRepository * Remove stale/restating comments found in second pass * Restore mock curated-data branch comment in main.cc * Remove more restating/filler comments in backend * Document account-management endpoints, compose files, and env generator * Squashed commit of the following: commit a8a5b8abd9969859c695092fae6990d03b2135ed Author: Aaron Po <aaron.po97@gmail.com> Date: Sun Aug 23 23:53:56 2026 -0400 Add reverse geocoding for brewery street addresses (#245) * Add geocoding to seed application, remove postal codes from generator Update comments * Update pipeline class diagram for OpenAI generator * Update pipeline activity diagram for brewery coordinates and OpenAI backend * Add mailpit, production, db-only, and minimal environments to deployment diagram * Fix authentication flow diagram for Identity migration * Add account-management flows to authentication diagram * Fix database schema diagram note referencing removed AuthRepository
63 lines
2.3 KiB
C#
63 lines
2.3 KiB
C#
using Microsoft.Data.SqlClient;
|
|
using Microsoft.Extensions.Configuration;
|
|
|
|
namespace Infrastructure.Sql;
|
|
|
|
/// <summary>
|
|
/// Helper for building SQL Server connection strings from configuration
|
|
/// (backed by the <c>DB_*</c> environment variables).
|
|
/// </summary>
|
|
public static class SqlConnectionStringHelper
|
|
{
|
|
/// <summary>
|
|
/// Builds a SQL Server connection string from configuration.
|
|
/// </summary>
|
|
/// <remarks>Throws <see cref="InvalidOperationException" /> if DB_SERVER, DB_NAME, DB_USER, or DB_PASSWORD is unset.</remarks>
|
|
/// <param name="configuration">The configuration to read the <c>DB_*</c> values from.</param>
|
|
/// <param name="databaseName">If null, falls back to the DB_NAME configuration value.</param>
|
|
public static string BuildConnectionString(
|
|
IConfiguration configuration,
|
|
string? databaseName = null
|
|
)
|
|
{
|
|
string server = Required(configuration, "DB_SERVER");
|
|
string dbName = databaseName ?? Required(configuration, "DB_NAME");
|
|
string user = Required(configuration, "DB_USER");
|
|
string password = Required(configuration, "DB_PASSWORD");
|
|
|
|
SqlConnectionStringBuilder builder = new()
|
|
{
|
|
DataSource = server,
|
|
InitialCatalog = dbName,
|
|
UserID = user,
|
|
Password = password,
|
|
TrustServerCertificate = ResolveTrustServerCertificate(configuration),
|
|
Encrypt = true,
|
|
};
|
|
|
|
return builder.ConnectionString;
|
|
}
|
|
|
|
public static string BuildMasterConnectionString(IConfiguration configuration)
|
|
{
|
|
return BuildConnectionString(configuration, "master");
|
|
}
|
|
|
|
/// <summary>
|
|
/// Resolves the <c>DB_TRUST_SERVER_CERTIFICATE</c> configuration value, defaulting to
|
|
/// <c>true</c> when it is unset or not a valid boolean.
|
|
/// </summary>
|
|
private static bool ResolveTrustServerCertificate(IConfiguration configuration)
|
|
{
|
|
return !bool.TryParse(
|
|
configuration["DB_TRUST_SERVER_CERTIFICATE"],
|
|
out bool trustServerCertificate
|
|
)
|
|
|| trustServerCertificate;
|
|
}
|
|
|
|
private static string Required(IConfiguration configuration, string key) =>
|
|
configuration[key]
|
|
?? throw new InvalidOperationException($"The {key} environment variable is not set.");
|
|
}
|