From b75e59da2fc49139ff6663692ac9af9d48ad0629 Mon Sep 17 00:00:00 2001 From: spiral Date: Mon, 13 Jun 2022 15:23:13 -0400 Subject: [PATCH] feat: allow specifying database password in separate config parameter --- PluralKit.Core/CoreConfig.cs | 1 + PluralKit.Core/Database/Database.cs | 9 +++++++-- 2 files changed, 8 insertions(+), 2 deletions(-) diff --git a/PluralKit.Core/CoreConfig.cs b/PluralKit.Core/CoreConfig.cs index 5c2a11f0..a4f06c7a 100644 --- a/PluralKit.Core/CoreConfig.cs +++ b/PluralKit.Core/CoreConfig.cs @@ -5,6 +5,7 @@ namespace PluralKit.Core; public class CoreConfig { public string Database { get; set; } + public string? DatabasePassword { get; set; } public string RedisAddr { get; set; } public bool UseRedisMetrics { get; set; } = false; public string SentryUrl { get; set; } diff --git a/PluralKit.Core/Database/Database.cs b/PluralKit.Core/Database/Database.cs index 8d3547eb..e5e1b0d0 100644 --- a/PluralKit.Core/Database/Database.cs +++ b/PluralKit.Core/Database/Database.cs @@ -35,7 +35,7 @@ internal partial class Database: IDatabase _migrator = migrator; _logger = logger.ForContext(); - _connectionString = new NpgsqlConnectionStringBuilder(_config.Database) + var connectionString = new NpgsqlConnectionStringBuilder(_config.Database) { Pooling = true, Enlist = false, @@ -43,7 +43,12 @@ internal partial class Database: IDatabase // Lower timeout than default (15s -> 2s), should ideally fail-fast instead of hanging Timeout = 2 - }.ConnectionString; + }; + + if (_config.DatabasePassword != null) + connectionString.Password = _config.DatabasePassword; + + _connectionString = connectionString.ConnectionString; } private static readonly PostgresCompiler _compiler = new();