Documentation
¶
Overview ¶
Package identity is the canonical per-domain Store over the generated sqlc surface (D-A2-01). It is built FIRST in Phase 4 to prove the Store pattern (Store{pool,q} + SQLSTATE error classification + db_integration discipline) that conversations/askuser copy verbatim. Scope is the single-user `local` identity scaffolding (Slice 1.7): identity CRUD plus capability grant/revoke with wildcard-or-exact HasCapability semantics.
No interface is declared here — the consumer (the Runner) declares the narrow interface it needs (D-A2-02, "accept interfaces, return structs").
Index ¶
- Constants
- Variables
- type Identity
- type Store
- func (s *Store) DeleteIdentity(ctx context.Context, name string) error
- func (s *Store) GetIdentityByID(ctx context.Context, identityID string) (Identity, error)
- func (s *Store) GetIdentityByName(ctx context.Context, name string) (Identity, error)
- func (s *Store) GrantCapability(ctx context.Context, identityID, capability string) error
- func (s *Store) HasCapability(ctx context.Context, identityID, capability string) (bool, error)
- func (s *Store) ListIdentities(ctx context.Context) ([]Identity, error)
- func (s *Store) RevokeCapability(ctx context.Context, identityID, capability string) error
Constants ¶
const Wildcard = "*"
Wildcard is the system-managed match-all capability. It is seeded by migration 0004 on the `local` identity and is NEVER granted or revoked through the Store or CLI — HasCapability treats it as "has every capability".
Variables ¶
var ( ErrWildcardManaged = errors.New("wildcard '*' is system-managed and cannot be granted or revoked") ErrInvalidCapability = errors.New("invalid capability name") ErrIdentityNotFound = errors.New("identity not found") )
Sentinel errors so callers (CLI, tests) classify failures without string matching. ErrWildcardManaged is the "wildcard is system-managed" rejection; ErrInvalidCapability is the name-grammar failure; ErrIdentityNotFound is a missing identity lookup.
Functions ¶
This section is empty.
Types ¶
type Identity ¶
Identity is the domain projection of aura.identities — plain Go types at the package boundary instead of the sqlc pgtype wrappers.
type Store ¶
type Store struct {
// contains filtered or unexported fields
}
Store wraps a pgx pool and the generated Queries. The canonical shape every future DB slice copies (D-A2-01): non-tx reads use s.q; atomic multi-statement writes wrap db.WithTx (none needed in identity — it is single-statement only).
func New ¶
New builds a Store over an open pool. sqlc.New(pool) binds the Queries to the pool's DBTX; mirrors the construction in internal/db/tx.go.
func (*Store) DeleteIdentity ¶
DeleteIdentity removes an identity by name. Its capability_grants cascade away via the FK ON DELETE CASCADE (verified by the integration test). Deleting an absent identity is a no-op (DELETE affects zero rows, no error).
func (*Store) GetIdentityByID ¶
GetIdentityByID fetches one identity by UUID. A missing row is reported as ErrIdentityNotFound (wrapped) rather than the raw pgx.ErrNoRows.
func (*Store) GetIdentityByName ¶
GetIdentityByName fetches one identity by its unique name. A missing row is reported as ErrIdentityNotFound (wrapped) rather than the raw pgx.ErrNoRows.
func (*Store) GrantCapability ¶
GrantCapability grants an ordinary capability to an identity, idempotently: the underlying INSERT uses ON CONFLICT DO NOTHING, and a 23505 unique_violation (belt-and-suspenders) is swallowed so a repeat grant is a no-op, never an error. Granting '*' is rejected before any DB call (ErrWildcardManaged), and names failing the grammar are rejected (ErrInvalidCapability).
func (*Store) HasCapability ¶
HasCapability reports whether the identity holds either the '*' wildcard or the exact capability. The generated query does the wildcard-or-exact match in SQL; only a real DB failure returns a non-nil error.
func (*Store) ListIdentities ¶
ListIdentities returns every identity ordered by creation then name.
func (*Store) RevokeCapability ¶
RevokeCapability revokes a capability from an identity, idempotently: revoking an absent capability affects zero rows and returns no error. Revoking '*' is rejected before any DB call (ErrWildcardManaged); names failing the grammar are rejected (ErrInvalidCapability).