mirror of https://github.com/jackc/pgx.git
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.pull/1372/head^2
parent
d8c04249d1
commit
6f90866f58
53
conn.go
53
conn.go
|
@ -42,6 +42,11 @@ type ConnConfig struct {
|
|||
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.
|
||||
// The only exception is the tls.Config:
|
||||
// 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)
|
||||
}
|
||||
|
||||
// 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.
|
||||
// connConfig must have been created by ParseConfig.
|
||||
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)
|
||||
}
|
||||
|
||||
// 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) {
|
||||
config, err := pgconn.ParseConfig(connString)
|
||||
// ParseConfigWithOptions behaves exactly as ParseConfig does with the addition of options. At the present options is
|
||||
// only used to provide a GetSSLPassword function.
|
||||
func ParseConfigWithOptions(connString string, options ParseConfigOptions) (*ConnConfig, error) {
|
||||
config, err := pgconn.ParseConfigWithOptions(connString, options.ParseConfigOptions)
|
||||
if err != nil {
|
||||
return nil, err
|
||||
}
|
||||
|
@ -191,6 +194,24 @@ func ParseConfig(connString string) (*ConnConfig, error) {
|
|||
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.
|
||||
func connect(ctx context.Context, config *ConnConfig) (c *Conn, err error) {
|
||||
if connectTracer, ok := config.Tracer.(ConnectTracer); ok {
|
||||
|
|
|
@ -64,7 +64,7 @@ type Config struct {
|
|||
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 {
|
||||
// GetSSLPassword gets the password to decrypt a SSL client certificate. This is analogous to the the libpq function
|
||||
// PQsetSSLKeyPassHook_OpenSSL.
|
||||
|
|
Loading…
Reference in New Issue