Refactor bookmarks ssl params
This commit is contained in:
@@ -66,13 +66,13 @@ func FormatURL(opts command.Options) (string, error) {
|
||||
|
||||
// Determine if we need to specify sslmode if it's missing
|
||||
if params["sslmode"] == "" {
|
||||
if opts.Ssl == "" {
|
||||
if opts.SSLMode == "" {
|
||||
// Only modify sslmode for local connections
|
||||
if strings.Contains(uri.Host, "localhost") || strings.Contains(uri.Host, "127.0.0.1") {
|
||||
params["sslmode"] = "disable"
|
||||
}
|
||||
} else {
|
||||
params["sslmode"] = opts.Ssl
|
||||
params["sslmode"] = opts.SSLMode
|
||||
}
|
||||
}
|
||||
|
||||
@@ -108,21 +108,21 @@ func BuildStringFromOptions(opts command.Options) (string, error) {
|
||||
}
|
||||
}
|
||||
|
||||
if opts.Ssl != "" {
|
||||
query.Add("sslmode", opts.Ssl)
|
||||
if opts.SSLMode != "" {
|
||||
query.Add("sslmode", opts.SSLMode)
|
||||
} else {
|
||||
if opts.Host == "localhost" || opts.Host == "127.0.0.1" {
|
||||
query.Add("sslmode", "disable")
|
||||
}
|
||||
}
|
||||
if opts.SslCert != "" {
|
||||
query.Add("sslcert", opts.SslCert)
|
||||
if opts.SSLCert != "" {
|
||||
query.Add("sslcert", opts.SSLCert)
|
||||
}
|
||||
if opts.SslKey != "" {
|
||||
query.Add("sslkey", opts.SslKey)
|
||||
if opts.SSLKey != "" {
|
||||
query.Add("sslkey", opts.SSLKey)
|
||||
}
|
||||
if opts.SslRootCert != "" {
|
||||
query.Add("sslrootcert", opts.SslRootCert)
|
||||
if opts.SSLRootCert != "" {
|
||||
query.Add("sslrootcert", opts.SSLRootCert)
|
||||
}
|
||||
|
||||
url := neturl.URL{
|
||||
|
||||
@@ -38,8 +38,8 @@ func Test_Valid_Url(t *testing.T) {
|
||||
|
||||
func Test_Url_And_Ssl_Flag(t *testing.T) {
|
||||
str, err := BuildStringFromOptions(command.Options{
|
||||
URL: "postgres://myhost/database",
|
||||
Ssl: "disable",
|
||||
URL: "postgres://myhost/database",
|
||||
SSLMode: "disable",
|
||||
})
|
||||
|
||||
assert.Equal(t, nil, err)
|
||||
@@ -62,15 +62,15 @@ func Test_Localhost_Url_And_No_Ssl_Flag(t *testing.T) {
|
||||
|
||||
func Test_Localhost_Url_And_Ssl_Flag(t *testing.T) {
|
||||
str, err := BuildStringFromOptions(command.Options{
|
||||
URL: "postgres://localhost/database",
|
||||
Ssl: "require",
|
||||
URL: "postgres://localhost/database",
|
||||
SSLMode: "require",
|
||||
})
|
||||
assert.Equal(t, nil, err)
|
||||
assert.Equal(t, "postgres://localhost/database?sslmode=require", str)
|
||||
|
||||
str, err = BuildStringFromOptions(command.Options{
|
||||
URL: "postgres://127.0.0.1/database",
|
||||
Ssl: "require",
|
||||
URL: "postgres://127.0.0.1/database",
|
||||
SSLMode: "require",
|
||||
})
|
||||
assert.Equal(t, nil, err)
|
||||
assert.Equal(t, "postgres://127.0.0.1/database?sslmode=require", str)
|
||||
@@ -137,10 +137,10 @@ func Test_Localhost_And_Ssl(t *testing.T) {
|
||||
User: "user",
|
||||
Pass: "password",
|
||||
DbName: "db",
|
||||
Ssl: "require",
|
||||
SslKey: "keyPath",
|
||||
SslCert: "certPath",
|
||||
SslRootCert: "caPath",
|
||||
SSLMode: "require",
|
||||
SSLKey: "keyPath",
|
||||
SSLCert: "certPath",
|
||||
SSLRootCert: "caPath",
|
||||
}
|
||||
|
||||
str, err := BuildStringFromOptions(opts)
|
||||
|
||||
Reference in New Issue
Block a user