pgmultiauth
is a Go module that simplifies and streamlines authentication with PostgreSQL databases using multiple authentication methods. It provides a unified interface for connecting to PostgreSQL databases using various authentication mechanisms.
- Multiple Authentication Methods: Support for AWS, GCP, and Azure authentication.
- Connection Management: Handles token refresh and reconnection logic automatically
- Multiple consumption mechanism: Supports various handlers like *sql.DB, driver.Connector, *pgxpool.Pool etc
The module currently supports:
- AWS Authentication: For RDS and Aurora PostgreSQL instances
- GCP Authentication: For Cloud SQL PostgreSQL instances
- Azure Authentication: For Azure Database for PostgreSQL
go get github.com/hashicorp/go-pgmultiauth
authConfig := NewConfig(
connString,
WithAWSConfig(awsConfig),
)
db, err := pgmultiauth.Open(ctx, authConfig)
if err != nil {
// handle error
}
defer db.Close()
// Use db as a standard database/sql.DB
pool, err := pgmultiauth.NewDBPool(ctx, authConfig)
if err != nil {
// handle error
}
defer pool.Close()
// Use pool as a standard pgx.Pool
beforeConnect, err := pgmultiauth.BeforeConnectFn(ctx, authConfig)
if err != nil {
// handle error
}
poolConfig := pgxpool.Config{
ConnConfig: connConfig,
BeforeConnect: beforeConnect,
..
..
}
dbConnector, err := pgmultiauth.GetConnector(ctx, dbAuthConfig)
if err != nil {
// handle error
}
db := sql.OpenDB(dbConnector)
Thank you for your interest in contributing! Please refer to CONTRIBUTING.md for guidance.