Documentation
¶
Index ¶
- func BeforeConnectFn(ctx context.Context, config Config) (func(context.Context, *pgx.ConnConfig) error, error)
- func GetAuthenticatedConnString(ctx context.Context, config Config) (string, error)
- func GetConnector(ctx context.Context, config Config) (driver.Connector, error)
- func NewDBPool(ctx context.Context, config Config) (*pgxpool.Pool, error)
- func Open(ctx context.Context, config Config) (*sql.DB, error)
- type AuthMethod
- type Config
- type ConfigOpt
- type DefaultAuthConfigOptions
Constants ¶
This section is empty.
Variables ¶
This section is empty.
Functions ¶
func BeforeConnectFn ¶
func BeforeConnectFn(ctx context.Context, config Config) (func(context.Context, *pgx.ConnConfig) error, error)
BeforeConnectFn returns a function that can be used to set up the authentication before establishing a connection to the database.
func GetAuthenticatedConnString ¶
GetAuthenticatedConnString returns the database connection string based on the provided authentication configuration. It returns the original connection string if no authentication method is configured.
func GetConnector ¶
GetConnector initializes and returns a driver.Connector using the provided authentication configuration.
Types ¶
type AuthMethod ¶
type AuthMethod int
AuthMethod represents the type of authentication method used for connecting to the database.
const ( StandardAuth AuthMethod = iota // Default value, standard authentication AWSAuth // AWS authentication GCPAuth // GCP authentication AzureAuth // Azure authentication )
type Config ¶
type Config struct {
// contains filtered or unexported fields
}
Config holds the configuration for the database.
func DefaultConfig ¶
func DefaultConfig(ctx context.Context, connString string, authOpts DefaultAuthConfigOptions, opts ...ConfigOpt) (Config, error)
DefaultConfig initializes Config with default behavior across the auth methods. For Cloud based auth it assumes that application is running in the cloud environment. For AWS, it uses AWS IAM authentication For GCP, it uses GCP default credentials For Azure, it uses Managed Identity (MSI) authentication For StandardAuth, it uses the default PostgreSQL authentication
type ConfigOpt ¶ added in v1.0.0
type ConfigOpt func(r *Config)
ConfigOpt provides a method to customize a Config.
func WithAWSAuth ¶ added in v1.0.0
WithawsConfig sets the AWS configuration for the database connection.
func WithAzureAuth ¶ added in v1.0.0
func WithAzureAuth(creds azcore.TokenCredential) ConfigOpt
WithazureCreds sets the Azure credentials for the database connection.
func WithGoogleAuth ¶ added in v1.0.0
func WithGoogleAuth(creds *google.Credentials) ConfigOpt
WithGoogleCreds sets the Google credentials for the database connection.
func WithLogger ¶ added in v1.0.0
WithLogger sets the logger for the Config.
type DefaultAuthConfigOptions ¶
type DefaultAuthConfigOptions struct {
AuthMethod AuthMethod
// AWS IAM Auth
AWSDBRegion string
// Azure MSI Auth
AzureClientID string
}
DefaultAuthConfigOptions holds the configuration options for various authentication methods.