Documentation
¶
Index ¶
- Constants
- Variables
- func GenerateIngestToken() (string, string, error)
- func HashIngestToken(token string) string
- type IngestToken
- type IngestTokenActor
- type Store
- func (s *Store) ApplyConfiguredIngestToken(ctx context.Context, token string) (bool, error)
- func (s *Store) AuthenticateIngestToken(ctx context.Context, token string) (bool, error)
- func (s *Store) CreateIngestToken(ctx context.Context, name string, actor IngestTokenActor) (IngestToken, string, error)
- func (s *Store) Delete(ctx context.Context, key string) error
- func (s *Store) Get(ctx context.Context, key string, out any) error
- func (s *Store) HasActiveIngestToken(ctx context.Context) (bool, error)
- func (s *Store) IssueFirstIngestToken(ctx context.Context, actor IngestTokenActor) (string, error)
- func (s *Store) ListActiveIngestTokens(ctx context.Context) ([]IngestToken, error)
- func (s *Store) RevokeIngestToken(ctx context.Context, id string, actor IngestTokenActor) error
- func (s *Store) StartIngestTokenLastUsedFlusher() (stop func())
- func (s *Store) Upsert(ctx context.Context, key string, value any) error
Constants ¶
const ( // MaxActiveIngestTokens caps the tokens that can authenticate at once. MaxActiveIngestTokens = 50 // MaxIngestTokenNameLength is measured in characters after trimming. MaxIngestTokenNameLength = 64 )
Variables ¶
var ( ErrInvalidIngestTokenName = errors.New("settings: invalid ingest token name") ErrIngestTokenNameTaken = errors.New("settings: ingest token name already in use") ErrIngestTokenLimitReached = errors.New("settings: active ingest token limit reached") ErrIngestTokenNotFound = errors.New("settings: ingest token not found") )
Functions ¶
func GenerateIngestToken ¶
GenerateIngestToken returns a new token and its digest. The format is foi_ followed by 43 base64url characters.
func HashIngestToken ¶
Types ¶
type IngestToken ¶
type IngestToken struct {
ID string `json:"id"`
Name string `json:"name"`
Hint string `json:"hint"`
CreatedAt string `json:"created_at"`
LastUsedAt *string `json:"last_used_at"`
}
IngestToken is the metadata an administrator can see. It holds no digest and no plaintext; the plaintext exists only in the create response.
type IngestTokenActor ¶
IngestTokenActor identifies who changed a token, for the audit trail.
type Store ¶
type Store struct {
// contains filtered or unexported fields
}
func (*Store) ApplyConfiguredIngestToken ¶
ApplyConfiguredIngestToken stores a token supplied by configuration, and reports whether it did. It acts only when no token row has ever existed, counting revoked rows, so a restart still carrying the setting cannot bring back a token an administrator revoked.
func (*Store) AuthenticateIngestToken ¶
AuthenticateIngestToken costs one digest and one lookup on the unique token_hash index. A match is recorded in memory for the last-used flusher; the request path never writes to SQLite.
func (*Store) CreateIngestToken ¶
func (s *Store) CreateIngestToken(ctx context.Context, name string, actor IngestTokenActor) (IngestToken, string, error)
CreateIngestToken issues a token and returns its plaintext, which is never stored or available again. The first statement of the transaction is the conditional insert, so SQLite takes its write lock before counting and concurrent creates cannot pass the cap together.
func (*Store) Get ¶
Get leaves out unchanged when the row is missing so callers keep their defaults. A corrupt value surfaces as a decode error rather than silently falling through to defaults.
func (*Store) HasActiveIngestToken ¶
HasActiveIngestToken reports whether ingest can currently authenticate anyone.
func (*Store) IssueFirstIngestToken ¶
IssueFirstIngestToken creates the token handed to the first administrator during setup. It returns an empty string when a token has already existed.
func (*Store) ListActiveIngestTokens ¶
func (s *Store) ListActiveIngestTokens(ctx context.Context) ([]IngestToken, error)
ListActiveIngestTokens returns at most MaxActiveIngestTokens rows, newest first.
func (*Store) RevokeIngestToken ¶
RevokeIngestToken stops a token immediately: ingest authenticates against the row on every request and no credential is cached. The row is kept for the audit trail and for the rule that configuration seeds only a first token.
func (*Store) StartIngestTokenLastUsedFlusher ¶
func (s *Store) StartIngestTokenLastUsedFlusher() (stop func())
StartIngestTokenLastUsedFlusher writes coalesced last-used times about once a minute. The returned function stops the loop and performs a final flush; call it after the ingest listeners have stopped and before the database closes.