Documentation
¶
Overview ¶
Package postgres provides PostgreSQL implementations of the output port interfaces.
Index ¶
- type AssertionJTIStore
- type AuditStore
- type BrokerGrantStore
- func (s *BrokerGrantStore) Create(ctx context.Context, g *resource.BrokerGrant) error
- func (s *BrokerGrantStore) Get(ctx context.Context, userID, brokerProviderID string) (*resource.BrokerGrant, error)
- func (s *BrokerGrantStore) GetByID(ctx context.Context, id string) (*resource.BrokerGrant, error)
- func (s *BrokerGrantStore) ListForUser(ctx context.Context, userID string) ([]*resource.BrokerGrant, error)
- func (s *BrokerGrantStore) Revoke(ctx context.Context, id string) error
- func (s *BrokerGrantStore) UpdateWithVersion(ctx context.Context, g *resource.BrokerGrant) error
- func (s *BrokerGrantStore) Upsert(ctx context.Context, g *resource.BrokerGrant) (*resource.BrokerGrant, error)
- type BrokerProviderStore
- func (s *BrokerProviderStore) Create(ctx context.Context, p *resource.BrokerProvider) error
- func (s *BrokerProviderStore) Delete(ctx context.Context, id string) error
- func (s *BrokerProviderStore) GetByID(ctx context.Context, id string) (*resource.BrokerProvider, error)
- func (s *BrokerProviderStore) GetBySlug(ctx context.Context, slug string) (*resource.BrokerProvider, error)
- func (s *BrokerProviderStore) List(ctx context.Context) ([]*resource.BrokerProvider, error)
- func (s *BrokerProviderStore) Update(ctx context.Context, p *resource.BrokerProvider) error
- type ClientStore
- func (s *ClientStore) Count(ctx context.Context, status string) (int, error)
- func (s *ClientStore) Create(ctx context.Context, c *client.Client) error
- func (s *ClientStore) Delete(ctx context.Context, id string) error
- func (s *ClientStore) GetByCIMDURL(ctx context.Context, url string) (*client.Client, error)
- func (s *ClientStore) GetByID(ctx context.Context, id string) (*client.Client, error)
- func (s *ClientStore) List(ctx context.Context, status, source string, limit, offset int) ([]client.Client, error)
- func (s *ClientStore) ListAgents(ctx context.Context) ([]client.Client, error)
- func (s *ClientStore) Update(ctx context.Context, c *client.Client) error
- type ConfigChangeListener
- type ConnectPendingStateStore
- func (s *ConnectPendingStateStore) Consume(ctx context.Context, id string) (*resource.ConnectPendingState, error)
- func (s *ConnectPendingStateStore) Insert(ctx context.Context, state *resource.ConnectPendingState) error
- func (s *ConnectPendingStateStore) PurgeExpired(ctx context.Context, before time.Time) (int, error)
- type ConsentGrantStore
- func (s *ConsentGrantStore) Get(ctx context.Context, userID, clientID, resourceID string) (*resource.ConsentGrant, error)
- func (s *ConsentGrantStore) GetByID(ctx context.Context, id string) (*resource.ConsentGrant, error)
- func (s *ConsentGrantStore) ListForUser(ctx context.Context, userID string) ([]*resource.ConsentGrant, error)
- func (s *ConsentGrantStore) Revoke(ctx context.Context, id string) error
- func (s *ConsentGrantStore) Upsert(ctx context.Context, g *resource.ConsentGrant) error
- type DB
- func (d *DB) AssertionJTI() output.AssertionJTIStore
- func (d *DB) Audit() output.AuditStore
- func (d *DB) BrokerGrant() output.BrokerGrantStore
- func (d *DB) BrokerProvider() output.BrokerProviderStore
- func (d *DB) Client() output.ClientStore
- func (d *DB) Close() error
- func (d *DB) ConnectPendingState() output.ConnectPendingStateStore
- func (d *DB) ConsentGrant() output.ConsentGrantStore
- func (d *DB) DPoPNonce() output.DPoPNonceStore
- func (d *DB) FrontingLink() output.FrontingLinkStore
- func (d *DB) IDP() output.IDPStore
- func (d *DB) Issuance() output.IssuanceStore
- func (d *DB) MachineToken() output.MachineTokenStore
- func (d *DB) Migrate(ctx context.Context) error
- func (d *DB) NewStores() *Stores
- func (d *DB) Ping(ctx context.Context) error
- func (d *DB) Resource() output.ResourceStore
- func (d *DB) Revocation() output.RevocationStore
- func (d *DB) RuntimeSettings() output.RuntimeSettingsStore
- func (d *DB) Session() output.SessionStore
- func (d *DB) SubjectMapping() output.SubjectMappingStore
- func (d *DB) Token() output.TokenStore
- func (d *DB) Transaction() output.TransactionManager
- func (d *DB) User() output.UserStore
- func (d *DB) XAAPolicy() output.XAAPolicyStore
- type DPoPNonceStore
- func (s *DPoPNonceStore) ConsumeJTI(ctx context.Context, jti string, expiry time.Time) error
- func (s *DPoPNonceStore) IssueNonce(ctx context.Context, ttl time.Duration) (string, error)
- func (s *DPoPNonceStore) PurgeExpired(ctx context.Context) error
- func (s *DPoPNonceStore) ValidateNonce(ctx context.Context, nonce string) error
- type FrontingLinkStore
- func (s *FrontingLinkStore) Create(ctx context.Context, link *resource.FrontingLink) error
- func (s *FrontingLinkStore) Delete(ctx context.Context, sourceSlug, targetSlug string) error
- func (s *FrontingLinkStore) DeleteForResource(ctx context.Context, slug string) (int, error)
- func (s *FrontingLinkStore) Get(ctx context.Context, sourceSlug, targetSlug string) (*resource.FrontingLink, error)
- func (s *FrontingLinkStore) List(ctx context.Context, filter output.FrontingLinkFilter) ([]*resource.FrontingLink, error)
- func (s *FrontingLinkStore) ListForResource(ctx context.Context, slug string) ([]*resource.FrontingLink, error)
- func (s *FrontingLinkStore) Update(ctx context.Context, link *resource.FrontingLink) error
- type HAKeyStore
- func (s *HAKeyStore) InvalidateCache()
- func (s *HAKeyStore) ListActive(ctx context.Context) ([]*output.SigningKey, error)
- func (s *HAKeyStore) LoadCurrent(ctx context.Context) (*output.SigningKey, error)
- func (s *HAKeyStore) LoadPrevious(ctx context.Context) (*output.SigningKey, error)
- func (s *HAKeyStore) Save(ctx context.Context, key *output.SigningKey) error
- type IDPStore
- func (s *IDPStore) Delete(ctx context.Context, id string) error
- func (s *IDPStore) GetByID(ctx context.Context, id string) (*idp.TrustedIDP, error)
- func (s *IDPStore) GetByIssuer(ctx context.Context, issuer string) (*idp.TrustedIDP, error)
- func (s *IDPStore) List(ctx context.Context) ([]idp.TrustedIDP, error)
- func (s *IDPStore) Save(ctx context.Context, i idp.TrustedIDP) error
- type IssuanceStore
- func (s *IssuanceStore) GetByID(ctx context.Context, id string) (*resource.Issuance, error)
- func (s *IssuanceStore) GetByJTI(ctx context.Context, jti string) (*resource.Issuance, error)
- func (s *IssuanceStore) Insert(ctx context.Context, i *resource.Issuance) error
- func (s *IssuanceStore) ListForActor(ctx context.Context, clientID string, since time.Time) ([]*resource.Issuance, error)
- func (s *IssuanceStore) ListForResource(ctx context.Context, resourceID string, since time.Time) ([]*resource.Issuance, error)
- func (s *IssuanceStore) ListForUser(ctx context.Context, userID string, since time.Time) ([]*resource.Issuance, error)
- func (s *IssuanceStore) PurgeExpired(ctx context.Context, before time.Time) (int, error)
- func (s *IssuanceStore) Revoke(ctx context.Context, id string) error
- func (s *IssuanceStore) RevokeFamily(ctx context.Context, userID, clientID, resourceID string) (int, error)
- type KeyStoreListener
- type MachineTokenStore
- func (s *MachineTokenStore) CountIssuedSince(ctx context.Context, since int64) (int, error)
- func (s *MachineTokenStore) CountRevokedSince(ctx context.Context, since int64) (int, error)
- func (s *MachineTokenStore) GetByJTI(ctx context.Context, jti string) (*token.MachineToken, error)
- func (s *MachineTokenStore) List(ctx context.Context, filter output.MachineTokenFilter) ([]token.MachineToken, int, error)
- func (s *MachineTokenStore) PurgeExpired(ctx context.Context) error
- func (s *MachineTokenStore) Revoke(ctx context.Context, jti string) error
- func (s *MachineTokenStore) RevokeByClientID(ctx context.Context, clientID string) (int, error)
- func (s *MachineTokenStore) Save(ctx context.Context, mt token.MachineToken) error
- type PoolConfig
- type ResourceStore
- func (s *ResourceStore) Create(ctx context.Context, r *resource.Resource) error
- func (s *ResourceStore) Delete(ctx context.Context, id string) error
- func (s *ResourceStore) FindByRuntimeClientID(ctx context.Context, clientID string) (*resource.Resource, error)
- func (s *ResourceStore) GetByID(ctx context.Context, id string) (*resource.Resource, error)
- func (s *ResourceStore) GetBySlug(ctx context.Context, slug string) (*resource.Resource, error)
- func (s *ResourceStore) List(ctx context.Context, filter output.ResourceFilter) ([]*resource.Resource, error)
- func (s *ResourceStore) Resolve(ctx context.Context, slugOrURI string) ([]*resource.Resource, error)
- func (s *ResourceStore) Update(ctx context.Context, r *resource.Resource) error
- type RevocationStore
- func (s *RevocationStore) IsRevoked(ctx context.Context, jti string) (bool, error)
- func (s *RevocationStore) PurgeExpired(ctx context.Context) (int64, error)
- func (s *RevocationStore) RevokeByFamily(ctx context.Context, familyID string) error
- func (s *RevocationStore) RevokeJTI(ctx context.Context, jti string) error
- func (s *RevocationStore) TrackJTI(ctx context.Context, jti, familyID string, expiresAt time.Time) error
- type RuntimeSettingsStore
- type SessionStore
- func (st *SessionStore) ConsumeByCodeHash(ctx context.Context, codeHash string) (*session.AuthSession, error)
- func (st *SessionStore) Create(ctx context.Context, s *session.AuthSession) error
- func (st *SessionStore) Delete(ctx context.Context, id string) error
- func (st *SessionStore) DeleteExpired(ctx context.Context) (int64, error)
- func (st *SessionStore) GetByID(ctx context.Context, id string) (*session.AuthSession, error)
- func (st *SessionStore) UpdateCodeHashAndScope(ctx context.Context, sessionID, codeHash, scope string) error
- type Stores
- type SubjectMappingStore
- func (s *SubjectMappingStore) Delete(ctx context.Context, id string) error
- func (s *SubjectMappingStore) GetMapping(ctx context.Context, idpID, idpSubject string) (*xaa.SubjectMapping, error)
- func (s *SubjectMappingStore) ListByIDP(ctx context.Context, idpID string) ([]xaa.SubjectMapping, error)
- func (s *SubjectMappingStore) Save(ctx context.Context, m xaa.SubjectMapping) error
- type TokenStore
- func (s *TokenStore) ConsumeRefreshToken(ctx context.Context, id string) (*token.RefreshToken, error)
- func (s *TokenStore) CountActiveByClientID(ctx context.Context, clientID string) (int, error)
- func (s *TokenStore) CountIssuedSince(ctx context.Context, since int64) (int, error)
- func (s *TokenStore) CountRevokedSince(ctx context.Context, since int64) (int, error)
- func (s *TokenStore) CreateFamily(ctx context.Context, f *token.Family) error
- func (s *TokenStore) CreateRefreshToken(ctx context.Context, rt *token.RefreshToken) error
- func (s *TokenStore) GetFamily(ctx context.Context, id string) (*token.Family, error)
- func (s *TokenStore) GetRefreshTokenByHash(ctx context.Context, hash string) (*token.RefreshToken, error)
- func (s *TokenStore) ListFamilies(ctx context.Context, filter output.FamilyFilter) ([]token.Family, int, error)
- func (s *TokenStore) PurgeExpired(ctx context.Context) (int64, error)
- func (s *TokenStore) RevokeByClientID(ctx context.Context, clientID string) (int, error)
- func (s *TokenStore) RevokeByUserID(ctx context.Context, userID string) (int, error)
- func (s *TokenStore) RevokeFamily(ctx context.Context, familyID string) error
- type TransactionManager
- type UserStore
- func (s *UserStore) Count(ctx context.Context) (int, error)
- func (s *UserStore) Create(ctx context.Context, u *user.User) error
- func (s *UserStore) Delete(ctx context.Context, id string) error
- func (s *UserStore) GetByEmail(ctx context.Context, email string) (*user.User, error)
- func (s *UserStore) GetByID(ctx context.Context, id string) (*user.User, error)
- func (s *UserStore) GetByProviderSub(ctx context.Context, provider user.Provider, sub string) (*user.User, error)
- func (s *UserStore) List(ctx context.Context) ([]user.User, error)
- func (s *UserStore) Update(ctx context.Context, u *user.User) error
- type XAAPolicyStore
- func (s *XAAPolicyStore) Delete(ctx context.Context, id string) error
- func (s *XAAPolicyStore) GetByID(ctx context.Context, id string) (*xaa.Policy, error)
- func (s *XAAPolicyStore) List(ctx context.Context) ([]xaa.Policy, error)
- func (s *XAAPolicyStore) ListByIDP(ctx context.Context, idpID string) ([]xaa.Policy, error)
- func (s *XAAPolicyStore) Save(ctx context.Context, p xaa.Policy) error
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 ¶
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.
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 ¶
func (s *BrokerGrantStore) Create(ctx context.Context, g *resource.BrokerGrant) error
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 ¶
func (s *BrokerGrantStore) GetByID(ctx context.Context, id string) (*resource.BrokerGrant, error)
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 ¶
func (s *BrokerGrantStore) Upsert(ctx context.Context, g *resource.BrokerGrant) (*resource.BrokerGrant, error)
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 ¶
func (s *BrokerProviderStore) Create(ctx context.Context, p *resource.BrokerProvider) error
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 ¶
func (s *BrokerProviderStore) GetByID(ctx context.Context, id string) (*resource.BrokerProvider, error)
GetByID returns the BrokerProvider with the given id.
func (*BrokerProviderStore) GetBySlug ¶
func (s *BrokerProviderStore) GetBySlug(ctx context.Context, slug string) (*resource.BrokerProvider, error)
GetBySlug returns the BrokerProvider with the given slug.
func (*BrokerProviderStore) List ¶
func (s *BrokerProviderStore) List(ctx context.Context) ([]*resource.BrokerProvider, error)
List returns all providers ordered by slug.
func (*BrokerProviderStore) Update ¶
func (s *BrokerProviderStore) Update(ctx context.Context, p *resource.BrokerProvider) error
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) Delete ¶
func (s *ClientStore) Delete(ctx context.Context, id string) error
Delete implements output.ClientStore.
func (*ClientStore) GetByCIMDURL ¶
GetByCIMDURL 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 ¶
ListAgents 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).
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 ¶
func (s *ConnectPendingStateStore) Consume(ctx context.Context, id string) (*resource.ConnectPendingState, error)
Consume atomically reads + deletes the row using DELETE ... RETURNING. Single-use: a second Consume on the same id returns domain.ErrPendingStateNotFound.
func (*ConnectPendingStateStore) Insert ¶
func (s *ConnectPendingStateStore) Insert(ctx context.Context, state *resource.ConnectPendingState) error
Insert persists a new pending-state row.
func (*ConnectPendingStateStore) PurgeExpired ¶
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 ¶
func (s *ConsentGrantStore) GetByID(ctx context.Context, id string) (*resource.ConsentGrant, error)
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 ¶
func (s *ConsentGrantStore) Upsert(ctx context.Context, g *resource.ConsentGrant) error
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 ¶
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) 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) 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 (*DB) FrontingLink ¶
func (d *DB) FrontingLink() output.FrontingLinkStore
FrontingLink returns the FrontingLinkStore.
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) 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) SubjectMapping ¶
func (d *DB) SubjectMapping() output.SubjectMappingStore
SubjectMapping returns the subject mapping store.
func (*DB) Transaction ¶
func (d *DB) Transaction() output.TransactionManager
Transaction returns the transaction manager.
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 ¶
ConsumeJTI records a DPoP proof JTI. Returns domain.ErrDPoPReplay if already consumed.
func (*DPoPNonceStore) IssueNonce ¶
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 ¶
func (s *FrontingLinkStore) Create(ctx context.Context, link *resource.FrontingLink) error
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 ¶
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 ¶
func (s *FrontingLinkStore) List(ctx context.Context, filter output.FrontingLinkFilter) ([]*resource.FrontingLink, error)
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 ¶
func (s *FrontingLinkStore) Update(ctx context.Context, link *resource.FrontingLink) error
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:
- Demote the current key (is_current = FALSE)
- Encrypt and INSERT the new key with is_current = TRUE
- 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) GetByIssuer ¶
GetByIssuer 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 ¶
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) 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 ¶
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).
type MachineTokenStore ¶
type MachineTokenStore struct {
// contains filtered or unexported fields
}
MachineTokenStore implements output.MachineTokenStore using PostgreSQL.
func (*MachineTokenStore) CountIssuedSince ¶
CountIssuedSince returns the number of machine tokens issued since the given unix timestamp.
func (*MachineTokenStore) CountRevokedSince ¶
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 ¶
func (s *MachineTokenStore) List(ctx context.Context, filter output.MachineTokenFilter) ([]token.MachineToken, int, error)
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 ¶
RevokeByClientID revokes all active machine tokens for a client.
func (*MachineTokenStore) Save ¶
func (s *MachineTokenStore) Save(ctx context.Context, mt token.MachineToken) error
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) 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) List ¶
func (s *ResourceStore) List(ctx context.Context, filter output.ResourceFilter) ([]*resource.Resource, error)
List returns Resources matching the filter.
type RevocationStore ¶
type RevocationStore struct {
// contains filtered or unexported fields
}
RevocationStore implements output.RevocationStore for PostgreSQL.
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.
type RuntimeSettingsStore ¶
type RuntimeSettingsStore struct {
// contains filtered or unexported fields
}
RuntimeSettingsStore implements output.RuntimeSettingsStore for PostgreSQL.
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 ¶
func (s *SubjectMappingStore) Save(ctx context.Context, m xaa.SubjectMapping) error
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 ¶
CountActiveByClientID returns the number of active families for a client.
func (*TokenStore) CountIssuedSince ¶
CountIssuedSince implements output.TokenStore.
func (*TokenStore) CountRevokedSince ¶
CountRevokedSince implements output.TokenStore.
func (*TokenStore) CreateFamily ¶
CreateFamily implements output.TokenStore.
func (*TokenStore) CreateRefreshToken ¶
func (s *TokenStore) CreateRefreshToken(ctx context.Context, rt *token.RefreshToken) error
CreateRefreshToken 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 ¶
RevokeByClientID revokes all active families for a client. Returns count revoked.
func (*TokenStore) RevokeByUserID ¶
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) GetByEmail ¶
GetByEmail 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.
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.
Source Files
¶
- assertion_jti_store.go
- audit.go
- broker_grant_store.go
- broker_provider_store.go
- client.go
- config_listener.go
- connect_pending_state_store.go
- consent_grant_store.go
- db.go
- dpop_nonce.go
- fronting_link_store.go
- hakeystore.go
- hakeystore_listener.go
- idp_store.go
- issuance_store.go
- machine_token.go
- resource_store.go
- revocation.go
- session.go
- settings.go
- subject_mapping_store.go
- token.go
- transaction.go
- user.go
- xaa_policy_store.go