settings

package
v0.0.0-...-0301fe8 Latest Latest
Warning

This package is not in the latest version of its module.

Go to latest
Published: Nov 23, 2026 License: Apache-2.0 Imports: 18 Imported by: 0 modules, 0 packages

The first number is the count of modules that contain a package that imports this one. The module count is a better indicator of popularity than the package count. A module with 100 importing packages is counted only once instead of 100 times, reflecting the fact that the choice to use the package was likely made only once, not 100 times.
A '?' means that the value hasn't been computed yet.

Documentation

Index

Constants

View Source
const (
	// MaxActiveIngestTokens caps the tokens that can authenticate at once.
	MaxActiveIngestTokens = 50
	// MaxIngestTokenNameLength is measured in characters after trimming.
	MaxIngestTokenNameLength = 64
)

Variables

View Source
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

func GenerateIngestToken() (string, string, error)

GenerateIngestToken returns a new token and its digest. The format is foi_ followed by 43 base64url characters.

func HashIngestToken

func HashIngestToken(token string) string

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

type IngestTokenActor struct {
	UserID    string
	RemoteIP  string
	UserAgent string
}

IngestTokenActor identifies who changed a token, for the audit trail.

type Store

type Store struct {
	// contains filtered or unexported fields
}

func NewStore

func NewStore(db *sql.DB) *Store

func (*Store) ApplyConfiguredIngestToken

func (s *Store) ApplyConfiguredIngestToken(ctx context.Context, token string) (bool, error)

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

func (s *Store) AuthenticateIngestToken(ctx context.Context, token string) (bool, error)

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) Delete

func (s *Store) Delete(ctx context.Context, key string) error

func (*Store) Get

func (s *Store) Get(ctx context.Context, key string, out any) error

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

func (s *Store) HasActiveIngestToken(ctx context.Context) (bool, error)

HasActiveIngestToken reports whether ingest can currently authenticate anyone.

func (*Store) IssueFirstIngestToken

func (s *Store) IssueFirstIngestToken(ctx context.Context, actor IngestTokenActor) (string, error)

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

func (s *Store) RevokeIngestToken(ctx context.Context, id string, actor IngestTokenActor) error

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.

func (*Store) Upsert

func (s *Store) Upsert(ctx context.Context, key string, value any) error

Jump to

Keyboard shortcuts

? : This menu
/ : Search site
f or F : Jump to
y or Y : Canonical URL