Expose underlying pgconn GetSSLPassword support to pgx
pgconn supports a GetSSLPassword function but the pgx connection functions did not expose a means of using it. See PR #1233 for more context.
This commit is contained in:
@@ -42,6 +42,11 @@ type ConnConfig struct {
|
|||||||
createdByParseConfig bool // Used to enforce created by ParseConfig rule.
|
createdByParseConfig bool // Used to enforce created by ParseConfig rule.
|
||||||
}
|
}
|
||||||
|
|
||||||
|
// ParseConfigOptions contains options that control how a config is built such as getsslpassword.
|
||||||
|
type ParseConfigOptions struct {
|
||||||
|
pgconn.ParseConfigOptions
|
||||||
|
}
|
||||||
|
|
||||||
// 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.
|
||||||
// The only exception is the tls.Config:
|
// The only exception is the tls.Config:
|
||||||
// according to the tls.Config docs it must not be modified after creation.
|
// according to the tls.Config docs it must not be modified after creation.
|
||||||
@@ -110,6 +115,16 @@ func Connect(ctx context.Context, connString string) (*Conn, error) {
|
|||||||
return connect(ctx, connConfig)
|
return connect(ctx, connConfig)
|
||||||
}
|
}
|
||||||
|
|
||||||
|
// ConnectWithOptions behaves exactly like Connect with the addition of options. At the present options is only used to
|
||||||
|
// provide a GetSSLPassword function.
|
||||||
|
func ConnectWithOptions(ctx context.Context, connString string, options ParseConfigOptions) (*Conn, error) {
|
||||||
|
connConfig, err := ParseConfigWithOptions(connString, options)
|
||||||
|
if err != nil {
|
||||||
|
return nil, err
|
||||||
|
}
|
||||||
|
return connect(ctx, connConfig)
|
||||||
|
}
|
||||||
|
|
||||||
// ConnectConfig establishes a connection with a PostgreSQL server with a configuration struct.
|
// ConnectConfig establishes a connection with a PostgreSQL server with a configuration struct.
|
||||||
// connConfig must have been created by ParseConfig.
|
// connConfig must have been created by ParseConfig.
|
||||||
func ConnectConfig(ctx context.Context, connConfig *ConnConfig) (*Conn, error) {
|
func ConnectConfig(ctx context.Context, connConfig *ConnConfig) (*Conn, error) {
|
||||||
@@ -120,22 +135,10 @@ func ConnectConfig(ctx context.Context, connConfig *ConnConfig) (*Conn, error) {
|
|||||||
return connect(ctx, connConfig)
|
return connect(ctx, connConfig)
|
||||||
}
|
}
|
||||||
|
|
||||||
// ParseConfig creates a ConnConfig from a connection string. ParseConfig handles all options that pgconn.ParseConfig
|
// ParseConfigWithOptions behaves exactly as ParseConfig does with the addition of options. At the present options is
|
||||||
// does. In addition, it accepts the following options:
|
// only used to provide a GetSSLPassword function.
|
||||||
//
|
func ParseConfigWithOptions(connString string, options ParseConfigOptions) (*ConnConfig, error) {
|
||||||
// default_query_exec_mode
|
config, err := pgconn.ParseConfigWithOptions(connString, options.ParseConfigOptions)
|
||||||
// Possible values: "cache_statement", "cache_describe", "describe_exec", "exec", and "simple_protocol". See
|
|
||||||
// QueryExecMode constant documentation for the meaning of these values. Default: "cache_statement".
|
|
||||||
//
|
|
||||||
// statement_cache_capacity
|
|
||||||
// The maximum size of the statement cache used when executing a query with "cache_statement" query exec mode.
|
|
||||||
// Default: 512.
|
|
||||||
//
|
|
||||||
// description_cache_capacity
|
|
||||||
// The maximum size of the description cache used when executing a query with "cache_describe" query exec mode.
|
|
||||||
// Default: 512.
|
|
||||||
func ParseConfig(connString string) (*ConnConfig, error) {
|
|
||||||
config, err := pgconn.ParseConfig(connString)
|
|
||||||
if err != nil {
|
if err != nil {
|
||||||
return nil, err
|
return nil, err
|
||||||
}
|
}
|
||||||
@@ -191,6 +194,24 @@ func ParseConfig(connString string) (*ConnConfig, error) {
|
|||||||
return connConfig, nil
|
return connConfig, nil
|
||||||
}
|
}
|
||||||
|
|
||||||
|
// ParseConfig creates a ConnConfig from a connection string. ParseConfig handles all options that pgconn.ParseConfig
|
||||||
|
// does. In addition, it accepts the following options:
|
||||||
|
//
|
||||||
|
// default_query_exec_mode
|
||||||
|
// Possible values: "cache_statement", "cache_describe", "describe_exec", "exec", and "simple_protocol". See
|
||||||
|
// QueryExecMode constant documentation for the meaning of these values. Default: "cache_statement".
|
||||||
|
//
|
||||||
|
// statement_cache_capacity
|
||||||
|
// The maximum size of the statement cache used when executing a query with "cache_statement" query exec mode.
|
||||||
|
// Default: 512.
|
||||||
|
//
|
||||||
|
// description_cache_capacity
|
||||||
|
// The maximum size of the description cache used when executing a query with "cache_describe" query exec mode.
|
||||||
|
// Default: 512.
|
||||||
|
func ParseConfig(connString string) (*ConnConfig, error) {
|
||||||
|
return ParseConfigWithOptions(connString, ParseConfigOptions{})
|
||||||
|
}
|
||||||
|
|
||||||
// connect connects to a database. connect takes ownership of config. The caller must not use or access it again.
|
// connect connects to a database. connect takes ownership of config. The caller must not use or access it again.
|
||||||
func connect(ctx context.Context, config *ConnConfig) (c *Conn, err error) {
|
func connect(ctx context.Context, config *ConnConfig) (c *Conn, err error) {
|
||||||
if connectTracer, ok := config.Tracer.(ConnectTracer); ok {
|
if connectTracer, ok := config.Tracer.(ConnectTracer); ok {
|
||||||
|
|||||||
+1
-1
@@ -64,7 +64,7 @@ type Config struct {
|
|||||||
createdByParseConfig bool // Used to enforce created by ParseConfig rule.
|
createdByParseConfig bool // Used to enforce created by ParseConfig rule.
|
||||||
}
|
}
|
||||||
|
|
||||||
// ParseConfigOptions contains options that control how a config is built such as getsslpassword.
|
// ParseConfigOptions contains options that control how a config is built such as GetSSLPassword.
|
||||||
type ParseConfigOptions struct {
|
type ParseConfigOptions struct {
|
||||||
// GetSSLPassword gets the password to decrypt a SSL client certificate. This is analogous to the the libpq function
|
// GetSSLPassword gets the password to decrypt a SSL client certificate. This is analogous to the the libpq function
|
||||||
// PQsetSSLKeyPassHook_OpenSSL.
|
// PQsetSSLKeyPassHook_OpenSSL.
|
||||||
|
|||||||
Reference in New Issue
Block a user