Documentation
¶
Overview ¶
Package store provides SQLite-backed persistence for the dashboard, using an Ent client for queries and Atlas-generated versioned migrations. It depends only on the model leaf package so the dashboard package can import it for wiring without an import cycle.
Index ¶
- Variables
- func Migrate(ctx context.Context, db *sql.DB) error
- func Open(ctx context.Context, path string) (*ent.Client, *sql.DB, error)
- type APIKeyStore
- func (s *APIKeyStore) Create(ctx context.Context, label string) (string, model.APIKey, error)
- func (s *APIKeyStore) List(ctx context.Context) ([]model.APIKey, error)
- func (s *APIKeyStore) Revoke(ctx context.Context, id string) error
- func (s *APIKeyStore) Seed(ctx context.Context, label, key string) (bool, error)
- func (s *APIKeyStore) Validate(_ context.Context, presented string) (string, bool)
- type FleetStore
- func (s *FleetStore) CreateGroup(ctx context.Context, name string) (model.Group, error)
- func (s *FleetStore) DeleteGroup(ctx context.Context, id string) error
- func (s *FleetStore) DeleteInstance(ctx context.Context, id string) error
- func (s *FleetStore) ListGroups(ctx context.Context) ([]model.Group, error)
- func (s *FleetStore) ListInstances(ctx context.Context) ([]model.Instance, error)
- func (s *FleetStore) Reconcile(ctx context.Context, rep model.SyncReport) (model.DesiredConfig, error)
- func (s *FleetStore) SetGroupPolicy(ctx context.Context, id, policy, filterMode string) error
- func (s *FleetStore) SetInstanceGroup(ctx context.Context, id, groupID string) error
- func (s *FleetStore) SetInstancePolicy(ctx context.Context, id string, policy *string) error
- type LogStore
- func (s *LogStore) Aggregate(ctx context.Context, from, to time.Time, q string, buckets int) (model.AggregateResult, error)
- func (s *LogStore) Clear(ctx context.Context) error
- func (s *LogStore) Insert(ctx context.Context, e *model.LogEntry) (int64, error)
- func (s *LogStore) Query(ctx context.Context, q string, sinceID int64, limit int) ([]model.LogEntry, error)
- type SessionStore
- func (s *SessionStore) Create(ctx context.Context, user model.User, ttl time.Duration) (string, error)
- func (s *SessionStore) GC(ctx context.Context) error
- func (s *SessionStore) Lookup(ctx context.Context, token string) (model.Session, bool)
- func (s *SessionStore) Revoke(ctx context.Context, token string) error
- type UnblockStore
- func (s *UnblockStore) Acknowledge(id string) bool
- func (s *UnblockStore) Add(reqType, value, targetHostname string) string
- func (s *UnblockStore) GetCompleted() []model.CompletedUnblock
- func (s *UnblockStore) GetPending() []model.UnblockRequest
- func (s *UnblockStore) GetPendingForHost(hostname string) []model.UnblockRequest
- type UserStore
Constants ¶
This section is empty.
Variables ¶
var ( ErrGroupNotFound = errors.New("group not found") ErrInstanceNotFound = errors.New("instance not found") )
ErrGroupNotFound / ErrInstanceNotFound signal unknown IDs to handlers.
Functions ¶
func Migrate ¶
Migrate applies all pending versioned migrations, tracked in schema_migrations so re-running is a no-op. It must run (and succeed) before the HTTP server starts serving; callers should treat an error as fatal rather than serve against a half-migrated database.
Types ¶
type APIKeyStore ¶
type APIKeyStore struct {
// contains filtered or unexported fields
}
APIKeyStore is the SQLite-backed API key store. Active key hashes are cached in memory so the ingest hot path never hits the database.
func NewAPIKeyStore ¶
NewAPIKeyStore creates the store and loads the active-key cache.
func (*APIKeyStore) Revoke ¶
func (s *APIKeyStore) Revoke(ctx context.Context, id string) error
Revoke marks a key revoked and drops it from the active cache.
type FleetStore ¶
type FleetStore struct {
// contains filtered or unexported fields
}
FleetStore is the SQLite-backed instance/group control plane.
func NewFleetStore ¶
func NewFleetStore(client *ent.Client, lg *slog.Logger) *FleetStore
NewFleetStore creates a SQLite-backed fleet store.
func (*FleetStore) CreateGroup ¶
CreateGroup creates an empty group with the given name.
func (*FleetStore) DeleteGroup ¶
func (s *FleetStore) DeleteGroup(ctx context.Context, id string) error
DeleteGroup removes a group; member instances fall back to unmanaged.
func (*FleetStore) DeleteInstance ¶
func (s *FleetStore) DeleteInstance(ctx context.Context, id string) error
DeleteInstance removes an instance record.
func (*FleetStore) ListGroups ¶
ListGroups returns all groups.
func (*FleetStore) ListInstances ¶
ListInstances returns all instances with resolved group + sync state.
func (*FleetStore) Reconcile ¶
func (s *FleetStore) Reconcile(ctx context.Context, rep model.SyncReport) (model.DesiredConfig, error)
Reconcile records an instance report and returns its resolved desired config.
func (*FleetStore) SetGroupPolicy ¶
func (s *FleetStore) SetGroupPolicy(ctx context.Context, id, policy, filterMode string) error
SetGroupPolicy updates a group's policy and optional filter mode.
func (*FleetStore) SetInstanceGroup ¶
func (s *FleetStore) SetInstanceGroup(ctx context.Context, id, groupID string) error
SetInstanceGroup assigns (groupID != "") or clears an instance's group.
func (*FleetStore) SetInstancePolicy ¶
SetInstancePolicy sets (non-nil) or clears (nil) an instance policy override.
type LogStore ¶
type LogStore struct {
// contains filtered or unexported fields
}
LogStore is an Ent-backed implementation of the dashboard LogStore interface, used when DB_PATH is set. Pruning is amortized (every logPruneEvery inserts), so the row count settles around `retention` but can transiently exceed it by up to logPruneEvery-1 rows between prunes.
func NewLogStore ¶
NewLogStore creates a SQLite-backed log store with the given row retention.
func (*LogStore) Aggregate ¶ added in v0.7.2
func (s *LogStore) Aggregate( ctx context.Context, from, to time.Time, q string, buckets int, ) (model.AggregateResult, error)
Aggregate summarizes every retained row in the requested time window.
type SessionStore ¶
type SessionStore struct {
// contains filtered or unexported fields
}
SessionStore is the SQLite-backed session store. Only the SHA-256 of each token is persisted, so a database read cannot hijack live sessions.
func NewSessionStore ¶
func NewSessionStore(client *ent.Client, lg *slog.Logger) *SessionStore
NewSessionStore creates a SQLite-backed session store.
func (*SessionStore) Create ¶
func (s *SessionStore) Create(ctx context.Context, user model.User, ttl time.Duration) (string, error)
Create mints a session for the user and returns the opaque token.
func (*SessionStore) GC ¶
func (s *SessionStore) GC(ctx context.Context) error
GC prunes expired sessions.
type UnblockStore ¶
type UnblockStore struct {
// contains filtered or unexported fields
}
UnblockStore is the SQLite-backed implementation of the dashboard's UnblockStore interface. The interface predates persistence and carries no context or error returns, so failures are logged and reported as zero values.
func NewUnblockStore ¶
func NewUnblockStore(client *ent.Client, lg *slog.Logger) *UnblockStore
NewUnblockStore creates a SQLite-backed unblock store.
func (*UnblockStore) Acknowledge ¶
func (s *UnblockStore) Acknowledge(id string) bool
Acknowledge moves a pending request to the completed list. Returns false if the ID is unknown or on error.
func (*UnblockStore) Add ¶
func (s *UnblockStore) Add(reqType, value, targetHostname string) string
Add queues an unblock request, deduplicating on (type, value, target). Returns the request ID, or "" when the store is full or on error.
func (*UnblockStore) GetCompleted ¶
func (s *UnblockStore) GetCompleted() []model.CompletedUnblock
GetCompleted returns the bounded list of completed unblocks, oldest first.
func (*UnblockStore) GetPending ¶
func (s *UnblockStore) GetPending() []model.UnblockRequest
GetPending returns all pending unblock requests.
func (*UnblockStore) GetPendingForHost ¶
func (s *UnblockStore) GetPendingForHost(hostname string) []model.UnblockRequest
GetPendingForHost returns pending requests targeting the given hostname or all hosts.
type UserStore ¶
type UserStore struct {
// contains filtered or unexported fields
}
UserStore is the SQLite-backed user store.
func NewUserStore ¶
NewUserStore creates a SQLite-backed user store.