From bdc60d25768a595856976c1d83d43783f1f3a5d3 Mon Sep 17 00:00:00 2001 From: Sandy Garrido Date: Sun, 28 Jan 2024 22:46:48 +0000 Subject: [PATCH] feature: Added database connection config option SSLMode --- src/Plugin/Plugin.cs | 4 ++-- src/Plugin/PluginConfig.cs | 3 +++ src/Plugin/PluginStock.cs | 6 ++++-- 3 files changed, 9 insertions(+), 4 deletions(-) diff --git a/src/Plugin/Plugin.cs b/src/Plugin/Plugin.cs index 425e3d7..dad5d2f 100644 --- a/src/Plugin/Plugin.cs +++ b/src/Plugin/Plugin.cs @@ -48,7 +48,7 @@ public void OnConfigParsed(PluginConfig config) DatabaseSettings dbSettings = config.DatabaseSettings; - string connectionString = @$"Server={dbSettings.Host};Database={dbSettings.Database};Port={dbSettings.Port};Uid={dbSettings.Username};Password={dbSettings.Password};SslMode=none;"; + string connectionString = @$"Server={dbSettings.Host};Database={dbSettings.Database};Port={dbSettings.Port};Uid={dbSettings.Username};Password={dbSettings.Password};SslMode={dbSettings.Sslmode};"; try { @@ -66,7 +66,7 @@ public void OnConfigParsed(PluginConfig config) //** ? Database Connection */ - Database = new MySqlDb(dbSettings.Host, dbSettings.Username, dbSettings.Password, dbSettings.Database, dbSettings.Port); + Database = new MySqlDb(dbSettings.Host, dbSettings.Username, dbSettings.Password, dbSettings.Database, dbSettings.Port, dbSettings.Sslmode); //** ? Save Config */ diff --git a/src/Plugin/PluginConfig.cs b/src/Plugin/PluginConfig.cs index 2407cec..5b619ce 100644 --- a/src/Plugin/PluginConfig.cs +++ b/src/Plugin/PluginConfig.cs @@ -132,6 +132,9 @@ public sealed class DatabaseSettings [JsonPropertyName("port")] public int Port { get; set; } = 3306; + [JsonPropertyName("sslmode")] + public string Sslmode { get; set; } = "none"; + [JsonPropertyName("table-prefix")] public string TablePrefix { get; set; } = ""; diff --git a/src/Plugin/PluginStock.cs b/src/Plugin/PluginStock.cs index 76b4ab1..6aba13e 100644 --- a/src/Plugin/PluginStock.cs +++ b/src/Plugin/PluginStock.cs @@ -31,14 +31,16 @@ public bool InitializeDatabase(string tableName, string createTableQuery) if (string.IsNullOrEmpty(this.Config.DatabaseSettings.Host) || string.IsNullOrEmpty(this.Config.DatabaseSettings.Database) || string.IsNullOrEmpty(this.Config.DatabaseSettings.Username) || - string.IsNullOrEmpty(this.Config.DatabaseSettings.Password)) + string.IsNullOrEmpty(this.Config.DatabaseSettings.Password) || + string.IsNullOrEmpty(this.Config.DatabaseSettings.Sslmode)) + { return false; } tableName = $"{this.Config.DatabaseSettings.TablePrefix}{tableName}"; - string connectionString = $"Server={this.Config.DatabaseSettings.Host};Database={this.Config.DatabaseSettings.Database};port={this.Config.DatabaseSettings.Port};User Id={this.Config.DatabaseSettings.Username};password={this.Config.DatabaseSettings.Password};SslMode=none;"; + string connectionString = $"Server={this.Config.DatabaseSettings.Host};Database={this.Config.DatabaseSettings.Database};port={this.Config.DatabaseSettings.Port};User Id={this.Config.DatabaseSettings.Username};password={this.Config.DatabaseSettings.Password};SslMode={this.Config.DatabaseSettings.Sslmode};"; string checkTableQuery = $@" SELECT COUNT(*)