From 9c7f566d4da270988b53fb84602cb6c25eceeee4 Mon Sep 17 00:00:00 2001 From: Dan Sosedoff Date: Wed, 5 Feb 2020 22:01:25 -0600 Subject: [PATCH] Add option to support sslrootcert parameter --- pkg/command/options.go | 2 ++ pkg/connection/connection_string.go | 15 +++++++++------ 2 files changed, 11 insertions(+), 6 deletions(-) diff --git a/pkg/command/options.go b/pkg/command/options.go index 7eeaf83..d6f4096 100644 --- a/pkg/command/options.go +++ b/pkg/command/options.go @@ -19,6 +19,7 @@ type Options struct { Pass string `long:"pass" description:"Password for user"` DbName string `long:"db" description:"Database name"` Ssl string `long:"ssl" description:"SSL option"` + SslRootCert string `long:"ssl-root-cert" description:"SSL Root Cert"` HTTPHost string `long:"bind" description:"HTTP server host" default:"localhost"` HTTPPort uint `long:"listen" description:"HTTP server listen port" default:"8081"` AuthUser string `long:"auth-user" description:"HTTP basic auth user"` @@ -43,6 +44,7 @@ type Options struct { var Opts Options +// ParseOptions returns a new options struct from the input arguments func ParseOptions(args []string) (Options, error) { var opts = Options{} diff --git a/pkg/connection/connection_string.go b/pkg/connection/connection_string.go index 4ea141b..a4cbd1b 100644 --- a/pkg/connection/connection_string.go +++ b/pkg/connection/connection_string.go @@ -93,6 +93,8 @@ func IsBlank(opts command.Options) bool { // BuildStringFromOptions returns a new connection string built from options func BuildStringFromOptions(opts command.Options) (string, error) { + query := neturl.Values{} + // If connection string is provided we just use that if opts.URL != "" { return FormatURL(opts) @@ -106,14 +108,15 @@ func BuildStringFromOptions(opts command.Options) (string, error) { } } - // Disable ssl for localhost connections, most users have it disabled - if opts.Ssl == "" && (opts.Host == "localhost" || opts.Host == "127.0.0.1") { - opts.Ssl = "disable" - } - - query := neturl.Values{} if opts.Ssl != "" { query.Add("sslmode", opts.Ssl) + } else { + if opts.Host == "localhost" || opts.Host == "127.0.0.1" { + query.Add("sslmode", "disable") + } + } + if opts.SslRootCert != "" { + query.Add("sslrootcert", opts.SslRootCert) } url := neturl.URL{