From 8b491fc7f4ae1708e22610fe35fb2ec4ee1ce504 Mon Sep 17 00:00:00 2001 From: Eren Yilmaz Date: Tue, 1 Jul 2025 17:28:48 +0300 Subject: [PATCH 1/9] added tbp authentication support --- .../Providers/PostgresConnectionProvider.cs | 73 ++++++++++++++++++- 1 file changed, 69 insertions(+), 4 deletions(-) diff --git a/src/Database/Providers/PostgresConnectionProvider.cs b/src/Database/Providers/PostgresConnectionProvider.cs index fcd0378..10dd99c 100644 --- a/src/Database/Providers/PostgresConnectionProvider.cs +++ b/src/Database/Providers/PostgresConnectionProvider.cs @@ -1,5 +1,7 @@ +using System; using System.Data; using System.Diagnostics.CodeAnalysis; +using System.IO; using Microsoft.Extensions.Configuration; using Npgsql; using PollingOutboxPublisher.Database.Providers.Interfaces; @@ -14,13 +16,22 @@ public class PostgresConnectionProvider : IPostgresConnectionProvider public PostgresConnectionProvider(IConfiguration configuration) { - var connectionString = configuration.GetValue("ConnectionString"); - if (string.IsNullOrWhiteSpace(connectionString)) + if (configuration.GetValue("IsTbpAuthenticationEnabled") is true) { - throw new MissingConfigurationException("ConnectionString"); + var postgresqlCredentials = GetTbpAuthenticationCredentials(configuration); + var postgresqlUsernamePassword = GetPostgresqlUsernameAndPassword(postgresqlCredentials.clusterName); + _connectionString = GenerateConnectionString(postgresqlUsernamePassword.userName, postgresqlUsernamePassword.password, postgresqlCredentials.host, postgresqlCredentials.database, postgresqlCredentials.port); } + else + { + var connectionString = configuration.GetValue("ConnectionString"); + if (string.IsNullOrWhiteSpace(connectionString)) + { + throw new MissingConfigurationException("ConnectionString"); + } - _connectionString = connectionString; + _connectionString = connectionString; + } } public IDbConnection CreateConnection() @@ -29,4 +40,58 @@ public IDbConnection CreateConnection() public IDbConnection CreateConnectionForReadOnly() => new NpgsqlConnection(_connectionString); + + private static (string userName, string password) GetPostgresqlUsernameAndPassword(string clusterName) + { + var filePath = Path.Combine("config", $"postgresql-{clusterName}.json"); + + if (!File.Exists(filePath)) + { + throw new FileNotFoundException($"Postgresql credentials file not found: {filePath}"); + } + + var postgresqlCredentials= new ConfigurationBuilder() + .AddJsonFile(filePath) + .Build(); + + var username = postgresqlCredentials["username"]; + var password = postgresqlCredentials["password"]; + return (username, password); + } + + private static (string clusterName, string host, string database, int port) GetTbpAuthenticationCredentials(IConfiguration configuration) + { + var clusterName = configuration.GetValue("TbpAuthenticationCredentials:ClusterName"); + if (string.IsNullOrWhiteSpace(clusterName)) + { + throw new MissingConfigurationException("TbpAuthenticationCredentials:ClusterName"); + } + + var host = configuration.GetValue("TbpAuthenticationCredentials:Host"); + if (string.IsNullOrWhiteSpace(host)) + { + throw new MissingConfigurationException("TbpAuthenticationCredentials:Host"); + } + + var dbName = configuration.GetValue("TbpAuthenticationCredentials:Database"); + if (string.IsNullOrWhiteSpace(host)) + { + throw new MissingConfigurationException("TbpAuthenticationCredentials:Database"); + } + + var port = configuration.GetValue("TbpAuthenticationCredentials:Port"); + if ((string.IsNullOrWhiteSpace(port) || int.TryParse(port, out int parsedPort)) == false) + { + throw new MissingConfigurationException("TbpAuthenticationCredentials:Port"); + } + + return (clusterName, host, dbName, int.Parse(port!)); + } + + private static string GenerateConnectionString(string userName, string password, string host, string database, int port) + { + return $"User ID={userName};Password={password};Server={host};Port={port};Database={database};Pooling=true;TrustServerCertificate=true;"; + } + + } \ No newline at end of file From 5e39c97374623519c25777d3852be386b48db1e5 Mon Sep 17 00:00:00 2001 From: Eren Yilmaz Date: Tue, 1 Jul 2025 17:31:52 +0300 Subject: [PATCH 2/9] added appName --- .../Providers/PostgresConnectionProvider.cs | 18 ++++++++++++------ 1 file changed, 12 insertions(+), 6 deletions(-) diff --git a/src/Database/Providers/PostgresConnectionProvider.cs b/src/Database/Providers/PostgresConnectionProvider.cs index 10dd99c..4064707 100644 --- a/src/Database/Providers/PostgresConnectionProvider.cs +++ b/src/Database/Providers/PostgresConnectionProvider.cs @@ -20,7 +20,7 @@ public PostgresConnectionProvider(IConfiguration configuration) { var postgresqlCredentials = GetTbpAuthenticationCredentials(configuration); var postgresqlUsernamePassword = GetPostgresqlUsernameAndPassword(postgresqlCredentials.clusterName); - _connectionString = GenerateConnectionString(postgresqlUsernamePassword.userName, postgresqlUsernamePassword.password, postgresqlCredentials.host, postgresqlCredentials.database, postgresqlCredentials.port); + _connectionString = GenerateConnectionString(postgresqlUsernamePassword.userName, postgresqlUsernamePassword.password, postgresqlCredentials.host, postgresqlCredentials.database, postgresqlCredentials.port, postgresqlCredentials.appName); } else { @@ -30,7 +30,7 @@ public PostgresConnectionProvider(IConfiguration configuration) throw new MissingConfigurationException("ConnectionString"); } - _connectionString = connectionString; + _connectionString = connectionString; } } @@ -59,7 +59,7 @@ private static (string userName, string password) GetPostgresqlUsernameAndPasswo return (username, password); } - private static (string clusterName, string host, string database, int port) GetTbpAuthenticationCredentials(IConfiguration configuration) + private static (string clusterName, string host, string database, int port, string appName) GetTbpAuthenticationCredentials(IConfiguration configuration) { var clusterName = configuration.GetValue("TbpAuthenticationCredentials:ClusterName"); if (string.IsNullOrWhiteSpace(clusterName)) @@ -85,12 +85,18 @@ private static (string clusterName, string host, string database, int port) GetT throw new MissingConfigurationException("TbpAuthenticationCredentials:Port"); } - return (clusterName, host, dbName, int.Parse(port!)); + var appName = configuration.GetValue("TbpAuthenticationCredentials:ApplicationName"); + if (string.IsNullOrWhiteSpace(appName)) + { + throw new MissingConfigurationException("TbpAuthenticationCredentials:ApplicationName"); + } + + return (clusterName, host, dbName, int.Parse(port!), appName); } - private static string GenerateConnectionString(string userName, string password, string host, string database, int port) + private static string GenerateConnectionString(string userName, string password, string host, string database, int port, string appName) { - return $"User ID={userName};Password={password};Server={host};Port={port};Database={database};Pooling=true;TrustServerCertificate=true;"; + return $"User ID={userName};Password={password};Server={host};Port={port};Database={database};Pooling=true;TrustServerCertificate=true;ApplicationName={appName};"; } From d7aab412bafff6387681b003f77573904b7e483f Mon Sep 17 00:00:00 2001 From: Eren Yilmaz Date: Tue, 1 Jul 2025 19:02:37 +0300 Subject: [PATCH 3/9] use options pattern for config --- .../DatabaseTbpAuthenticationCredentials.cs | 13 ++++++ .../Providers/PostgresConnectionProvider.cs | 43 ++++++++----------- src/Program.cs | 2 + 3 files changed, 34 insertions(+), 24 deletions(-) create mode 100644 src/ConfigOptions/DatabaseTbpAuthenticationCredentials.cs diff --git a/src/ConfigOptions/DatabaseTbpAuthenticationCredentials.cs b/src/ConfigOptions/DatabaseTbpAuthenticationCredentials.cs new file mode 100644 index 0000000..ece2259 --- /dev/null +++ b/src/ConfigOptions/DatabaseTbpAuthenticationCredentials.cs @@ -0,0 +1,13 @@ +using System.Diagnostics.CodeAnalysis; + +namespace PollingOutboxPublisher.ConfigOptions; + +[ExcludeFromCodeCoverage] +public class DatabaseTbpAuthenticationCredentials +{ + public string ClusterName { get; set; } + public string Host { get; set; } + public string Database { get; set; } + public int Port { get; set; } + public string ApplicationName { get; set; } +} \ No newline at end of file diff --git a/src/Database/Providers/PostgresConnectionProvider.cs b/src/Database/Providers/PostgresConnectionProvider.cs index 4064707..7bb51f8 100644 --- a/src/Database/Providers/PostgresConnectionProvider.cs +++ b/src/Database/Providers/PostgresConnectionProvider.cs @@ -1,9 +1,10 @@ -using System; using System.Data; using System.Diagnostics.CodeAnalysis; using System.IO; using Microsoft.Extensions.Configuration; +using Microsoft.Extensions.Options; using Npgsql; +using PollingOutboxPublisher.ConfigOptions; using PollingOutboxPublisher.Database.Providers.Interfaces; using PollingOutboxPublisher.Exceptions; @@ -14,13 +15,14 @@ public class PostgresConnectionProvider : IPostgresConnectionProvider { private readonly string _connectionString; - public PostgresConnectionProvider(IConfiguration configuration) + public PostgresConnectionProvider(IConfiguration configuration, IOptions databaseTbpAuthenticationCredentials) { if (configuration.GetValue("IsTbpAuthenticationEnabled") is true) { - var postgresqlCredentials = GetTbpAuthenticationCredentials(configuration); - var postgresqlUsernamePassword = GetPostgresqlUsernameAndPassword(postgresqlCredentials.clusterName); - _connectionString = GenerateConnectionString(postgresqlUsernamePassword.userName, postgresqlUsernamePassword.password, postgresqlCredentials.host, postgresqlCredentials.database, postgresqlCredentials.port, postgresqlCredentials.appName); + ValidateTbpAuthenticationCredentials(databaseTbpAuthenticationCredentials.Value); + var dbCredentials = databaseTbpAuthenticationCredentials.Value; + var postgresqlUsernamePassword = GetPostgresqlUsernameAndPassword(dbCredentials.ClusterName); + _connectionString = GenerateConnectionString(postgresqlUsernamePassword.userName, postgresqlUsernamePassword.password, dbCredentials.Host, dbCredentials.Database, dbCredentials.Port, dbCredentials.ApplicationName); } else { @@ -58,40 +60,33 @@ private static (string userName, string password) GetPostgresqlUsernameAndPasswo var password = postgresqlCredentials["password"]; return (username, password); } - - private static (string clusterName, string host, string database, int port, string appName) GetTbpAuthenticationCredentials(IConfiguration configuration) + + private static void ValidateTbpAuthenticationCredentials(DatabaseTbpAuthenticationCredentials credentials) { - var clusterName = configuration.GetValue("TbpAuthenticationCredentials:ClusterName"); - if (string.IsNullOrWhiteSpace(clusterName)) + if (string.IsNullOrWhiteSpace(credentials.ClusterName)) { - throw new MissingConfigurationException("TbpAuthenticationCredentials:ClusterName"); + throw new MissingConfigurationException("DatabaseTbpAuthenticationCredentials:ClusterName"); } - var host = configuration.GetValue("TbpAuthenticationCredentials:Host"); - if (string.IsNullOrWhiteSpace(host)) + if (string.IsNullOrWhiteSpace(credentials.Host)) { - throw new MissingConfigurationException("TbpAuthenticationCredentials:Host"); + throw new MissingConfigurationException("DatabaseTbpAuthenticationCredentials:Host"); } - var dbName = configuration.GetValue("TbpAuthenticationCredentials:Database"); - if (string.IsNullOrWhiteSpace(host)) + if (string.IsNullOrWhiteSpace(credentials.Database)) { - throw new MissingConfigurationException("TbpAuthenticationCredentials:Database"); + throw new MissingConfigurationException("DatabaseTbpAuthenticationCredentials:Database"); } - var port = configuration.GetValue("TbpAuthenticationCredentials:Port"); - if ((string.IsNullOrWhiteSpace(port) || int.TryParse(port, out int parsedPort)) == false) + if (string.IsNullOrWhiteSpace(credentials.ApplicationName)) { - throw new MissingConfigurationException("TbpAuthenticationCredentials:Port"); + throw new MissingConfigurationException("DatabaseTbpAuthenticationCredentials:ApplicationName"); } - var appName = configuration.GetValue("TbpAuthenticationCredentials:ApplicationName"); - if (string.IsNullOrWhiteSpace(appName)) + if (credentials.Port == 0) { - throw new MissingConfigurationException("TbpAuthenticationCredentials:ApplicationName"); + throw new MissingConfigurationException("DatabaseTbpAuthenticationCredentials:Port"); } - - return (clusterName, host, dbName, int.Parse(port!), appName); } private static string GenerateConnectionString(string userName, string password, string host, string database, int port, string appName) diff --git a/src/Program.cs b/src/Program.cs index 7dcba20..5a8bfa0 100644 --- a/src/Program.cs +++ b/src/Program.cs @@ -103,6 +103,8 @@ private static void RegisterConfigs(IServiceCollection services, HostBuilderCont hostContext.Configuration.GetSection(nameof(ConfigOptions.Redis))); services.Configure( hostContext.Configuration.GetSection(nameof(CircuitBreakerSettings))); + services.Configure( + hostContext.Configuration.GetSection(nameof(DatabaseTbpAuthenticationCredentials))); } private static void RegisterSerilog(IServiceCollection services) From 982586cf09fe312833c008dcb8ed4d3021436566 Mon Sep 17 00:00:00 2001 From: Eren Yilmaz Date: Wed, 2 Jul 2025 08:32:12 +0300 Subject: [PATCH 4/9] increase version --- src/PollingOutboxPublisher.csproj | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/src/PollingOutboxPublisher.csproj b/src/PollingOutboxPublisher.csproj index d840d13..27612c8 100644 --- a/src/PollingOutboxPublisher.csproj +++ b/src/PollingOutboxPublisher.csproj @@ -4,7 +4,7 @@ Exe net8.0 false - 1.5.0 + 1.6.0 PollingOutboxPublisher From 0147ff7cc63290190de812bb337a746762f6fcfe Mon Sep 17 00:00:00 2001 From: Eren Yilmaz Date: Wed, 2 Jul 2025 09:14:00 +0300 Subject: [PATCH 5/9] change feature name as UseDbCredentialsFile --- ...ntials.cs => DbCredentialsFileSettings.cs} | 4 +-- .../Providers/PostgresConnectionProvider.cs | 30 +++++++++---------- src/Program.cs | 4 +-- 3 files changed, 18 insertions(+), 20 deletions(-) rename src/ConfigOptions/{DatabaseTbpAuthenticationCredentials.cs => DbCredentialsFileSettings.cs} (74%) diff --git a/src/ConfigOptions/DatabaseTbpAuthenticationCredentials.cs b/src/ConfigOptions/DbCredentialsFileSettings.cs similarity index 74% rename from src/ConfigOptions/DatabaseTbpAuthenticationCredentials.cs rename to src/ConfigOptions/DbCredentialsFileSettings.cs index ece2259..6f866f0 100644 --- a/src/ConfigOptions/DatabaseTbpAuthenticationCredentials.cs +++ b/src/ConfigOptions/DbCredentialsFileSettings.cs @@ -3,9 +3,9 @@ namespace PollingOutboxPublisher.ConfigOptions; [ExcludeFromCodeCoverage] -public class DatabaseTbpAuthenticationCredentials +public class DbCredentialsFileSettings { - public string ClusterName { get; set; } + public string FileName { get; set; } public string Host { get; set; } public string Database { get; set; } public int Port { get; set; } diff --git a/src/Database/Providers/PostgresConnectionProvider.cs b/src/Database/Providers/PostgresConnectionProvider.cs index 7bb51f8..322ecbb 100644 --- a/src/Database/Providers/PostgresConnectionProvider.cs +++ b/src/Database/Providers/PostgresConnectionProvider.cs @@ -15,13 +15,13 @@ public class PostgresConnectionProvider : IPostgresConnectionProvider { private readonly string _connectionString; - public PostgresConnectionProvider(IConfiguration configuration, IOptions databaseTbpAuthenticationCredentials) + public PostgresConnectionProvider(IConfiguration configuration, IOptions databaseTbpAuthenticationCredentials) { - if (configuration.GetValue("IsTbpAuthenticationEnabled") is true) + if (configuration.GetValue("UseDbCredentialsFile") is true) { ValidateTbpAuthenticationCredentials(databaseTbpAuthenticationCredentials.Value); var dbCredentials = databaseTbpAuthenticationCredentials.Value; - var postgresqlUsernamePassword = GetPostgresqlUsernameAndPassword(dbCredentials.ClusterName); + var postgresqlUsernamePassword = GetPostgresqlUsernameAndPassword(dbCredentials.FileName); _connectionString = GenerateConnectionString(postgresqlUsernamePassword.userName, postgresqlUsernamePassword.password, dbCredentials.Host, dbCredentials.Database, dbCredentials.Port, dbCredentials.ApplicationName); } else @@ -43,17 +43,15 @@ public IDbConnection CreateConnectionForReadOnly() => new NpgsqlConnection(_connectionString); - private static (string userName, string password) GetPostgresqlUsernameAndPassword(string clusterName) + private static (string userName, string password) GetPostgresqlUsernameAndPassword(string fileName) { - var filePath = Path.Combine("config", $"postgresql-{clusterName}.json"); - - if (!File.Exists(filePath)) + if (!File.Exists(fileName)) { - throw new FileNotFoundException($"Postgresql credentials file not found: {filePath}"); + throw new FileNotFoundException($"Postgresql credentials file not found: {fileName}"); } var postgresqlCredentials= new ConfigurationBuilder() - .AddJsonFile(filePath) + .AddJsonFile(fileName) .Build(); var username = postgresqlCredentials["username"]; @@ -61,29 +59,29 @@ private static (string userName, string password) GetPostgresqlUsernameAndPasswo return (username, password); } - private static void ValidateTbpAuthenticationCredentials(DatabaseTbpAuthenticationCredentials credentials) + private static void ValidateTbpAuthenticationCredentials(DbCredentialsFileSettings credentialses) { - if (string.IsNullOrWhiteSpace(credentials.ClusterName)) + if (string.IsNullOrWhiteSpace(credentialses.FileName)) { - throw new MissingConfigurationException("DatabaseTbpAuthenticationCredentials:ClusterName"); + throw new MissingConfigurationException("DatabaseTbpAuthenticationCredentials:FileName"); } - if (string.IsNullOrWhiteSpace(credentials.Host)) + if (string.IsNullOrWhiteSpace(credentialses.Host)) { throw new MissingConfigurationException("DatabaseTbpAuthenticationCredentials:Host"); } - if (string.IsNullOrWhiteSpace(credentials.Database)) + if (string.IsNullOrWhiteSpace(credentialses.Database)) { throw new MissingConfigurationException("DatabaseTbpAuthenticationCredentials:Database"); } - if (string.IsNullOrWhiteSpace(credentials.ApplicationName)) + if (string.IsNullOrWhiteSpace(credentialses.ApplicationName)) { throw new MissingConfigurationException("DatabaseTbpAuthenticationCredentials:ApplicationName"); } - if (credentials.Port == 0) + if (credentialses.Port == 0) { throw new MissingConfigurationException("DatabaseTbpAuthenticationCredentials:Port"); } diff --git a/src/Program.cs b/src/Program.cs index 5a8bfa0..f8b714c 100644 --- a/src/Program.cs +++ b/src/Program.cs @@ -103,8 +103,8 @@ private static void RegisterConfigs(IServiceCollection services, HostBuilderCont hostContext.Configuration.GetSection(nameof(ConfigOptions.Redis))); services.Configure( hostContext.Configuration.GetSection(nameof(CircuitBreakerSettings))); - services.Configure( - hostContext.Configuration.GetSection(nameof(DatabaseTbpAuthenticationCredentials))); + services.Configure( + hostContext.Configuration.GetSection(nameof(DbCredentialsFileSettings))); } private static void RegisterSerilog(IServiceCollection services) From 5bf5a5ac295148cd754f41cb95fcd2e0fba029f1 Mon Sep 17 00:00:00 2001 From: Eren Yilmaz Date: Wed, 2 Jul 2025 10:28:17 +0300 Subject: [PATCH 6/9] add changelog --- CHANGELOG.md | 15 +++++++++++++++ example/Postgres/config/config.json | 10 ++++++++++ src/ConfigOptions/DbCredentialsFileSettings.cs | 2 ++ .../Providers/PostgresConnectionProvider.cs | 17 ++++++++++++----- 4 files changed, 39 insertions(+), 5 deletions(-) diff --git a/CHANGELOG.md b/CHANGELOG.md index c2eddec..d2c2b2d 100644 --- a/CHANGELOG.md +++ b/CHANGELOG.md @@ -1,5 +1,20 @@ ## v1.5.0 (March 6, 2025) +### Added: +- Db Credentials file feature. +- This feature allows a database connection to be created in cases where database credentials need to be read from a file. Currently only active on PostgreSQL. +- It can be activated with the new config value `UseDbCredentialsFile`. +- This feature requires a new config section called `DbCredentialsFileSettings` with the following options: + - `FileName`: File name containing database credentials (should be full path) + - `Host`: Host information of the database + - `Database`: Db name of the database + - `ApplicationName`: App name information on database connection + - `Port`: Port of the database + - `Pooling`: Pooling information on the database connection. When true, `Pooling=true` flag will be added to the connection string. + - `TrustServerCertificate`: TrustServerCertificate information on the database connection. When true, `TrustServerCertificate=true` flag will be added to the connection string. + +## v1.5.0 (March 6, 2025) + ### Added: - Circuit breaker implementation for handling consecutive database failures - New configuration section `CircuitBreakerSettings` with the following options: diff --git a/example/Postgres/config/config.json b/example/Postgres/config/config.json index 4d289da..6c39c60 100644 --- a/example/Postgres/config/config.json +++ b/example/Postgres/config/config.json @@ -63,5 +63,15 @@ "Threshold": 3, "DurationSc": 60, "HalfOpenMaxAttempts": 1 + }, + "UseDbCredentialsFile": true, + "DbCredentialsFileSettings": { + "FileName": "{file-name}", + "Host": "{host}", + "Database": "{database}", + "ApplicationName": "{app-name}", + "Port": 5432, + "Pooling": true, + "TrustServerCertificate": true } } \ No newline at end of file diff --git a/src/ConfigOptions/DbCredentialsFileSettings.cs b/src/ConfigOptions/DbCredentialsFileSettings.cs index 6f866f0..2893204 100644 --- a/src/ConfigOptions/DbCredentialsFileSettings.cs +++ b/src/ConfigOptions/DbCredentialsFileSettings.cs @@ -10,4 +10,6 @@ public class DbCredentialsFileSettings public string Database { get; set; } public int Port { get; set; } public string ApplicationName { get; set; } + public bool Pooling { get; set; } + public bool TrustServerCertificate { get; set; } } \ No newline at end of file diff --git a/src/Database/Providers/PostgresConnectionProvider.cs b/src/Database/Providers/PostgresConnectionProvider.cs index 322ecbb..c2108fa 100644 --- a/src/Database/Providers/PostgresConnectionProvider.cs +++ b/src/Database/Providers/PostgresConnectionProvider.cs @@ -22,7 +22,8 @@ public PostgresConnectionProvider(IConfiguration configuration, IOptions Date: Wed, 2 Jul 2025 10:33:22 +0300 Subject: [PATCH 7/9] change version date --- CHANGELOG.md | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/CHANGELOG.md b/CHANGELOG.md index d2c2b2d..508e4e7 100644 --- a/CHANGELOG.md +++ b/CHANGELOG.md @@ -1,4 +1,4 @@ -## v1.5.0 (March 6, 2025) +## v1.6.0 (July 2, 2025) ### Added: - Db Credentials file feature. From d26b172850f369fb08b9bddca13f97c6ba0d6633 Mon Sep 17 00:00:00 2001 From: Eren Yilmaz Date: Wed, 2 Jul 2025 10:34:53 +0300 Subject: [PATCH 8/9] change example config --- example/Postgres/config/config.json | 8 ++++---- 1 file changed, 4 insertions(+), 4 deletions(-) diff --git a/example/Postgres/config/config.json b/example/Postgres/config/config.json index 6c39c60..30254c9 100644 --- a/example/Postgres/config/config.json +++ b/example/Postgres/config/config.json @@ -66,10 +66,10 @@ }, "UseDbCredentialsFile": true, "DbCredentialsFileSettings": { - "FileName": "{file-name}", - "Host": "{host}", - "Database": "{database}", - "ApplicationName": "{app-name}", + "FileName": "config/postgresql-test-cluster.json", + "Host": "10.85.240.242", + "Database": "test", + "ApplicationName": "PollingOutboxPublisher", "Port": 5432, "Pooling": true, "TrustServerCertificate": true From f1dbaff400a27a42a77e328800309534a14f7677 Mon Sep 17 00:00:00 2001 From: Eren Yilmaz Date: Wed, 2 Jul 2025 10:44:29 +0300 Subject: [PATCH 9/9] add additional parameters config --- CHANGELOG.md | 4 ++-- example/Postgres/config/config.json | 3 +-- src/ConfigOptions/DbCredentialsFileSettings.cs | 3 +-- src/Database/Providers/PostgresConnectionProvider.cs | 12 ++++-------- 4 files changed, 8 insertions(+), 14 deletions(-) diff --git a/CHANGELOG.md b/CHANGELOG.md index 508e4e7..e21f8fe 100644 --- a/CHANGELOG.md +++ b/CHANGELOG.md @@ -10,8 +10,8 @@ - `Database`: Db name of the database - `ApplicationName`: App name information on database connection - `Port`: Port of the database - - `Pooling`: Pooling information on the database connection. When true, `Pooling=true` flag will be added to the connection string. - - `TrustServerCertificate`: TrustServerCertificate information on the database connection. When true, `TrustServerCertificate=true` flag will be added to the connection string. + - `AdditionalParameters`: Additional parameters to be added on Connection. Flags such as `Pooling`, `TrustServerCertificate` can be added. + ## v1.5.0 (March 6, 2025) diff --git a/example/Postgres/config/config.json b/example/Postgres/config/config.json index 30254c9..fee60da 100644 --- a/example/Postgres/config/config.json +++ b/example/Postgres/config/config.json @@ -71,7 +71,6 @@ "Database": "test", "ApplicationName": "PollingOutboxPublisher", "Port": 5432, - "Pooling": true, - "TrustServerCertificate": true + "AdditionalParameters": "Pooling=true;TrustServerCertificate=true;" } } \ No newline at end of file diff --git a/src/ConfigOptions/DbCredentialsFileSettings.cs b/src/ConfigOptions/DbCredentialsFileSettings.cs index 2893204..74d71d0 100644 --- a/src/ConfigOptions/DbCredentialsFileSettings.cs +++ b/src/ConfigOptions/DbCredentialsFileSettings.cs @@ -10,6 +10,5 @@ public class DbCredentialsFileSettings public string Database { get; set; } public int Port { get; set; } public string ApplicationName { get; set; } - public bool Pooling { get; set; } - public bool TrustServerCertificate { get; set; } + public string AdditionalParameters { get; set; } } \ No newline at end of file diff --git a/src/Database/Providers/PostgresConnectionProvider.cs b/src/Database/Providers/PostgresConnectionProvider.cs index c2108fa..3ac6cd3 100644 --- a/src/Database/Providers/PostgresConnectionProvider.cs +++ b/src/Database/Providers/PostgresConnectionProvider.cs @@ -22,8 +22,7 @@ public PostgresConnectionProvider(IConfiguration configuration, IOptions