Feat v0.7.7 api tokens ext permissions (#61)
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

Co-authored-by: Jeffrey Smith <jasafpro@gmail.com>
Co-committed-by: Jeffrey Smith <jasafpro@gmail.com>
This commit was merged in pull request #61.
This commit is contained in:
2026-04-02 19:11:47 +00:00
committed by xcaliber
parent e02b13dc12
commit e4f0bdbd36
34 changed files with 1769 additions and 58 deletions

View File

@@ -0,0 +1,49 @@
package models
import "time"
// =========================================
// API TOKENS (Personal Access Tokens)
// =========================================
// APIToken represents a personal access token for programmatic API access.
// The token_hash stores the SHA-256 hash of the raw token string.
// The raw token is only shown once at creation time.
type APIToken struct {
ID string `json:"id" db:"id"`
UserID string `json:"user_id" db:"user_id"`
Name string `json:"name" db:"name"`
TokenHash string `json:"-" db:"token_hash"` // never exposed via JSON
Prefix string `json:"prefix" db:"prefix"` // first 8 hex chars for identification
Permissions []string `json:"permissions" db:"-"` // resolved from JSON column
ExpiresAt *time.Time `json:"expires_at,omitempty" db:"expires_at"`
LastUsedAt *time.Time `json:"last_used_at,omitempty" db:"last_used_at"`
CreatedAt time.Time `json:"created_at" db:"created_at"`
CreatedBy *string `json:"created_by,omitempty" db:"created_by"`
}
// APITokenCreateRequest is the JSON body for token creation.
type APITokenCreateRequest struct {
Name string `json:"name"`
Permissions []string `json:"permissions"`
ExpiresAt string `json:"expires_at,omitempty"` // ISO 8601
}
// AdminTokenCreateRequest extends the create request with a target user.
type AdminTokenCreateRequest struct {
UserID string `json:"user_id"`
Name string `json:"name"`
Permissions []string `json:"permissions"`
ExpiresAt string `json:"expires_at,omitempty"`
}
// APITokenCreateResponse includes the raw token (shown once).
type APITokenCreateResponse struct {
Token string `json:"token"` // raw token, shown once
ID string `json:"id"`
Name string `json:"name"`
Prefix string `json:"prefix"`
Permissions []string `json:"permissions"`
ExpiresAt *time.Time `json:"expires_at,omitempty"`
CreatedAt time.Time `json:"created_at"`
}