postgres

package
v0.2.0 Latest Latest
Warning

This package is not in the latest version of its module.

Go to latest
Published: Oct 30, 2026 License: MIT Imports: 17 Imported by: 0

Documentation

Overview

Package postgres stores encrypted MFA factors through explicit migrations and generated model queries. It borrows an existing pool; constructors do no I/O.

Index

Constants

View Source
const (
	MigrationOrigin migrate.Origin  = "foundry.mfa"
	CreateFactors   migrate.ID      = "000001_create_factors"
	Introduced      migrate.Version = "v0.1.0"
)

Variables

This section is empty.

Functions

func Migrations

func Migrations() []migrate.Definition

Migrations must be applied explicitly alongside the application's migrations. No constructor mutates schemas. Each row stores encrypted factor material and hashes only; no plaintext TOTP/recovery code is stored.

Types

type Backend

type Backend struct {
	// contains filtered or unexported fields
}

func New

func New(db *database.DB, config Config) (*Backend, error)

func (*Backend) Prune

func (b *Backend) Prune(ctx context.Context, address mfa.Address, limit int) (uint64, error)

func (*Backend) ReplaceCiphertext

func (b *Backend) ReplaceCiphertext(ctx context.Context, stored mfa.StoredCiphertext, next encryption.Ciphertext) (bool, error)

ReplaceCiphertext is one conditional UPDATE: it waits for a concurrent factor transaction holding the row and then rechecks generation and envelope, so a replaced, removed or already rotated factor is never overwritten.

func (*Backend) StaleCiphertexts

func (b *Backend) StaleCiphertexts(ctx context.Context, active encryption.KeyID, after string, limit int) ([]mfa.StoredCiphertext, error)

StaleCiphertexts walks factors in primary-key order and returns those whose envelope does not carry the active key's prefix. It locks nothing.

func (*Backend) Within

func (*Backend) WithinIn

func (b *Backend) WithinIn(ctx context.Context, tx *database.Tx, address mfa.Address, identity model.Identity, prepare func(context.Context, *database.Tx) error, change func(context.Context, *database.Tx, value.Optional[mfa.Record], temporal.DateTime) (mfa.Change, error)) (value.Optional[mfa.Record], error)

type Config

type Config struct {
	Schema string
	Clock  clock.Clock
}

Config's schema applies to factor and domain-model callbacks. Instances must use synchronized clocks. All callbacks use this backend's supplied transaction.

func DefaultConfig

func DefaultConfig() Config

func (Config) Validate

func (c Config) Validate() error

Jump to

Keyboard shortcuts

? : This menu
/ : Search site
f or F : Jump to
y or Y : Canonical URL