Expose tls parameter of Go MySQL driver to config file (#855)

Co-authored-by: Jonas Gunz <himself@jonasgunz.de>
Reviewed-on: https://kolaente.dev/vikunja/api/pulls/855
Reviewed-by: konrad <konrad@kola-entertainments.de>
Co-authored-by: kompetenzbolzen <himself@jonasgunz.de>
Co-committed-by: kompetenzbolzen <himself@jonasgunz.de>
This commit is contained in:
kompetenzbolzen 2021-05-08 14:54:55 +00:00 committed by konrad
parent 9dc72c5c98
commit 86b7d224ab
4 changed files with 13 additions and 2 deletions

View file

@ -62,6 +62,8 @@ database:
# Secure connection mode. Only used with postgres. # Secure connection mode. Only used with postgres.
# (see https://pkg.go.dev/github.com/lib/pq?tab=doc#hdr-Connection_String_Parameters) # (see https://pkg.go.dev/github.com/lib/pq?tab=doc#hdr-Connection_String_Parameters)
sslmode: disable sslmode: disable
# Enable SSL/TLS for mysql connections. Options: false, true, skip-verify, preferred
tls: false
cache: cache:
# If cache is enabled or not # If cache is enabled or not

View file

@ -237,6 +237,12 @@ Secure connection mode. Only used with postgres.
Default: `disable` Default: `disable`
### tls
Enable SSL/TLS for mysql connections. Options: false, true, skip-verify, preferred
Default: `false`
--- ---
## cache ## cache

View file

@ -73,6 +73,7 @@ const (
DatabaseMaxIdleConnections Key = `database.maxidleconnections` DatabaseMaxIdleConnections Key = `database.maxidleconnections`
DatabaseMaxConnectionLifetime Key = `database.maxconnectionlifetime` DatabaseMaxConnectionLifetime Key = `database.maxconnectionlifetime`
DatabaseSslMode Key = `database.sslmode` DatabaseSslMode Key = `database.sslmode`
DatabaseTLS Key = `database.tls`
CacheEnabled Key = `cache.enabled` CacheEnabled Key = `cache.enabled`
CacheType Key = `cache.type` CacheType Key = `cache.type`
@ -258,6 +259,7 @@ func InitDefaultConfig() {
DatabaseMaxIdleConnections.setDefault(50) DatabaseMaxIdleConnections.setDefault(50)
DatabaseMaxConnectionLifetime.setDefault(10000) DatabaseMaxConnectionLifetime.setDefault(10000)
DatabaseSslMode.setDefault("disable") DatabaseSslMode.setDefault("disable")
DatabaseTLS.setDefault("false")
// Cacher // Cacher
CacheEnabled.setDefault(false) CacheEnabled.setDefault(false)

View file

@ -113,11 +113,12 @@ func initMysqlEngine() (engine *xorm.Engine, err error) {
// We're using utf8mb here instead of just utf8 because we want to use non-BMP characters. // We're using utf8mb here instead of just utf8 because we want to use non-BMP characters.
// See https://stackoverflow.com/a/30074553/10924593 for more info. // See https://stackoverflow.com/a/30074553/10924593 for more info.
connStr := fmt.Sprintf( connStr := fmt.Sprintf(
"%s:%s@tcp(%s)/%s?charset=utf8mb4&parseTime=true", "%s:%s@tcp(%s)/%s?charset=utf8mb4&parseTime=true&tls=%s",
config.DatabaseUser.GetString(), config.DatabaseUser.GetString(),
config.DatabasePassword.GetString(), config.DatabasePassword.GetString(),
config.DatabaseHost.GetString(), config.DatabaseHost.GetString(),
config.DatabaseDatabase.GetString()) config.DatabaseDatabase.GetString(),
config.DatabaseTLS.GetString())
engine, err = xorm.NewEngine("mysql", connStr) engine, err = xorm.NewEngine("mysql", connStr)
if err != nil { if err != nil {
return return