Skip to content

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:

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.

About

No description, website, or topics provided.

Resources

Code of conduct

Contributing

Security policy

Stars

1 star

Watchers

23 watching

Forks

Releases

Packages

Used by

Contributors

Languages