This repository has been archived on 2026-04-03. You can view files and clone it. You cannot open issues or pull requests or push a commit.
Files
core/server/store/api_token_iface.go
Jeffrey Smith e4f0bdbd36
All checks were successful
CI/CD / detect-changes (push) Successful in 4s
CI/CD / e2e-smoke (push) Has been skipped
CI/CD / test-frontend (push) Successful in 6s
CI/CD / test-runners (push) Has been skipped
CI/CD / test-go-pg (push) Successful in 2m48s
CI/CD / test-sqlite (push) Successful in 2m49s
CI/CD / build-and-deploy (push) Successful in 28s
Feat v0.7.7 api tokens ext permissions (#61)
Co-authored-by: Jeffrey Smith <jasafpro@gmail.com>
Co-committed-by: Jeffrey Smith <jasafpro@gmail.com>
2026-04-02 19:11:47 +00:00

35 lines
1.3 KiB
Go

package store
import (
"context"
"armature/models"
)
// APITokenStore manages personal access tokens for programmatic API access.
type APITokenStore interface {
// Create inserts a new API token. The token_hash must be a SHA-256 hash
// of the raw token string. ID and CreatedAt are set by the implementation.
Create(ctx context.Context, token *models.APIToken) error
// GetByHash retrieves a non-expired token by its SHA-256 hash.
// Returns nil, nil if not found or expired.
GetByHash(ctx context.Context, tokenHash string) (*models.APIToken, error)
// ListForUser returns all tokens belonging to a user, ordered by created_at DESC.
ListForUser(ctx context.Context, userID string) ([]models.APIToken, error)
// Revoke deletes a token owned by the specified user.
// Returns the number of rows affected (0 if not found or not owned).
Revoke(ctx context.Context, id, userID string) (int64, error)
// RevokeByID deletes a token by ID regardless of owner (admin use).
RevokeByID(ctx context.Context, id string) (int64, error)
// CleanExpired deletes all tokens past their expires_at. Returns rows deleted.
CleanExpired(ctx context.Context) (int64, error)
// UpdateLastUsed sets last_used_at to now for the given token ID.
UpdateLastUsed(ctx context.Context, id string) error
}