postgres

package
v0.1.0 Latest Latest
Warning

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

Go to latest
Published: Jun 11, 2026 License: AGPL-3.0 Imports: 35 Imported by: 0

Documentation

Overview

Package postgres provides PostgreSQL implementations of the output port interfaces.

Index

Constants

This section is empty.

Variables

This section is empty.

Functions

This section is empty.

Types

type AssertionJTIStore

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

AssertionJTIStore implements output.AssertionJTIStore using PostgreSQL.

func (*AssertionJTIStore) ConsumeJTI

func (s *AssertionJTIStore) ConsumeJTI(ctx context.Context, jti string, expiry time.Time) error

ConsumeJTI marks an assertion JTI as used. Returns domain.ErrAssertionReplay if already consumed.

func (*AssertionJTIStore) PurgeExpired

func (s *AssertionJTIStore) PurgeExpired(ctx context.Context) error

PurgeExpired removes expired assertion JTI records from storage.

type AuditStore

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

AuditStore implements output.AuditStore using PostgreSQL. Append-only writes. Query supports client_id filter (closes compliance gap 15.14).

func (*AuditStore) Query

func (s *AuditStore) Query(ctx context.Context, filter output.AuditFilter) ([]audit.Event, error)

Query implements output.AuditStore.

func (*AuditStore) Record

func (s *AuditStore) Record(ctx context.Context, e *audit.Event) error

Record implements output.AuditStore.

type BrokerGrantStore

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

BrokerGrantStore implements output.BrokerGrantStore using PostgreSQL against the broker_grants table. Schema lives in migrations/postgres/001_initial.up.sql lines 537-555.

CredentialData is opaque BYTEA bytes — see the port comment.

func (*BrokerGrantStore) Create

Create inserts a new grant with version = 1. Caller must Revoke any previous active row for the same (user, provider) before calling Create — see port comment for the re-connect contract.

func (*BrokerGrantStore) Get

func (s *BrokerGrantStore) Get(ctx context.Context, userID, brokerProviderID string) (*resource.BrokerGrant, error)

Get returns the active grant for (user, broker_provider) or (nil, nil) when no row matches.

func (*BrokerGrantStore) GetByID

GetByID returns the grant with the given id (active or revoked) or (nil, nil) when no row matches. Used by the admin revoke path (the design audit-followup B17) for audit-detail enrichment.

func (*BrokerGrantStore) ListForUser

func (s *BrokerGrantStore) ListForUser(ctx context.Context, userID string) ([]*resource.BrokerGrant, error)

ListForUser returns all grants for the user (active + revoked), newest first.

func (*BrokerGrantStore) Revoke

func (s *BrokerGrantStore) Revoke(ctx context.Context, id string) error

Revoke sets revoked_at on the row with the given id. Idempotent.

func (*BrokerGrantStore) UpdateWithVersion

func (s *BrokerGrantStore) UpdateWithVersion(ctx context.Context, g *resource.BrokerGrant) error

UpdateWithVersion atomically updates credential_data, scopes_granted, enc_backend, and updated_at; increments version; matches on (id, version). Returns domain.ErrBrokerGrantConflict on stale version (0 rows affected). the data model Q4.

func (*BrokerGrantStore) Upsert

Upsert atomically inserts a new grant OR updates the existing (user_id, broker_provider_id) row. On conflict it resurrects soft- deleted rows (clears revoked_at), replaces credential_data, scopes_granted, enc_backend, bumps version by 1, and refreshes updated_at. Preserves the existing row's id (the supplied g.ID is only persisted on insert). Returns the canonical post-mutation row so the caller can audit/log the actual id+version..

type BrokerProviderStore

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

BrokerProviderStore implements output.BrokerProviderStore using PostgreSQL.

func (*BrokerProviderStore) Create

Create inserts a new BrokerProvider.

func (*BrokerProviderStore) Delete

func (s *BrokerProviderStore) Delete(ctx context.Context, id string) error

Delete removes the BrokerProvider by id.

func (*BrokerProviderStore) GetByID

GetByID returns the BrokerProvider with the given id.

func (*BrokerProviderStore) GetBySlug

GetBySlug returns the BrokerProvider with the given slug.

func (*BrokerProviderStore) List

List returns all providers ordered by slug.

func (*BrokerProviderStore) Update

Update replaces the BrokerProvider with id p.ID.

type ClientStore

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

ClientStore implements output.ClientStore using PostgreSQL.

func (*ClientStore) Count

func (s *ClientStore) Count(ctx context.Context, status string) (int, error)

Count implements output.ClientStore.

func (*ClientStore) Create

func (s *ClientStore) Create(ctx context.Context, c *client.Client) error

Create implements output.ClientStore.

func (*ClientStore) Delete

func (s *ClientStore) Delete(ctx context.Context, id string) error

Delete implements output.ClientStore.

func (*ClientStore) GetByCIMDURL

func (s *ClientStore) GetByCIMDURL(ctx context.Context, url string) (*client.Client, error)

GetByCIMDURL implements output.ClientStore.

func (*ClientStore) GetByID

func (s *ClientStore) GetByID(ctx context.Context, id string) (*client.Client, error)

GetByID implements output.ClientStore.

func (*ClientStore) List

func (s *ClientStore) List(ctx context.Context, status, source string, limit, offset int) ([]client.Client, error)

List implements output.ClientStore. List implements output.ClientStore.

func (*ClientStore) ListAgents

func (s *ClientStore) ListAgents(ctx context.Context) ([]client.Client, error)

ListAgents implements output.ClientStore.

func (*ClientStore) Update

func (s *ClientStore) Update(ctx context.Context, c *client.Client) error

Update implements output.ClientStore.

type ConfigChangeListener

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

ConfigChangeListener subscribes to PostgreSQL LISTEN/NOTIFY on a named channel and triggers a reload callback when changes are detected.

It uses a raw pgx.Conn (not a pool) because LISTEN requires a persistent connection. On disconnect, it reconnects with exponential backoff and falls back to polling until the connection is restored.

func NewConfigChangeListener

func NewConfigChangeListener(
	dsn string,
	channel string,
	reloadFn func(context.Context) error,
	obs *observability.Provider,
) *ConfigChangeListener

NewConfigChangeListener creates a listener that watches for config changes on the given PostgreSQL NOTIFY channel. reloadFn is called when a notification is received (typically CachedXxx.Reload).

func (*ConfigChangeListener) Run

Run starts the LISTEN loop. It blocks until ctx is canceled. On connection failure, it reconnects with exponential backoff and polls as a fallback while disconnected.

type ConnectPendingStateStore

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

ConnectPendingStateStore implements output.ConnectPendingStateStore using PostgreSQL against the connect_pending_states table. Schema lives in migrations/postgres/001_initial.up.sql lines 588-602.

func (*ConnectPendingStateStore) Consume

Consume atomically reads + deletes the row using DELETE ... RETURNING. Single-use: a second Consume on the same id returns domain.ErrPendingStateNotFound.

func (*ConnectPendingStateStore) Insert

Insert persists a new pending-state row.

func (*ConnectPendingStateStore) PurgeExpired

func (s *ConnectPendingStateStore) PurgeExpired(ctx context.Context, before time.Time) (int, error)

PurgeExpired deletes rows whose expires_at is before the given instant.

type ConsentGrantStore

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

ConsentGrantStore implements output.ConsentGrantStore using PostgreSQL against the consent_grants table. Schema lives in migrations/postgres/001_initial.up.sql lines 518-535.

func (*ConsentGrantStore) Get

func (s *ConsentGrantStore) Get(ctx context.Context, userID, clientID, resourceID string) (*resource.ConsentGrant, error)

Get returns the active grant for (user, client, resource) or (nil, nil) when no row matches.

func (*ConsentGrantStore) GetByID

GetByID returns the grant with the given id (active or revoked) or (nil, nil) when no row matches. Used by the admin revocation cascade.

func (*ConsentGrantStore) ListForUser

func (s *ConsentGrantStore) ListForUser(ctx context.Context, userID string) ([]*resource.ConsentGrant, error)

ListForUser returns all grants for the user (active + revoked), newest first.

func (*ConsentGrantStore) Revoke

func (s *ConsentGrantStore) Revoke(ctx context.Context, id string) error

Revoke sets revoked_at on the row with the given id. Idempotent.

func (*ConsentGrantStore) Upsert

Upsert inserts a new grant or updates the existing row keyed on (user_id, client_id, resource_id). A re-grant after revocation re-activates the same row by clearing revoked_at.

type DB

type DB struct {
	Pool *pgxpool.Pool
	// contains filtered or unexported fields
}

DB wraps a pgxpool.Pool with helpers and migration support. It implements output.DataStore.

func Open

func Open(ctx context.Context, dsn string, poolCfg PoolConfig, obs *observability.Provider) (*DB, error)

Open creates a new PostgreSQL connection pool with the given DSN. The pool is configured from PoolConfig; zero values use pgx defaults.

func WrapPool

func WrapPool(pool *pgxpool.Pool, obs *observability.Provider) *DB

WrapPool creates a DB using an externally-managed pool. Intended for tests where the pool lifecycle is controlled externally.

func (*DB) AssertionJTI

func (d *DB) AssertionJTI() output.AssertionJTIStore

AssertionJTI returns the assertion JTI store.

func (*DB) Audit

func (d *DB) Audit() output.AuditStore

Audit returns the audit store.

func (*DB) BrokerGrant

func (d *DB) BrokerGrant() output.BrokerGrantStore

BrokerGrant returns the BrokerGrant store.

func (*DB) BrokerProvider

func (d *DB) BrokerProvider() output.BrokerProviderStore

BrokerProvider returns the BrokerProvider store.

func (*DB) Client

func (d *DB) Client() output.ClientStore

Client returns the client store.

func (*DB) Close

func (d *DB) Close() error

Close closes the connection pool.

func (*DB) ConnectPendingState

func (d *DB) ConnectPendingState() output.ConnectPendingStateStore

ConnectPendingState returns the ConnectPendingStateStore.

func (*DB) ConsentGrant

func (d *DB) ConsentGrant() output.ConsentGrantStore

ConsentGrant returns the unified ConsentGrant store.

func (*DB) DPoPNonce

func (d *DB) DPoPNonce() output.DPoPNonceStore

DPoPNonce returns the DPoP nonce store.

func (d *DB) FrontingLink() output.FrontingLinkStore

FrontingLink returns the FrontingLinkStore.

func (*DB) IDP

func (d *DB) IDP() output.IDPStore

IDP returns the identity provider store.

func (*DB) Issuance

func (d *DB) Issuance() output.IssuanceStore

Issuance returns the unified IssuanceStore.

func (*DB) MachineToken

func (d *DB) MachineToken() output.MachineTokenStore

MachineToken returns the machine token store.

func (*DB) Migrate

func (d *DB) Migrate(ctx context.Context) error

Migrate runs all pending SQL migrations from the embedded FS.

func (*DB) NewStores

func (d *DB) NewStores() *Stores

NewStores returns all store implementations sharing this pool.

func (*DB) Ping

func (d *DB) Ping(ctx context.Context) error

Ping verifies the database connection is alive.

func (*DB) Resource

func (d *DB) Resource() output.ResourceStore

Resource returns the unified Resource store.

func (*DB) Revocation

func (d *DB) Revocation() output.RevocationStore

Revocation returns the revocation store.

func (*DB) RuntimeSettings

func (d *DB) RuntimeSettings() output.RuntimeSettingsStore

RuntimeSettings returns the runtime settings store.

func (*DB) Session

func (d *DB) Session() output.SessionStore

Session returns the session store.

func (*DB) SubjectMapping

func (d *DB) SubjectMapping() output.SubjectMappingStore

SubjectMapping returns the subject mapping store.

func (*DB) Token

func (d *DB) Token() output.TokenStore

Token returns the token store.

func (*DB) Transaction

func (d *DB) Transaction() output.TransactionManager

Transaction returns the transaction manager.

func (*DB) User

func (d *DB) User() output.UserStore

User returns the user store.

func (*DB) XAAPolicy

func (d *DB) XAAPolicy() output.XAAPolicyStore

XAAPolicy returns the XAA policy store.

type DPoPNonceStore

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

DPoPNonceStore implements output.DPoPNonceStore using PostgreSQL.

func (*DPoPNonceStore) ConsumeJTI

func (s *DPoPNonceStore) ConsumeJTI(ctx context.Context, jti string, expiry time.Time) error

ConsumeJTI records a DPoP proof JTI. Returns domain.ErrDPoPReplay if already consumed.

func (*DPoPNonceStore) IssueNonce

func (s *DPoPNonceStore) IssueNonce(ctx context.Context, ttl time.Duration) (string, error)

IssueNonce generates and stores a server nonce with the given TTL.

func (*DPoPNonceStore) PurgeExpired

func (s *DPoPNonceStore) PurgeExpired(ctx context.Context) error

PurgeExpired removes expired JTIs and nonces from storage.

func (*DPoPNonceStore) ValidateNonce

func (s *DPoPNonceStore) ValidateNonce(ctx context.Context, nonce string) error

ValidateNonce checks that a nonce exists and has not expired.

type FrontingLinkStore

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

FrontingLinkStore implements output.FrontingLinkStore using PostgreSQL. Schema lives in migrations/postgres/001_initial.up.sql.

func (*FrontingLinkStore) Create

Create inserts a new link. UNIQUE-violation on (source_slug, target_slug) surfaces as domain.ErrFrontingLinkExists; FK miss surfaces as domain.NewInvalidRequestError carrying the offending slug — the service layer pre-checks Resource existence so this is defense in depth only.

func (*FrontingLinkStore) Delete

func (s *FrontingLinkStore) Delete(ctx context.Context, sourceSlug, targetSlug string) error

Delete removes the link.

func (*FrontingLinkStore) DeleteForResource

func (s *FrontingLinkStore) DeleteForResource(ctx context.Context, slug string) (int, error)

DeleteForResource removes every link referencing slug (source OR target) and returns the number of rows deleted. Used by the cascade-on-delete path in ResourceAdminService.

func (*FrontingLinkStore) Get

func (s *FrontingLinkStore) Get(ctx context.Context, sourceSlug, targetSlug string) (*resource.FrontingLink, error)

Get returns the link with the given (source, target) pair.

func (*FrontingLinkStore) List

List returns links matching the filter ordered by (source_slug, target_slug).

func (*FrontingLinkStore) ListForResource

func (s *FrontingLinkStore) ListForResource(ctx context.Context, slug string) ([]*resource.FrontingLink, error)

ListForResource returns every link that names slug as either source or target. Used by the per-Resource detail view and cascade preflight.

func (*FrontingLinkStore) Update

Update replaces the scope_map of an existing link. created_at + created_by are intentionally preserved — patching them would erase audit provenance.

type HAKeyStore

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

HAKeyStore implements output.KeyStore using PostgreSQL with encrypted-at-rest PEM storage and atomic rotation via a unique partial index.

Keys are encrypted via the DataEncryptor port (aes_master or vault_transit_encrypt). The ownerContext for HKDF derivation is "signing-key:<kid>".

Concurrent rotation is prevented by a unique partial index on (is_current) WHERE is_current = TRUE. If two pods try to rotate simultaneously, one gets a unique violation and retries with backoff.

A cached atomic.Pointer holds the current signing key for fast reads; the listener invalidates it on NOTIFY and the JWKS service reloads.

func NewHAKeyStore

func NewHAKeyStore(pool *pgxpool.Pool, encryptor output.DataEncryptor, obs *observability.Provider) *HAKeyStore

NewHAKeyStore creates an HA-safe PostgreSQL signing key store.

func (*HAKeyStore) InvalidateCache

func (s *HAKeyStore) InvalidateCache()

InvalidateCache clears the cached current key. Called by the listener on NOTIFY.

func (*HAKeyStore) ListActive

func (s *HAKeyStore) ListActive(ctx context.Context) ([]*output.SigningKey, error)

ListActive returns all active signing keys (current first, then previous). Returns empty slice (not nil) if no keys exist.

func (*HAKeyStore) LoadCurrent

func (s *HAKeyStore) LoadCurrent(ctx context.Context) (*output.SigningKey, error)

LoadCurrent returns the current signing key. Uses an atomic cache for fast-path reads. Returns nil, nil if no current key exists.

func (*HAKeyStore) LoadPrevious

func (s *HAKeyStore) LoadPrevious(ctx context.Context) (*output.SigningKey, error)

LoadPrevious returns the most recent non-current signing key. Returns nil, nil if no previous key exists.

func (*HAKeyStore) Save

func (s *HAKeyStore) Save(ctx context.Context, key *output.SigningKey) error

Save persists a signing key with atomic rotation.

In a single transaction:

  1. Demote the current key (is_current = FALSE)
  2. Encrypt and INSERT the new key with is_current = TRUE
  3. Delete old non-current keys (keep at most 1 previous)

The unique partial index prevents two concurrent rotations. On unique violation, retries up to 3 times with exponential backoff.

type IDPStore

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

IDPStore implements output.IDPStore using PostgreSQL.

func (*IDPStore) Delete

func (s *IDPStore) Delete(ctx context.Context, id string) error

Delete implements output.IDPStore.

func (*IDPStore) GetByID

func (s *IDPStore) GetByID(ctx context.Context, id string) (*idp.TrustedIDP, error)

GetByID implements output.IDPStore.

func (*IDPStore) GetByIssuer

func (s *IDPStore) GetByIssuer(ctx context.Context, issuer string) (*idp.TrustedIDP, error)

GetByIssuer implements output.IDPStore.

func (*IDPStore) List

func (s *IDPStore) List(ctx context.Context) ([]idp.TrustedIDP, error)

List implements output.IDPStore.

func (*IDPStore) Save

func (s *IDPStore) Save(ctx context.Context, i idp.TrustedIDP) error

Save implements output.IDPStore.

type IssuanceStore

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

IssuanceStore implements output.IssuanceStore using PostgreSQL against the issuances table. Schema lives in migrations/postgres/001_initial.up.sql lines 557-586.

func (*IssuanceStore) GetByID

func (s *IssuanceStore) GetByID(ctx context.Context, id string) (*resource.Issuance, error)

GetByID returns the issuance whose id matches, or (nil, nil) on miss. Used by the admin path-keyed GET endpoint; Broker issuances (empty jti per ) remain addressable through this lookup. The (nil, nil) miss contract mirrors GetByJTI in this same store — sentinel-error mapping happens at the service layer.

func (*IssuanceStore) GetByJTI

func (s *IssuanceStore) GetByJTI(ctx context.Context, jti string) (*resource.Issuance, error)

GetByJTI returns the issuance whose jti matches, or (nil, nil).

func (*IssuanceStore) Insert

func (s *IssuanceStore) Insert(ctx context.Context, i *resource.Issuance) error

Insert writes a new issuance row.

func (*IssuanceStore) ListForActor

func (s *IssuanceStore) ListForActor(ctx context.Context, clientID string, since time.Time) ([]*resource.Issuance, error)

ListForActor returns issuances where client_id matches and issued_at >= since, newest first.

func (*IssuanceStore) ListForResource

func (s *IssuanceStore) ListForResource(ctx context.Context, resourceID string, since time.Time) ([]*resource.Issuance, error)

ListForResource returns issuances where resource_id matches and issued_at >= since, newest first.

func (*IssuanceStore) ListForUser

func (s *IssuanceStore) ListForUser(ctx context.Context, userID string, since time.Time) ([]*resource.Issuance, error)

ListForUser returns issuances for the user issued at/after since, newest first.

func (*IssuanceStore) PurgeExpired

func (s *IssuanceStore) PurgeExpired(ctx context.Context, before time.Time) (int, error)

PurgeExpired deletes rows past the retention window.

func (*IssuanceStore) Revoke

func (s *IssuanceStore) Revoke(ctx context.Context, id string) error

Revoke sets revoked_at on the row with the given id. Idempotent.

func (*IssuanceStore) RevokeFamily

func (s *IssuanceStore) RevokeFamily(ctx context.Context, userID, clientID, resourceID string) (int, error)

RevokeFamily marks every active Mint issuance for the (user, client, resource) tuple as revoked and returns the count of rows updated.

type KeyStoreListener

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

KeyStoreListener subscribes to PostgreSQL LISTEN/NOTIFY on the signing_key_change channel and triggers cache invalidation + JWKS reload.

It uses a raw pgx.Conn (not a pool) because LISTEN requires a persistent connection. On disconnect, it reconnects with exponential backoff and falls back to polling until the connection is restored.

func NewKeyStoreListener

func NewKeyStoreListener(dsn string, store *HAKeyStore, reloadFn func(context.Context) error, obs *observability.Provider) *KeyStoreListener

NewKeyStoreListener creates a listener that watches for signing key changes. reloadFn is called after cache invalidation (typically JWKSService.Reload).

func (*KeyStoreListener) Run

func (l *KeyStoreListener) Run(ctx context.Context) error

Run starts the LISTEN loop. It blocks until ctx is canceled. On connection failure, it reconnects with exponential backoff and polls as a fallback while disconnected.

type MachineTokenStore

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

MachineTokenStore implements output.MachineTokenStore using PostgreSQL.

func (*MachineTokenStore) CountIssuedSince

func (s *MachineTokenStore) CountIssuedSince(ctx context.Context, since int64) (int, error)

CountIssuedSince returns the number of machine tokens issued since the given unix timestamp.

func (*MachineTokenStore) CountRevokedSince

func (s *MachineTokenStore) CountRevokedSince(ctx context.Context, since int64) (int, error)

CountRevokedSince returns the number of machine tokens revoked since the given unix timestamp. Note: machine_tokens table tracks revoked as a boolean, not a timestamp. We approximate by counting revoked tokens that were issued since the given time.

func (*MachineTokenStore) GetByJTI

func (s *MachineTokenStore) GetByJTI(ctx context.Context, jti string) (*token.MachineToken, error)

GetByJTI returns a machine token by its JTI. Returns nil, nil if not found.

func (*MachineTokenStore) List

List returns machine tokens matching the filter.

func (*MachineTokenStore) PurgeExpired

func (s *MachineTokenStore) PurgeExpired(ctx context.Context) error

PurgeExpired removes expired machine tokens from storage.

func (*MachineTokenStore) Revoke

func (s *MachineTokenStore) Revoke(ctx context.Context, jti string) error

Revoke marks a machine token as revoked by JTI.

func (*MachineTokenStore) RevokeByClientID

func (s *MachineTokenStore) RevokeByClientID(ctx context.Context, clientID string) (int, error)

RevokeByClientID revokes all active machine tokens for a client.

func (*MachineTokenStore) Save

Save persists a machine token record.

type PoolConfig

type PoolConfig struct {
	MaxConns        int32
	MinConns        int32
	MaxConnLifetime time.Duration
	MaxConnIdleTime time.Duration
}

PoolConfig captures the pool-tuning knobs the storage layer exposes. Zero values are left as pgx's defaults.

type ResourceStore

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

ResourceStore implements output.ResourceStore using PostgreSQL. Schema is in migrations/postgres/001_initial.up.sql (see ).

func (*ResourceStore) Create

func (s *ResourceStore) Create(ctx context.Context, r *resource.Resource) error

Create inserts a new Resource.

func (*ResourceStore) Delete

func (s *ResourceStore) Delete(ctx context.Context, id string) error

Delete removes the Resource by id.

func (*ResourceStore) FindByRuntimeClientID

func (s *ResourceStore) FindByRuntimeClientID(ctx context.Context, clientID string) (*resource.Resource, error)

FindByRuntimeClientID returns the Resource whose policy.runtime.client_ids jsonb array contains clientID.. Uses jsonb's `?` containment operator (escaped to `?` in pgx); LIMIT 2 lets the caller distinguish 0/1/many.

func (*ResourceStore) GetByID

func (s *ResourceStore) GetByID(ctx context.Context, id string) (*resource.Resource, error)

GetByID returns the Resource with the given id.

func (*ResourceStore) GetBySlug

func (s *ResourceStore) GetBySlug(ctx context.Context, slug string) (*resource.Resource, error)

GetBySlug returns the Resource with the given slug.

func (*ResourceStore) List

List returns Resources matching the filter.

func (*ResourceStore) Resolve

func (s *ResourceStore) Resolve(ctx context.Context, slugOrURI string) ([]*resource.Resource, error)

Resolve implements the data model Q1.

func (*ResourceStore) Update

func (s *ResourceStore) Update(ctx context.Context, r *resource.Resource) error

Update replaces the Resource with id r.ID.

type RevocationStore

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

RevocationStore implements output.RevocationStore for PostgreSQL.

func (*RevocationStore) IsRevoked

func (s *RevocationStore) IsRevoked(ctx context.Context, jti string) (bool, error)

IsRevoked checks if a JTI is in the blacklist.

func (*RevocationStore) PurgeExpired

func (s *RevocationStore) PurgeExpired(ctx context.Context) (int64, error)

PurgeExpired removes expired JTI tracking and blacklist entries.

func (*RevocationStore) RevokeByFamily

func (s *RevocationStore) RevokeByFamily(ctx context.Context, familyID string) error

RevokeByFamily adds all JTIs belonging to a family to the blacklist.

func (*RevocationStore) RevokeJTI

func (s *RevocationStore) RevokeJTI(ctx context.Context, jti string) error

RevokeJTI adds a single JTI to the blacklist.

func (*RevocationStore) TrackJTI

func (s *RevocationStore) TrackJTI(ctx context.Context, jti, familyID string, expiresAt time.Time) error

TrackJTI records that a JTI was issued for a given family with its expiry.

type RuntimeSettingsStore

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

RuntimeSettingsStore implements output.RuntimeSettingsStore for PostgreSQL.

func (*RuntimeSettingsStore) Get

func (s *RuntimeSettingsStore) Get(ctx context.Context, key string) (string, error)

Get returns the value for a setting key. Returns "" if not found.

func (*RuntimeSettingsStore) Set

func (s *RuntimeSettingsStore) Set(ctx context.Context, key, value string) error

Set persists a setting key-value pair (upsert).

type SessionStore

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

SessionStore implements output.SessionStore using PostgreSQL.

func (*SessionStore) ConsumeByCodeHash

func (st *SessionStore) ConsumeByCodeHash(ctx context.Context, codeHash string) (*session.AuthSession, error)

ConsumeByCodeHash atomically marks the session as consumed using UPDATE...RETURNING. If already consumed, returns ErrCodeConsumed. If not found, returns ErrInvalidGrant.

func (*SessionStore) Create

func (st *SessionStore) Create(ctx context.Context, s *session.AuthSession) error

Create implements output.SessionStore.

func (*SessionStore) Delete

func (st *SessionStore) Delete(ctx context.Context, id string) error

Delete implements output.SessionStore.

func (*SessionStore) DeleteExpired

func (st *SessionStore) DeleteExpired(ctx context.Context) (int64, error)

DeleteExpired implements output.SessionStore.

func (*SessionStore) GetByID

func (st *SessionStore) GetByID(ctx context.Context, id string) (*session.AuthSession, error)

GetByID implements output.SessionStore.

func (*SessionStore) UpdateCodeHashAndScope

func (st *SessionStore) UpdateCodeHashAndScope(ctx context.Context, sessionID, codeHash, scope string) error

UpdateCodeHashAndScope implements output.SessionStore.

type Stores

type Stores struct {
	Client              *ClientStore
	User                *UserStore
	Session             *SessionStore
	Token               *TokenStore
	Audit               *AuditStore
	Revocation          *RevocationStore
	MachineToken        *MachineTokenStore
	DPoPNonce           *DPoPNonceStore
	RuntimeSettings     *RuntimeSettingsStore
	IDP                 *IDPStore
	AssertionJTI        *AssertionJTIStore
	XAAPolicy           *XAAPolicyStore
	SubjectMapping      *SubjectMappingStore
	Resource            *ResourceStore
	BrokerProvider      *BrokerProviderStore
	ConsentGrant        *ConsentGrantStore
	BrokerGrant         *BrokerGrantStore
	Issuance            *IssuanceStore
	ConnectPendingState *ConnectPendingStateStore
	FrontingLink        *FrontingLinkStore
	TransactionMgr      *TransactionManager
}

Stores groups all PostgreSQL store implementations.

type SubjectMappingStore

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

SubjectMappingStore implements output.SubjectMappingStore using PostgreSQL.

func (*SubjectMappingStore) Delete

func (s *SubjectMappingStore) Delete(ctx context.Context, id string) error

Delete implements output.SubjectMappingStore.

func (*SubjectMappingStore) GetMapping

func (s *SubjectMappingStore) GetMapping(ctx context.Context, idpID, idpSubject string) (*xaa.SubjectMapping, error)

GetMapping implements output.SubjectMappingStore.

func (*SubjectMappingStore) ListByIDP

func (s *SubjectMappingStore) ListByIDP(ctx context.Context, idpID string) ([]xaa.SubjectMapping, error)

ListByIDP implements output.SubjectMappingStore.

func (*SubjectMappingStore) Save

Save implements output.SubjectMappingStore.

type TokenStore

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

TokenStore implements output.TokenStore using PostgreSQL.

func (*TokenStore) ConsumeRefreshToken

func (s *TokenStore) ConsumeRefreshToken(ctx context.Context, id string) (*token.RefreshToken, error)

ConsumeRefreshToken atomically marks a refresh token as consumed using UPDATE...RETURNING. If already consumed, returns the token with ConsumedAt set (reuse signal). If not found, returns ErrInvalidGrant.

func (*TokenStore) CountActiveByClientID

func (s *TokenStore) CountActiveByClientID(ctx context.Context, clientID string) (int, error)

CountActiveByClientID returns the number of active families for a client.

func (*TokenStore) CountIssuedSince

func (s *TokenStore) CountIssuedSince(ctx context.Context, since int64) (int, error)

CountIssuedSince implements output.TokenStore.

func (*TokenStore) CountRevokedSince

func (s *TokenStore) CountRevokedSince(ctx context.Context, since int64) (int, error)

CountRevokedSince implements output.TokenStore.

func (*TokenStore) CreateFamily

func (s *TokenStore) CreateFamily(ctx context.Context, f *token.Family) error

CreateFamily implements output.TokenStore.

func (*TokenStore) CreateRefreshToken

func (s *TokenStore) CreateRefreshToken(ctx context.Context, rt *token.RefreshToken) error

CreateRefreshToken implements output.TokenStore.

func (*TokenStore) GetFamily

func (s *TokenStore) GetFamily(ctx context.Context, id string) (*token.Family, error)

GetFamily implements output.TokenStore.

func (*TokenStore) GetRefreshTokenByHash

func (s *TokenStore) GetRefreshTokenByHash(ctx context.Context, hash string) (*token.RefreshToken, error)

GetRefreshTokenByHash implements output.TokenStore.

func (*TokenStore) ListFamilies

func (s *TokenStore) ListFamilies(ctx context.Context, filter output.FamilyFilter) ([]token.Family, int, error)

ListFamilies returns token families matching the filter.

func (*TokenStore) PurgeExpired

func (s *TokenStore) PurgeExpired(ctx context.Context) (int64, error)

PurgeExpired removes refresh tokens whose expires_at is in the past. Both consumed and unconsumed expired rows are deleted: an expired refresh token is rejected by the refresh flow before any reuse check, so retaining it provides no security value.

func (*TokenStore) RevokeByClientID

func (s *TokenStore) RevokeByClientID(ctx context.Context, clientID string) (int, error)

RevokeByClientID revokes all active families for a client. Returns count revoked.

func (*TokenStore) RevokeByUserID

func (s *TokenStore) RevokeByUserID(ctx context.Context, userID string) (int, error)

RevokeByUserID revokes all active families for a user. Returns count revoked.

func (*TokenStore) RevokeFamily

func (s *TokenStore) RevokeFamily(ctx context.Context, familyID string) error

RevokeFamily atomically revokes a family and all its refresh tokens. Idempotent — already-revoked family is a no-op.

type TransactionManager

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

TransactionManager implements output.TransactionManager for PostgreSQL.

func (*TransactionManager) WithTransaction

func (tm *TransactionManager) WithTransaction(ctx context.Context, fn func(ctx context.Context) error) error

WithTransaction executes fn within a database transaction. If fn returns nil the transaction is committed; otherwise it is rolled back. Nested calls reuse the existing transaction (no savepoints).

type UserStore

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

UserStore implements output.UserStore using PostgreSQL.

func (*UserStore) Count

func (s *UserStore) Count(ctx context.Context) (int, error)

Count implements output.UserStore.

func (*UserStore) Create

func (s *UserStore) Create(ctx context.Context, u *user.User) error

Create implements output.UserStore.

func (*UserStore) Delete

func (s *UserStore) Delete(ctx context.Context, id string) error

Delete implements output.UserStore.

func (*UserStore) GetByEmail

func (s *UserStore) GetByEmail(ctx context.Context, email string) (*user.User, error)

GetByEmail implements output.UserStore.

func (*UserStore) GetByID

func (s *UserStore) GetByID(ctx context.Context, id string) (*user.User, error)

GetByID implements output.UserStore.

func (*UserStore) GetByProviderSub

func (s *UserStore) GetByProviderSub(ctx context.Context, provider user.Provider, sub string) (*user.User, error)

GetByProviderSub implements output.UserStore.

func (*UserStore) List

func (s *UserStore) List(ctx context.Context) ([]user.User, error)

List implements output.UserStore.

func (*UserStore) Update

func (s *UserStore) Update(ctx context.Context, u *user.User) error

Update implements output.UserStore.

type XAAPolicyStore

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

XAAPolicyStore implements output.XAAPolicyStore using PostgreSQL.

func (*XAAPolicyStore) Delete

func (s *XAAPolicyStore) Delete(ctx context.Context, id string) error

Delete implements output.XAAPolicyStore.

func (*XAAPolicyStore) GetByID

func (s *XAAPolicyStore) GetByID(ctx context.Context, id string) (*xaa.Policy, error)

GetByID implements output.XAAPolicyStore.

func (*XAAPolicyStore) List

func (s *XAAPolicyStore) List(ctx context.Context) ([]xaa.Policy, error)

List implements output.XAAPolicyStore.

func (*XAAPolicyStore) ListByIDP

func (s *XAAPolicyStore) ListByIDP(ctx context.Context, idpID string) ([]xaa.Policy, error)

ListByIDP implements output.XAAPolicyStore.

func (*XAAPolicyStore) Save

func (s *XAAPolicyStore) Save(ctx context.Context, p xaa.Policy) error

Save implements output.XAAPolicyStore.

Jump to

Keyboard shortcuts

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