{"modulePath":"github.com/bitechdev/ResolveSpec","version":"v1.3.14","isLatest":true,"isStandardLibrary":false,"goos":"all","goarch":"all","docs":"# package direct\n\nPackage direct is the table-backed implementation of the lookup stores. SQL is built from the configured Schema (table and column names) and Dialect (placeholders, quoting, booleans, insert-returning-id); no statement is written per database and no ORM is used.\n\n## Functions\n\n```go\nfunc BurnPasswordCheck(supplied string)\n```\nBurnPasswordCheck spends roughly one bcrypt comparison so an unknown username costs about the same as a wrong password.\n\n```go\nfunc GenerateSessionToken() (string, error)\n```\nGenerateSessionToken returns \"sess\\_\\\u003c64 hex\u003e\\_\\\u003cunix\u003e\".\n\n```go\nfunc HashPassword(password string) (string, error)\n```\nHashPassword returns the bcrypt hash of password.\n\n```go\nfunc ParseRoles(s string) []string\n```\nParseRoles splits the comma-separated roles column.\n\n```go\nfunc VerifyPassword(stored, supplied string) (ok, needsRehash bool)\n```\nVerifyPassword checks supplied against the stored value. A stored bcrypt hash is compared with bcrypt. A legacy cleartext value (written before hashing was implemented) is compared in constant time and, on a match, needsRehash is true so the caller can upgrade the row. An empty stored value (e.g. an OAuth2-only user) never matches.\n\n## Types\n\n```go\ntype Assignment struct {\n\tCol lookup.Column\n\tVal any\n}\n```\nAssignment is one \\`col = value\\` of an UPDATE or INSERT.\n\n```go\nfunc Set(c lookup.Column, v any) Assignment\n```\nSet builds an Assignment.\n\n```go\ntype Auth struct {\n\t*Base\n\t// contains filtered or unexported fields\n}\n```\nAuth implements lookup.AuthStore on the tables. Passwords are verified with bcrypt; legacy cleartext rows are accepted at login and only rewritten when UpgradePasswordHash is set. Registration never honours client-supplied user\\_level or roles. Multi-step writes (login, register, refresh, reset) run in one transaction.\n\n```go\nfunc NewAuth(b *Base, opts AuthOptions) *Auth\n```\nNewAuth creates the direct AuthStore.\n\n```go\nfunc (a *Auth) JWTLogin(ctx context.Context, req sectypes.LoginRequest) (*sectypes.LoginResponse, error)\n```\nJWTLogin implements lookup.AuthStore (mirrors resolvespec\\_jwt\\_login). The token is a placeholder until JWT signing is wired in.\n\n```go\nfunc (a *Auth) JWTLogout(ctx context.Context, req sectypes.LogoutRequest) error\n```\nJWTLogout implements lookup.AuthStore: the token goes on the blacklist.\n\n```go\nfunc (a *Auth) Login(ctx context.Context, req sectypes.LoginRequest) (*sectypes.LoginResponse, error)\n```\nLogin implements lookup.AuthStore.\n\n```go\nfunc (a *Auth) LoginAPIKey(ctx context.Context, rawKey string, claims map[string]any) (*sectypes.LoginResponse, error)\n```\nLoginAPIKey implements lookup.AuthStore. Unknown, expired, inactive and wrong-type keys (and inactive users) all return lookup.ErrInvalidAPIKey; the raw key is never logged.\n\n```go\nfunc (a *Auth) Logout(ctx context.Context, req sectypes.LogoutRequest) error\n```\nLogout implements lookup.AuthStore.\n\n```go\nfunc (a *Auth) Refresh(ctx context.Context, oldToken string) (*sectypes.LoginResponse, error)\n```\nRefresh implements lookup.AuthStore: the old session is replaced by a new one.\n\n```go\nfunc (a *Auth) Register(ctx context.Context, req sectypes.RegisterRequest) (*sectypes.LoginResponse, error)\n```\nRegister implements lookup.AuthStore.\n\n```go\nfunc (a *Auth) ResetComplete(ctx context.Context, req sectypes.PasswordResetCompleteRequest) error\n```\nResetComplete implements lookup.AuthStore: sets the new password, ends every session of the user and consumes the reset token, atomically.\n\n```go\nfunc (a *Auth) ResetRequest(ctx context.Context, req sectypes.PasswordResetRequest) (*sectypes.PasswordResetResponse, error)\n```\nResetRequest implements lookup.AuthStore. An unknown user yields a generic empty success so accounts cannot be enumerated.\n\n```go\nfunc (a *Auth) Session(ctx context.Context, token, _ string) (*sectypes.UserContext, error)\n```\nSession implements lookup.AuthStore. reference is only meaningful to the procedure backend.\n\n```go\nfunc (a *Auth) TouchSession(ctx context.Context, token string, _ *sectypes.UserContext) error\n```\nTouchSession implements lookup.AuthStore.\n\n```go\ntype AuthOptions struct {\n\t// UpgradePasswordHash rewrites legacy cleartext passwords as bcrypt on a successful login.\n\tUpgradePasswordHash bool\n}\n```\nAuthOptions tunes Auth.\n\n```go\ntype Base struct {\n\n\t// Now is the clock; tests replace it.\n\tNow func() time.Time\n\t// contains filtered or unexported fields\n}\n```\nBase is the state shared by every direct store: the runner, dialect, schema and clock.\n\n```go\nfunc NewBase(run Runner, d dialect.Dialect, schema lookup.Schema) (*Base, error)\n```\nNewBase creates the shared state. The schema is merged with the defaults and validated.\n\n```go\nfunc (b *Base) Delete(e lookup.Entity) *Delete\n```\nDelete starts a DELETE on e.\n\n```go\nfunc (b *Base) Dialect() dialect.Dialect\n```\nDialect returns the dialect in use.\n\n```go\nfunc (b *Base) From(e lookup.Entity) *Select\n```\nFrom starts a SELECT on e.\n\n```go\nfunc (b *Base) Insert(e lookup.Entity) *Insert\n```\nInsert starts an INSERT into e.\n\n```go\nfunc (b *Base) Update(e lookup.Entity) *Update\n```\nUpdate starts an UPDATE of e.\n\n```go\ntype Cond func(*builder) string\n```\nCond renders one boolean condition.\n\n```go\nfunc And(cs ...Cond) Cond\n```\nAnd joins conditions with AND inside parentheses.\n\n```go\nfunc Eq(c lookup.Column, v any) Cond\n```\nEq is \\`col = value\\`.\n\n```go\nfunc EqCol(a, c lookup.Column) Cond\n```\nEqCol is \\`a = b\\` between two columns (join conditions).\n\n```go\nfunc EqFold(c lookup.Column, v string) Cond\n```\nEqFold is a case-insensitive \\`LOWER(col) = value\\` match (the value is lowered in Go).\n\n```go\nfunc Gt(c lookup.Column, v any) Cond\n```\nGt is \\`col \u003e value\\`.\n\n```go\nfunc In(c lookup.Column, vs ...any) Cond\n```\nIn is \\`col IN (v...)\\`; an empty list renders a condition that is never true.\n\n```go\nfunc InSelect(c lookup.Column, sub *Select) Cond\n```\nInSelect is \\`col IN (subselect)\\`; the subselect's arguments share the outer numbering.\n\n```go\nfunc IsNull(c lookup.Column) Cond\n```\nIsNull is \\`col IS NULL\\`.\n\n```go\nfunc Lt(c lookup.Column, v any) Cond\n```\nLt is \\`col \\\u003c value\\`.\n\n```go\nfunc Ne(c lookup.Column, v any) Cond\n```\nNe is \\`col \\\u003c\u003e value\\`.\n\n```go\nfunc Or(cs ...Cond) Cond\n```\nOr joins conditions with OR inside parentheses.\n\n```go\ntype Delete struct {\n\t// contains filtered or unexported fields\n}\n```\nDelete builds a DELETE.\n\n```go\nfunc (d *Delete) Exec(ctx context.Context, q Querier) (int64, error)\n```\nExec runs the delete and returns the affected row count.\n\n```go\nfunc (d *Delete) Where(cs ...Cond) *Delete\n```\nWhere adds AND-ed conditions.\n\n```go\ntype Insert struct {\n\t// contains filtered or unexported fields\n}\n```\nInsert builds an INSERT.\n\n```go\nfunc (i *Insert) Exec(ctx context.Context, q Querier) error\n```\nExec runs the insert.\n\n```go\nfunc (i *Insert) ExecID(ctx context.Context, q Querier, idCol lookup.Column) (int64, error)\n```\nExecID runs the insert and returns the generated value of idCol, using the dialect's insert-returning-id strategy.\n\n```go\nfunc (i *Insert) Set(as ...Assignment) *Insert\n```\nSet adds assignments.\n\n```go\ntype Keys struct{ *Base }\n```\nKeys implements lookup.KeyStore on the user keys table. scopes and meta are stored as JSON through the dialect (native JSON column or TEXT).\n\n```go\nfunc NewKeys(b *Base) *Keys\n```\nNewKeys creates the direct KeyStore.\n\n```go\nfunc (k *Keys) Create(ctx context.Context, req sectypes.CreateKeyRequest, keyHash string) (*sectypes.UserKey, error)\n```\nCreate implements lookup.KeyStore.\n\n```go\nfunc (k *Keys) Delete(ctx context.Context, userID int, keyID int64) (string, error)\n```\nDelete implements lookup.KeyStore: soft-deletes the key after checking ownership and returns its hash.\n\n```go\nfunc (k *Keys) List(ctx context.Context, userID int, keyType sectypes.KeyType) ([]sectypes.UserKey, error)\n```\nList implements lookup.KeyStore: active, non-expired keys; an empty keyType means all types.\n\n```go\nfunc (k *Keys) Validate(ctx context.Context, keyHash string, keyType sectypes.KeyType) (*sectypes.UserKey, error)\n```\nValidate implements lookup.KeyStore: finds an active, non-expired key by hash (optionally of one type) and stamps last\\_used\\_at.\n\n```go\ntype OAuthClients struct{ *Base }\n```\nOAuthClients implements lookup.OAuthClientStore. Array columns (redirect\\_uris, grant\\_types, allowed\\_scopes, scopes) are JSON through the dialect.\n\n```go\nfunc NewOAuthClients(b *Base) *OAuthClients\n```\nNewOAuthClients creates the direct OAuthClientStore.\n\n```go\nfunc (o *OAuthClients) DeleteClient(ctx context.Context, clientID string) error\n```\nDeleteClient implements lookup.OAuthClientStore: the client is deactivated.\n\n```go\nfunc (o *OAuthClients) ExchangeCode(ctx context.Context, code string) (*sectypes.OAuthCode, error)\n```\nExchangeCode implements lookup.OAuthClientStore: the code is consumed in a transaction and only the caller whose delete removes the row gets it, so a code cannot be redeemed twice.\n\n```go\nfunc (o *OAuthClients) GetClient(ctx context.Context, clientID string) (*sectypes.OAuthServerClient, error)\n```\nGetClient implements lookup.OAuthClientStore.\n\n```go\nfunc (o *OAuthClients) Introspect(ctx context.Context, token string) (*sectypes.OAuthTokenInfo, error)\n```\nIntrospect implements lookup.OAuthClientStore (RFC 7662). An unknown or expired token is {active:false}, not an error.\n\n```go\nfunc (o *OAuthClients) RegisterClient(ctx context.Context, client *sectypes.OAuthServerClient) (*sectypes.OAuthServerClient, error)\n```\nRegisterClient implements lookup.OAuthClientStore.\n\n```go\nfunc (o *OAuthClients) Revoke(ctx context.Context, token string) error\n```\nRevoke implements lookup.OAuthClientStore (RFC 7009): the session is deleted; an unknown token is not an error.\n\n```go\nfunc (o *OAuthClients) SaveCode(ctx context.Context, code *sectypes.OAuthCode) error\n```\nSaveCode implements lookup.OAuthClientStore.\n\n```go\nfunc (o *OAuthClients) UpdateClient(ctx context.Context, client *sectypes.OAuthServerClient) error\n```\nUpdateClient implements lookup.OAuthClientStore: it rewrites the mutable registration fields of an existing client (RFC 7592 management).\n\n```go\ntype OAuthGrants struct{ *Base }\n```\nOAuthGrants implements lookup.OAuthGrantStore on tables. Every multi-step operation runs in one transaction, and single-use records (refresh rotation, device codes, pushed requests) are consumed with a conditional write so concurrent callers cannot both succeed.\n\n```go\nfunc NewOAuthGrants(b *Base) *OAuthGrants\n```\nNewOAuthGrants creates the direct OAuthGrantStore.\n\n```go\nfunc (o *OAuthGrants) ConsumePushedRequest(ctx context.Context, requestURI string) (*lookup.PushedRequest, error)\n```\nConsumePushedRequest implements lookup.OAuthGrantStore.\n\n```go\nfunc (o *OAuthGrants) CreateDevice(ctx context.Context, d lookup.DeviceCode) error\n```\nCreateDevice implements lookup.OAuthGrantStore.\n\n```go\nfunc (o *OAuthGrants) DeviceByUserCode(ctx context.Context, userCode string) (*lookup.DeviceCode, error)\n```\nDeviceByUserCode implements lookup.OAuthGrantStore.\n\n```go\nfunc (o *OAuthGrants) DeviceDecide(ctx context.Context, userCode string, approve bool, userID int, sessionToken string) error\n```\nDeviceDecide implements lookup.OAuthGrantStore.\n\n```go\nfunc (o *OAuthGrants) DevicePoll(ctx context.Context, deviceHash string) (*lookup.DeviceCode, error)\n```\nDevicePoll implements lookup.OAuthGrantStore.\n\n```go\nfunc (o *OAuthGrants) GetConsent(ctx context.Context, userID int, clientID string) (*lookup.Consent, error)\n```\nGetConsent implements lookup.OAuthGrantStore.\n\n```go\nfunc (o *OAuthGrants) PeekRefresh(ctx context.Context, hash string) (*lookup.RefreshToken, error)\n```\nPeekRefresh implements lookup.OAuthGrantStore.\n\n```go\nfunc (o *OAuthGrants) RevokeConsent(ctx context.Context, userID int, clientID string) error\n```\nRevokeConsent implements lookup.OAuthGrantStore.\n\n```go\nfunc (o *OAuthGrants) RevokeRefreshBySession(ctx context.Context, sessionToken string) error\n```\nRevokeRefreshBySession implements lookup.OAuthGrantStore.\n\n```go\nfunc (o *OAuthGrants) RevokeRefreshFamily(ctx context.Context, familyID string) error\n```\nRevokeRefreshFamily implements lookup.OAuthGrantStore.\n\n```go\nfunc (o *OAuthGrants) RotateRefresh(ctx context.Context, oldHash string, next lookup.RefreshToken) (*lookup.RefreshToken, error)\n```\nRotateRefresh implements lookup.OAuthGrantStore.\n\n```go\nfunc (o *OAuthGrants) SaveConsent(ctx context.Context, c lookup.Consent) error\n```\nSaveConsent implements lookup.OAuthGrantStore.\n\n```go\nfunc (o *OAuthGrants) SavePushedRequest(ctx context.Context, r lookup.PushedRequest) error\n```\nSavePushedRequest implements lookup.OAuthGrantStore.\n\n```go\nfunc (o *OAuthGrants) SaveRefresh(ctx context.Context, t lookup.RefreshToken) error\n```\nSaveRefresh implements lookup.OAuthGrantStore.\n\n```go\nfunc (o *OAuthGrants) SeenJTI(ctx context.Context, key string, expires time.Time) (bool, error)\n```\nSeenJTI implements lookup.OAuthGrantStore.\n\n```go\ntype OAuthUsers struct{ *Base }\n```\nOAuthUsers implements lookup.OAuthUserStore.\n\n```go\nfunc NewOAuthUsers(b *Base) *OAuthUsers\n```\nNewOAuthUsers creates the direct OAuthUserStore.\n\n```go\nfunc (o *OAuthUsers) CreateSession(ctx context.Context, s lookup.OAuthSession) error\n```\nCreateSession implements lookup.OAuthUserStore: insert, or update when the token exists.\n\n```go\nfunc (o *OAuthUsers) GetByRefreshToken(ctx context.Context, refreshToken string) (*lookup.OAuthRefreshSession, error)\n```\nGetByRefreshToken implements lookup.OAuthUserStore.\n\n```go\nfunc (o *OAuthUsers) GetOrCreateUser(ctx context.Context, user *sectypes.UserContext, provider string) (int, error)\n```\nGetOrCreateUser implements lookup.OAuthUserStore: select by email, then update or insert, in one transaction (no upsert).\n\n```go\nfunc (o *OAuthUsers) GetUser(ctx context.Context, userID int) (*sectypes.UserContext, error)\n```\nGetUser implements lookup.OAuthUserStore.\n\n```go\nfunc (o *OAuthUsers) UpdateRefreshToken(ctx context.Context, userID int, oldRefreshToken, newSessionToken, newAccessToken, newRefreshToken string, expiresAt time.Time) error\n```\nUpdateRefreshToken implements lookup.OAuthUserStore.\n\n```go\ntype Passkey struct{ *Base }\n```\nPasskey implements lookup.PasskeyStore. credential\\_id, public\\_key and aaguid are base64 TEXT (not native bytea) and transports is JSON, so one schema works on every dialect.\n\n```go\nfunc NewPasskey(b *Base) *Passkey\n```\nNewPasskey creates the direct PasskeyStore.\n\n```go\nfunc (p *Passkey) ByUsername(ctx context.Context, username string) (int, []lookup.PasskeyCredentialRef, error)\n```\nByUsername implements lookup.PasskeyStore.\n\n```go\nfunc (p *Passkey) Delete(ctx context.Context, userID int, credentialID string) error\n```\nDelete implements lookup.PasskeyStore.\n\n```go\nfunc (p *Passkey) Get(ctx context.Context, credentialID string) (userID int, signCount uint32, err error)\n```\nGet implements lookup.PasskeyStore.\n\n```go\nfunc (p *Passkey) List(ctx context.Context, userID int) ([]sectypes.PasskeyCredential, error)\n```\nList implements lookup.PasskeyStore, newest first.\n\n```go\nfunc (p *Passkey) Login(ctx context.Context, userID int, claims map[string]any) (*sectypes.LoginResponse, error)\n```\nLogin implements lookup.PasskeyStore: it creates the session for a user whose passkey assertion was already verified.\n\n```go\nfunc (p *Passkey) Rename(ctx context.Context, userID int, credentialID, name string) error\n```\nRename implements lookup.PasskeyStore.\n\n```go\nfunc (p *Passkey) Store(ctx context.Context, rec lookup.PasskeyCredentialRecord) (int64, error)\n```\nStore implements lookup.PasskeyStore.\n\n```go\nfunc (p *Passkey) UpdateCounter(ctx context.Context, credentialID string, newCounter uint32) (bool, error)\n```\nUpdateCounter implements lookup.PasskeyStore. A counter that did not advance flags the credential as possibly cloned and leaves the stored counter unchanged.\n\n```go\ntype Policy struct {\n\t*Base\n\t// contains filtered or unexported fields\n}\n```\nPolicy implements lookup.PolicyStore on the rule tables.\n\nApplicable rules are the active rules whose user\\_id is the caller plus the rules of every group the caller belongs to; schema and table match case-insensitively and exactly (never a prefix). Column security returns the union of the matching rules. Row security: any applicable has\\_block rule wins, otherwise the templates are combined with AND, each in parentheses. No rule is an empty result; failures are errors so callers fail closed.\n\n```go\nfunc NewPolicy(b *Base, opts PolicyOptions) *Policy\n```\nNewPolicy creates the direct PolicyStore.\n\n```go\nfunc (p *Policy) ColumnSecurity(ctx context.Context, userID int, schema, table string) ([]sectypes.ColumnSecurity, error)\n```\nColumnSecurity implements lookup.PolicyStore.\n\n```go\nfunc (p *Policy) RowSecurity(ctx context.Context, userRef any, schema, table string) (sectypes.RowSecurity, error)\n```\nRowSecurity implements lookup.PolicyStore.\n\n```go\ntype PolicyOptions struct {\n\t// NoGroups skips the group membership table: only rules addressed to the user directly\n\t// apply. Use it when the sec_group_members table is not deployed.\n\tNoGroups bool\n}\n```\nPolicyOptions tunes Policy.\n\n```go\ntype Querier interface {\n\tExecContext(ctx context.Context, query string, args ...any) (sql.Result, error)\n\tQueryContext(ctx context.Context, query string, args ...any) (*sql.Rows, error)\n\tQueryRowContext(ctx context.Context, query string, args ...any) *sql.Row\n}\n```\nQuerier is implemented by \\*sql.DB and \\*sql.Tx.\n\n```go\ntype Runner interface {\n\tRun(run func(*sql.DB) error) error\n}\n```\nRunner runs a database operation, reconnecting once when the \\*sql.DB has been closed. procedure.Runner (and procedure.DB) satisfy it.\n\n```go\ntype Select struct {\n\t// contains filtered or unexported fields\n}\n```\nSelect builds a SELECT.\n\n```go\nfunc (s *Select) Build() Stmt\n```\nBuild renders the statement.\n\n```go\nfunc (s *Select) Cols(cs ...lookup.Column) *Select\n```\nCols sets the selected columns.\n\n```go\nfunc (s *Select) Exists(ctx context.Context, q Querier) (bool, error)\n```\nExists reports whether the select returns at least one row.\n\n```go\nfunc (s *Select) Join(e lookup.Entity, on Cond) *Select\n```\nJoin adds \\`JOIN e ON on\\`.\n\n```go\nfunc (s *Select) OrderBy(cs ...lookup.Column) *Select\n```\nOrderBy adds ascending order columns.\n\n```go\nfunc (s *Select) Query(ctx context.Context, q Querier) (*sql.Rows, error)\n```\nQuery runs the select.\n\n```go\nfunc (s *Select) QueryRow(ctx context.Context, q Querier, dest ...any) error\n```\nQueryRow runs the select and scans the first row into dest.\n\n```go\nfunc (s *Select) Where(cs ...Cond) *Select\n```\nWhere adds AND-ed conditions.\n\n```go\ntype Stmt struct {\n\tSQL  string\n\tArgs []any\n}\n```\nStmt is a rendered statement.\n\n```go\ntype TOTP struct{ *Base }\n```\nTOTP implements lookup.TOTPStore: the secret and enabled flag live on the users table, backup code hashes in their own table.\n\n```go\nfunc NewTOTP(b *Base) *TOTP\n```\nNewTOTP creates the direct TOTPStore.\n\n```go\nfunc (t *TOTP) Disable(ctx context.Context, userID int) error\n```\nDisable implements lookup.TOTPStore.\n\n```go\nfunc (t *TOTP) Enable(ctx context.Context, userID int, secret string, hashedCodes []string) error\n```\nEnable implements lookup.TOTPStore.\n\n```go\nfunc (t *TOTP) RegenerateBackupCodes(ctx context.Context, userID int, hashedCodes []string) error\n```\nRegenerateBackupCodes implements lookup.TOTPStore.\n\n```go\nfunc (t *TOTP) Secret(ctx context.Context, userID int) (string, error)\n```\nSecret implements lookup.TOTPStore.\n\n```go\nfunc (t *TOTP) Status(ctx context.Context, userID int) (bool, error)\n```\nStatus implements lookup.TOTPStore.\n\n```go\nfunc (t *TOTP) ValidateBackupCode(ctx context.Context, userID int, codeHash string) (bool, error)\n```\nValidateBackupCode implements lookup.TOTPStore. An unknown code is (false, nil); a used code is an error. The code is consumed with a conditional update so it cannot be spent twice.\n\n```go\ntype Update struct {\n\t// contains filtered or unexported fields\n}\n```\nUpdate builds an UPDATE.\n\n```go\nfunc (u *Update) Exec(ctx context.Context, q Querier) (int64, error)\n```\nExec runs the update and returns the affected row count.\n\n```go\nfunc (u *Update) Set(as ...Assignment) *Update\n```\nSet adds assignments.\n\n```go\nfunc (u *Update) Where(cs ...Cond) *Update\n```\nWhere adds AND-ed conditions.\n\n","path":"github.com/bitechdev/ResolveSpec/pkg/security/lookup/direct","name":"direct","synopsis":"Package direct is the table-backed implementation of the lookup stores.","isRedistributable":true}
