Skip to content
This repository has been archived by the owner on Oct 22, 2024. It is now read-only.

Commit

Permalink
Merge pull request #125 from Sandy-Garrido/feature/enable-database-co…
Browse files Browse the repository at this point in the history
…nnection-sslmode

feature: Added database connection config option SSLMode
  • Loading branch information
K4ryuu authored Jan 28, 2024
2 parents d3e7b29 + bdc60d2 commit f5e81c3
Show file tree
Hide file tree
Showing 3 changed files with 9 additions and 4 deletions.
4 changes: 2 additions & 2 deletions src/Plugin/Plugin.cs
Original file line number Diff line number Diff line change
Expand Up @@ -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
{
Expand All @@ -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 */

Expand Down
3 changes: 3 additions & 0 deletions src/Plugin/PluginConfig.cs
Original file line number Diff line number Diff line change
Expand Up @@ -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; } = "";

Expand Down
6 changes: 4 additions & 2 deletions src/Plugin/PluginStock.cs
Original file line number Diff line number Diff line change
Expand Up @@ -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(*)
Expand Down

0 comments on commit f5e81c3

Please sign in to comment.