diff --git a/config.go b/config.go index 2e038304..dd023a96 100644 --- a/config.go +++ b/config.go @@ -67,7 +67,7 @@ type Config struct { //Congig Options such as getsslpassword function type ParseConfigOptions struct { - GetSSLPassword GetSSLPasswordFunc + GetSSLPassword GetSSLPasswordFunc } // Copy returns a deep copy of the config that is safe to use and modify. @@ -715,25 +715,25 @@ func configTLS(settings map[string]string, thisHost string, parseConfigOptions P if x509.IsEncryptedPEMBlock(block) { // Attempt decryption with pass phrase // NOTE: only supports RSA (PKCS#1) - if(sslpassword != ""){ - decryptedKey, decryptedError = x509.DecryptPEMBlock(block, []byte(sslpassword)) + if sslpassword != "" { + decryptedKey, decryptedError = x509.DecryptPEMBlock(block, []byte(sslpassword)) } //if sslpassword not provided or has decryption error when use it //try to find sslpassword with callback function - if (sslpassword == "" || decryptedError!= nil) { - if(parseConfigOptions.GetSSLPassword != nil){ - sslpassword = parseConfigOptions.GetSSLPassword(context.Background()) + if sslpassword == "" || decryptedError != nil { + if parseConfigOptions.GetSSLPassword != nil { + sslpassword = parseConfigOptions.GetSSLPassword(context.Background()) } - if(sslpassword == ""){ - return nil, fmt.Errorf("unable to find sslpassword") + if sslpassword == "" { + return nil, fmt.Errorf("unable to find sslpassword") } } decryptedKey, decryptedError = x509.DecryptPEMBlock(block, []byte(sslpassword)) // Should we also provide warning for PKCS#1 needed? - if decryptedError != nil { + if decryptedError != nil { return nil, fmt.Errorf("unable to decrypt key: %w", err) } - + pemBytes := pem.Block{ Type: "RSA PRIVATE KEY", Bytes: decryptedKey, diff --git a/defaults.go b/defaults.go index f69cad31..c7209fdd 100644 --- a/defaults.go +++ b/defaults.go @@ -1,3 +1,4 @@ +//go:build !windows // +build !windows package pgconn diff --git a/pgconn.go b/pgconn.go index f582f5b8..c817de49 100644 --- a/pgconn.go +++ b/pgconn.go @@ -109,8 +109,8 @@ func Connect(ctx context.Context, connString string) (*PgConn, error) { return ConnectConfig(ctx, config) } -// Connect establishes a connection to a PostgreSQL server using the environment -// and connString (in URL or DSN format) and ParseConfigOptions +// Connect establishes a connection to a PostgreSQL server using the environment +// and connString (in URL or DSN format) and ParseConfigOptions // to provide configuration. See documentation for ParseConfig for details. ctx can be used to cancel a connect attempt. func ConnectWithOptions(ctx context.Context, connString string, parseConfigOptions ParseConfigOptions) (*PgConn, error) { config, err := ParseConfigWithOptions(connString, parseConfigOptions) diff --git a/pgconn_test.go b/pgconn_test.go index 9a52abf6..c08fa54a 100644 --- a/pgconn_test.go +++ b/pgconn_test.go @@ -72,8 +72,8 @@ func TestConnectWithOption(t *testing.T) { if connString == "" { t.Skipf("Skipping due to missing environment variable %v", tt.env) } - var sslOptions pgconn.ParseConfigOptions - sslOptions.GetSSLPassword = GetSSLPassword + var sslOptions pgconn.ParseConfigOptions + sslOptions.GetSSLPassword = GetSSLPassword conn, err := pgconn.ConnectWithOptions(context.Background(), connString, sslOptions) require.NoError(t, err) @@ -97,12 +97,12 @@ func TestConnectTLS(t *testing.T) { var sslOptions pgconn.ParseConfigOptions sslOptions.GetSSLPassword = GetSSLPassword - config, err := pgconn.ParseConfigWithOptions(connString, sslOptions) + config, err := pgconn.ParseConfigWithOptions(connString, sslOptions) require.Nil(t, err) - conn, err = pgconn.ConnectConfig(context.Background(), config) + conn, err = pgconn.ConnectConfig(context.Background(), config) require.NoError(t, err) - + if _, ok := conn.Conn().(*tls.Conn); !ok { t.Error("not a TLS connection") } @@ -2167,5 +2167,5 @@ func Example() { func GetSSLPassword(ctx context.Context) string { connString := os.Getenv("PGX_SSL_PASSWORD") - return connString -} \ No newline at end of file + return connString +}