Run go fmt

pull/1281/head
Jack Christensen 2022-07-20 06:06:54 -05:00
parent cdd2cc4124
commit 69b99209fb
4 changed files with 20 additions and 19 deletions

View File

@ -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,

View File

@ -1,3 +1,4 @@
//go:build !windows
// +build !windows
package pgconn

View File

@ -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)

View File

@ -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
}
return connString
}