mirror of
https://github.com/hashicorp/go-pgmultiauth
synced 2026-04-05 19:10:05 +00:00
No description
- Go 100%
|
|
||
|---|---|---|
| .github | ||
| .gitignore | ||
| .go-version | ||
| aws.go | ||
| azure.go | ||
| CODEOWNERS | ||
| default.go | ||
| gcp.go | ||
| go.mod | ||
| go.sum | ||
| LICENSE | ||
| mocks_test.go | ||
| pgmultiauth.go | ||
| pgmultiauth_integration_test.go | ||
| pgmultiauth_test.go | ||
| README.md | ||
go-pgmultiauth
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.
Features
- 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
Authentication Methods
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(Managed Identity), Workload Identity
Installation
go get github.com/hashicorp/go-pgmultiauth
Usage
Using with database/sql.DB
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
Using with pgx connection pool
pool, err := pgmultiauth.NewDBPool(ctx, authConfig)
if err != nil {
// handle error
}
defer pool.Close()
// Use pool as a standard pgx.Pool
Using BeforeConnect function of pgxpool.Config
beforeConnect, err := pgmultiauth.BeforeConnectFn(ctx, authConfig)
if err != nil {
// handle error
}
poolConfig := pgxpool.Config{
ConnConfig: connConfig,
BeforeConnect: beforeConnect,
..
..
}
Using driver.Connector
dbConnector, err := pgmultiauth.GetConnector(ctx, dbAuthConfig)
if err != nil {
// handle error
}
db := sql.OpenDB(dbConnector)
Contributing
Thank you for your interest in contributing! Please refer to CONTRIBUTING.md for guidance.