Add redshift (and DigitalOcean Managed DB) compatibility and start using a string building to create the sql connection string
This commit is contained in:
parent
a4b914d576
commit
d9f8e9a80e
4 changed files with 28 additions and 3 deletions
|
@ -32,6 +32,7 @@
|
|||
GEEKBOT_DB_TRUST_CERT: "true"
|
||||
GEEKBOT_SUMOLOCIG: "{{ lookup('env', 'GEEKBOT_SUMOLOCIG') }}"
|
||||
GEEKBOT_SENTRY: "{{ lookup('env', 'GEEKBOT_SENTRY') }}"
|
||||
GEEKBOT_DB_REDSHIFT_COMPAT: "true"
|
||||
- name: Cleanup Old Container
|
||||
docker_prune:
|
||||
images: yes
|
||||
|
|
|
@ -37,7 +37,8 @@ namespace Geekbot.net.Database
|
|||
Username = _runParameters.DbUser,
|
||||
Password = _runParameters.DbPassword,
|
||||
RequireSsl = _runParameters.DbSsl,
|
||||
TrustServerCertificate = _runParameters.DbTrustCert
|
||||
TrustServerCertificate = _runParameters.DbTrustCert,
|
||||
RedshiftCompatibility = _runParameters.DbRedshiftCompatibility
|
||||
});
|
||||
}
|
||||
}
|
||||
|
|
|
@ -1,4 +1,6 @@
|
|||
namespace Geekbot.net.Database
|
||||
using System.Text;
|
||||
|
||||
namespace Geekbot.net.Database
|
||||
{
|
||||
public class SqlConnectionString
|
||||
{
|
||||
|
@ -9,11 +11,29 @@
|
|||
public string Password { get; set; }
|
||||
public bool RequireSsl { get; set; }
|
||||
public bool TrustServerCertificate { get; set; }
|
||||
public bool RedshiftCompatibility { get; set; }
|
||||
|
||||
public override string ToString()
|
||||
{
|
||||
var sb = new StringBuilder();
|
||||
sb.Append("Application Name=Geekbot;");
|
||||
|
||||
sb.Append($"Host={Host};");
|
||||
sb.Append($"Port={Port};");
|
||||
sb.Append($"Database={Database};");
|
||||
sb.Append($"Username={Username};");
|
||||
sb.Append($"Password={Password};");
|
||||
|
||||
var sslMode = RequireSsl ? "Require" : "Prefer";
|
||||
return $"ApplicationName=Geekbot;Server={Host};Port={Port};Database={Database};Uid={Username};Pwd={Password};SSLMode={sslMode};TrustServerCertificate={TrustServerCertificate.ToString()};";
|
||||
sb.Append($"SSL Mode={sslMode};");
|
||||
sb.Append($"Trust Server Certificate={TrustServerCertificate.ToString()};");
|
||||
|
||||
if (RedshiftCompatibility)
|
||||
{
|
||||
sb.Append("Server Compatibility Mode=Redshift");
|
||||
}
|
||||
|
||||
return sb.ToString();
|
||||
}
|
||||
}
|
||||
}
|
|
@ -50,6 +50,9 @@ namespace Geekbot.net.Lib
|
|||
[Option("db-trust-cert", HelpText = "Trust the database certificate, regardless if it is valid (default: false) (env: DB_TRUST_CERT)")]
|
||||
public bool DbTrustCert { get; set; } = ParamFallback("DB_TRUST_CERT", false);
|
||||
|
||||
[Option("db-redshift-compat", HelpText = "Enable compatibility for AWS Redshift and DigitalOcean Managed Database (default: false) (env: DB_REDSHIFT_COMPAT)")]
|
||||
public bool DbRedshiftCompatibility { get; set; } = ParamFallback("DB_REDSHIFT_COMPAT", false);
|
||||
|
||||
// Logging
|
||||
[Option("db-logging", HelpText = "Enable database logging (default: false) (env: DB_LOGGING)")]
|
||||
public bool DbLogging { get; set; } = ParamFallback("DB_LOGGING", false);
|
||||
|
|
Loading…
Reference in a new issue