postgres

package
v0.5.2 Latest Latest
Warning

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

Go to latest
Published: Nov 2, 2026 License: MIT Imports: 18 Imported by: 0

Documentation

Overview

Package postgres persists single-use recovery credentials through explicit migrations and generated queries. It borrows the application's existing pool.

Index

Constants

View Source
const (
	MigrationOrigin  migrate.Origin  = "foundry.challenges"
	CreateChallenges migrate.ID      = "000001_create_challenges"
	Introduced       migrate.Version = "v0.1.0"
)

Variables

This section is empty.

Functions

func Migrations

func Migrations() []migrate.Definition

Migrations must be registered and applied explicitly. Subject rows are stable synchronization records and are not garbage-collected by ordinary pruning.

Types

type Backend

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

Backend persists single-use challenges in PostgreSQL using a borrowed database pool.

func New

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

New validates configuration and creates an adapter borrowing db.

func (*Backend) Consume

Consume locks and rechecks the token, applies model changes and deletes the token in one transaction. Expiry during the action rolls back its writes.

func (*Backend) Issue

func (b *Backend) Issue(ctx context.Context, address challenge.Address, identity model.Identity, hash challenge.Digest, lifetime time.Duration, prepare func(context.Context, *database.Tx) (challenge.Binding, error)) (challenge.Record, error)

Issue locks the challenge subject, prepares its binding and atomically replaces the previous token.

func (*Backend) Prune

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

Prune deletes at most limit expired challenges after locking and rechecking each candidate.

func (*Backend) Revoke

func (b *Backend) Revoke(ctx context.Context, address challenge.Address, identity model.Identity) (bool, error)

Revoke locks the subject and removes its challenge, reporting whether one existed.

type Config

type Config struct {
	Schema string
	Clock  clock.Clock
}

Config's schema is shared by challenge and domain-model queries inside the callback. Instances must share synchronized clocks. Construction does no I/O.

func DefaultConfig

func DefaultConfig() Config

DefaultConfig returns the public schema and system clock.

func (Config) Validate

func (c Config) Validate() error

Validate requires a valid SQL schema and a non-nil clock.

Jump to

Keyboard shortcuts

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