Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

enhancement: Add additional ssl options to db configuration #3387

Open
wants to merge 3 commits into
base: master
Choose a base branch
from
Open
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
31 changes: 27 additions & 4 deletions pkg/csconfig/database.go
Original file line number Diff line number Diff line change
Expand Up @@ -26,7 +26,10 @@
User string `yaml:"user"`
Password string `yaml:"password"`
DbName string `yaml:"db_name"`
Sslmode string `yaml:"sslmode"`
SSLMode string `yaml:"sslmode"`
SSLCACert string `yaml:"ssl_ca_cert"`
SSLClientCert string `yaml:"ssl_client_cert"`
SSLClientKey string `yaml:"ssl_client_key"`
Host string `yaml:"host"`
Port int `yaml:"port"`
DbPath string `yaml:"db_path"`
Expand Down Expand Up @@ -136,14 +139,34 @@
connString = fmt.Sprintf("%s:%s@tcp(%s:%d)/%s?parseTime=True", d.User, d.Password, d.Host, d.Port, d.DbName)
}

if d.Sslmode != "" {
connString = fmt.Sprintf("%s&tls=%s", connString, d.Sslmode)
if d.SSLMode != "" {
connString = fmt.Sprintf("%s&tls=%s", connString, d.SSLMode)
}

Check warning on line 144 in pkg/csconfig/database.go

View check run for this annotation

Codecov / codecov/patch

pkg/csconfig/database.go#L142-L144

Added lines #L142 - L144 were not covered by tests

if d.SSLCACert != "" {
connString = fmt.Sprintf("%s&tls-ca=%s", connString, d.SSLCACert)
}

Check warning on line 148 in pkg/csconfig/database.go

View check run for this annotation

Codecov / codecov/patch

pkg/csconfig/database.go#L146-L148

Added lines #L146 - L148 were not covered by tests

if d.SSLClientCert != "" && d.SSLClientKey != "" {
connString = fmt.Sprintf("%s&tls-cert=%s&tls-key=%s", connString, d.SSLClientCert, d.SSLClientKey)

Check warning on line 151 in pkg/csconfig/database.go

View check run for this annotation

Codecov / codecov/patch

pkg/csconfig/database.go#L150-L151

Added lines #L150 - L151 were not covered by tests
}
case "postgres", "postgresql", "pgx":
if d.isSocketConfig() {
connString = fmt.Sprintf("host=%s user=%s dbname=%s password=%s", d.DbPath, d.User, d.DbName, d.Password)
} else {
connString = fmt.Sprintf("host=%s port=%d user=%s dbname=%s password=%s sslmode=%s", d.Host, d.Port, d.User, d.DbName, d.Password, d.Sslmode)
connString = fmt.Sprintf("host=%s port=%d user=%s dbname=%s password=%s", d.Host, d.Port, d.User, d.DbName, d.Password)
}

Check warning on line 158 in pkg/csconfig/database.go

View check run for this annotation

Codecov / codecov/patch

pkg/csconfig/database.go#L157-L158

Added lines #L157 - L158 were not covered by tests

if d.SSLMode != "" {
connString = fmt.Sprintf("%s sslmode=%s", connString, d.SSLMode)
}

Check warning on line 162 in pkg/csconfig/database.go

View check run for this annotation

Codecov / codecov/patch

pkg/csconfig/database.go#L160-L162

Added lines #L160 - L162 were not covered by tests

if d.SSLCACert != "" {
connString = fmt.Sprintf("%s sslrootcert=%s", connString, d.SSLCACert)
}

Check warning on line 166 in pkg/csconfig/database.go

View check run for this annotation

Codecov / codecov/patch

pkg/csconfig/database.go#L164-L166

Added lines #L164 - L166 were not covered by tests

if d.SSLClientCert != "" && d.SSLClientKey != "" {
connString = fmt.Sprintf("%s sslcert=%s sslkey=%s", connString, d.SSLClientCert, d.SSLClientKey)

Check warning on line 169 in pkg/csconfig/database.go

View check run for this annotation

Codecov / codecov/patch

pkg/csconfig/database.go#L168-L169

Added lines #L168 - L169 were not covered by tests
}
}

Expand Down
Loading