Documentation
¶
Overview ¶
Package postgres provides a native PostgreSQL adapter for auth stores.
Index ¶
- Variables
- func DeleteData(ctx context.Context, db *sql.DB) error
- func Migrate(ctx context.Context, db *sql.DB) error
- func Migrations() []migrate.Migration
- func Open(ctx context.Context, dsn string) (*sql.DB, error)
- func ValidateSchema(ctx context.Context, db *sql.DB) error
- type MigrationDriver
- type Store
- func (s *Store) CreateAPIKey(ctx context.Context, key auth.APIKey) error
- func (s *Store) CreateAPIKeyWithAudit(ctx context.Context, key auth.APIKey, event auth.AuditEvent) error
- func (s *Store) CreatePrincipal(ctx context.Context, principal auth.Principal) error
- func (s *Store) DeleteData(ctx context.Context) error
- func (s *Store) GetAPIKeyByID(ctx context.Context, keyID string) (auth.APIKey, error)
- func (s *Store) GetAPIKeyByPrefix(ctx context.Context, prefix string) (auth.APIKey, error)
- func (s *Store) GetPrincipal(ctx context.Context, principalType auth.PrincipalType, principalID string) (auth.Principal, error)
- func (s *Store) ListAPIKeys(ctx context.Context, ownerType auth.PrincipalType, ownerID string, ...) (auth.Page[auth.APIKey], error)
- func (s *Store) RecordAuditEvent(ctx context.Context, event auth.AuditEvent) error
- func (s *Store) RevokeAPIKey(ctx context.Context, keyID string, revokedAt time.Time) error
- func (s *Store) RevokeAPIKeyWithAudit(ctx context.Context, keyID string, revokedAt time.Time, event auth.AuditEvent) (auth.APIKey, error)
- func (s *Store) TouchAPIKey(ctx context.Context, keyID string, usedAt time.Time) error
Constants ¶
This section is empty.
Variables ¶
var ErrIncompatibleSchema = errors.New("postgres: incompatible schema")
ErrIncompatibleSchema reports an existing auth schema that cannot safely be used by the PostgreSQL adapter.
Functions ¶
func DeleteData ¶
DeleteData deletes all auth adapter data while keeping the PostgreSQL schema.
This is intentionally separate from Migrate so schema creation stays non-destructive unless callers explicitly choose to delete data.
func Migrations ¶
Migrations returns the PostgreSQL schema migrations for the auth adapter.
Types ¶
type MigrationDriver ¶
type MigrationDriver struct {
// contains filtered or unexported fields
}
MigrationDriver implements migrate.Driver for PostgreSQL.
func NewMigrationDriver ¶
func NewMigrationDriver(db *sql.DB) *MigrationDriver
NewMigrationDriver creates a PostgreSQL migration driver.
func (*MigrationDriver) Applied ¶
func (d *MigrationDriver) Applied(ctx context.Context) (map[int64]migrate.AppliedMigration, error)
Applied returns migrations already applied, keyed by version.
func (*MigrationDriver) EnsureSchema ¶
func (d *MigrationDriver) EnsureSchema(ctx context.Context) error
EnsureSchema creates the migration metadata table if needed.
type Store ¶
type Store struct {
// contains filtered or unexported fields
}
Store implements auth stores using PostgreSQL.
func (*Store) CreateAPIKey ¶
CreateAPIKey stores API key metadata.
func (*Store) CreateAPIKeyWithAudit ¶
func (s *Store) CreateAPIKeyWithAudit(ctx context.Context, key auth.APIKey, event auth.AuditEvent) error
CreateAPIKeyWithAudit stores API key metadata and its audit event atomically.
func (*Store) CreatePrincipal ¶
CreatePrincipal stores a user or group principal.
func (*Store) DeleteData ¶
DeleteData deletes all auth adapter data while keeping the PostgreSQL schema.
func (*Store) GetAPIKeyByID ¶
GetAPIKeyByID returns API key metadata by ID.
func (*Store) GetAPIKeyByPrefix ¶
GetAPIKeyByPrefix returns API key metadata by public prefix.
func (*Store) GetPrincipal ¶
func (s *Store) GetPrincipal(ctx context.Context, principalType auth.PrincipalType, principalID string) (auth.Principal, error)
GetPrincipal returns a user or group principal.
func (*Store) ListAPIKeys ¶
func (s *Store) ListAPIKeys(ctx context.Context, ownerType auth.PrincipalType, ownerID string, page auth.PageRequest) (auth.Page[auth.APIKey], error)
ListAPIKeys returns a page of keys for a principal.
func (*Store) RecordAuditEvent ¶
RecordAuditEvent stores an audit event.
func (*Store) RevokeAPIKey ¶
RevokeAPIKey marks an API key as revoked.