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
|
//Congig Options such as getsslpassword function
|
||||||
type ParseConfigOptions struct {
|
type ParseConfigOptions struct {
|
||||||
GetSSLPassword GetSSLPasswordFunc
|
GetSSLPassword GetSSLPasswordFunc
|
||||||
}
|
}
|
||||||
|
|
||||||
// Copy returns a deep copy of the config that is safe to use and modify.
|
// 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) {
|
if x509.IsEncryptedPEMBlock(block) {
|
||||||
// Attempt decryption with pass phrase
|
// Attempt decryption with pass phrase
|
||||||
// NOTE: only supports RSA (PKCS#1)
|
// NOTE: only supports RSA (PKCS#1)
|
||||||
if(sslpassword != ""){
|
if sslpassword != "" {
|
||||||
decryptedKey, decryptedError = x509.DecryptPEMBlock(block, []byte(sslpassword))
|
decryptedKey, decryptedError = x509.DecryptPEMBlock(block, []byte(sslpassword))
|
||||||
}
|
}
|
||||||
//if sslpassword not provided or has decryption error when use it
|
//if sslpassword not provided or has decryption error when use it
|
||||||
//try to find sslpassword with callback function
|
//try to find sslpassword with callback function
|
||||||
if (sslpassword == "" || decryptedError!= nil) {
|
if sslpassword == "" || decryptedError != nil {
|
||||||
if(parseConfigOptions.GetSSLPassword != nil){
|
if parseConfigOptions.GetSSLPassword != nil {
|
||||||
sslpassword = parseConfigOptions.GetSSLPassword(context.Background())
|
sslpassword = parseConfigOptions.GetSSLPassword(context.Background())
|
||||||
}
|
}
|
||||||
if(sslpassword == ""){
|
if sslpassword == "" {
|
||||||
return nil, fmt.Errorf("unable to find sslpassword")
|
return nil, fmt.Errorf("unable to find sslpassword")
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
decryptedKey, decryptedError = x509.DecryptPEMBlock(block, []byte(sslpassword))
|
decryptedKey, decryptedError = x509.DecryptPEMBlock(block, []byte(sslpassword))
|
||||||
// Should we also provide warning for PKCS#1 needed?
|
// 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)
|
return nil, fmt.Errorf("unable to decrypt key: %w", err)
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
|
@ -1,3 +1,4 @@
|
||||||
|
//go:build !windows
|
||||||
// +build !windows
|
// +build !windows
|
||||||
|
|
||||||
package pgconn
|
package pgconn
|
||||||
|
|
|
@ -72,8 +72,8 @@ func TestConnectWithOption(t *testing.T) {
|
||||||
if connString == "" {
|
if connString == "" {
|
||||||
t.Skipf("Skipping due to missing environment variable %v", tt.env)
|
t.Skipf("Skipping due to missing environment variable %v", tt.env)
|
||||||
}
|
}
|
||||||
var sslOptions pgconn.ParseConfigOptions
|
var sslOptions pgconn.ParseConfigOptions
|
||||||
sslOptions.GetSSLPassword = GetSSLPassword
|
sslOptions.GetSSLPassword = GetSSLPassword
|
||||||
conn, err := pgconn.ConnectWithOptions(context.Background(), connString, sslOptions)
|
conn, err := pgconn.ConnectWithOptions(context.Background(), connString, sslOptions)
|
||||||
require.NoError(t, err)
|
require.NoError(t, err)
|
||||||
|
|
||||||
|
@ -97,10 +97,10 @@ func TestConnectTLS(t *testing.T) {
|
||||||
|
|
||||||
var sslOptions pgconn.ParseConfigOptions
|
var sslOptions pgconn.ParseConfigOptions
|
||||||
sslOptions.GetSSLPassword = GetSSLPassword
|
sslOptions.GetSSLPassword = GetSSLPassword
|
||||||
config, err := pgconn.ParseConfigWithOptions(connString, sslOptions)
|
config, err := pgconn.ParseConfigWithOptions(connString, sslOptions)
|
||||||
require.Nil(t, err)
|
require.Nil(t, err)
|
||||||
|
|
||||||
conn, err = pgconn.ConnectConfig(context.Background(), config)
|
conn, err = pgconn.ConnectConfig(context.Background(), config)
|
||||||
require.NoError(t, err)
|
require.NoError(t, err)
|
||||||
|
|
||||||
if _, ok := conn.Conn().(*tls.Conn); !ok {
|
if _, ok := conn.Conn().(*tls.Conn); !ok {
|
||||||
|
@ -2167,5 +2167,5 @@ func Example() {
|
||||||
|
|
||||||
func GetSSLPassword(ctx context.Context) string {
|
func GetSSLPassword(ctx context.Context) string {
|
||||||
connString := os.Getenv("PGX_SSL_PASSWORD")
|
connString := os.Getenv("PGX_SSL_PASSWORD")
|
||||||
return connString
|
return connString
|
||||||
}
|
}
|
Loading…
Reference in New Issue