mirror of https://github.com/jackc/pgx.git
Run go fmt
parent
cdd2cc4124
commit
69b99209fb
18
config.go
18
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,22 +715,22 @@ 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)
|
||||
}
|
||||
|
||||
|
|
|
@ -1,3 +1,4 @@
|
|||
//go:build !windows
|
||||
// +build !windows
|
||||
|
||||
package pgconn
|
||||
|
|
|
@ -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,10 +97,10 @@ 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 {
|
||||
|
@ -2167,5 +2167,5 @@ func Example() {
|
|||
|
||||
func GetSSLPassword(ctx context.Context) string {
|
||||
connString := os.Getenv("PGX_SSL_PASSWORD")
|
||||
return connString
|
||||
return connString
|
||||
}
|
Loading…
Reference in New Issue