vars

package
v0.3.1 Latest Latest
Warning

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

Go to latest
Published: Apr 5, 2026 License: MIT Imports: 19 Imported by: 0

Documentation

Overview

Package vars implements the tailkitd var store: a per-scope, concurrency-safe key-value store persisted as JSON files under /etc/tailkitd/vars/.

Scope identity is "project/env". Each scope has its own *sync.RWMutex so concurrent reads across different scopes never block each other, and writes within a scope are serialised without blocking other scopes.

Invariants:

  • Keys starting with "_" are reserved for internal metadata and are never returned to callers. Set rejects them with an error.
  • _meta.updated_at and _meta.updated_by are written on every Set/Delete.
  • All writes are atomic: temp file in same directory → rename.

Index

Constants

View Source
const (
	ErrScopeNotFound = storeError("vars: scope not found")
	ErrKeyNotFound   = storeError("vars: key not found")
	ErrReservedKey   = storeError("vars: key is reserved (_-prefixed keys are internal)")
	ErrInvalidKey    = storeError("vars: invalid key format")
)

Variables

This section is empty.

Functions

This section is empty.

Types

type Handler

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

Handler serves all /vars/* endpoints.

GET  /vars                           — list all configured scopes
GET  /vars/config                    — get the vars config
GET  /vars/{project}/{env}           — list all keys in scope (JSON map)
GET  /vars/{project}/{env}?format=env — render as KEY=VALUE text
GET  /vars/{project}/{env}/{key}     — get a single key
PUT  /vars/{project}/{env}/{key}     — set a key (body: plain text value)
DELETE /vars/{project}/{env}/{key}   — delete a key
DELETE /vars/{project}/{env}         — delete entire scope

func NewHandler

func NewHandler(cfg config.VarsConfig, store *Store, logger *zap.Logger) *Handler

NewHandler constructs a vars Handler.

func (*Handler) Register

func (h *Handler) Register(mux *http.ServeMux)

Register mounts all vars endpoints onto mux.

type Store

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

Store is the var store. It holds per-scope mutexes in a sync.Map and persists data as JSON files on disk.

func NewStore

func NewStore(baseDir string, logger *zap.Logger) *Store

NewStore constructs a Store rooted at baseDir. Call with defaultBaseDir ("/etc/tailkitd/vars") in production.

func (*Store) Delete

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

Delete removes a key from a scope and updates _meta.*. Returns ErrReservedKey if key starts with "_". Returns nil (not an error) if the key did not exist.

func (*Store) DeleteScope

func (s *Store) DeleteScope(ctx context.Context, project, env string) error

DeleteScope removes the entire scope file. Returns nil if the scope did not exist.

func (*Store) Get

func (s *Store) Get(ctx context.Context, project, env, key string) (string, error)

Get returns the value of a single key in a scope. Returns ("", ErrKeyNotFound) if the key does not exist. Returns ErrReservedKey if the key starts with "_".

func (*Store) List

func (s *Store) List(ctx context.Context, project, env string) (map[string]string, error)

List returns all non-reserved keys and their values for a scope. Keys starting with "_" are stripped before returning. Returns ErrScopeNotFound if the scope file does not exist.

func (*Store) RenderEnv

func (s *Store) RenderEnv(ctx context.Context, project, env string) (string, error)

RenderEnv returns vars as sorted KEY=VALUE lines, shell-quoted. Used by GET /vars/{project}/{env}?format=env.

func (*Store) Set

func (s *Store) Set(ctx context.Context, project, env, key, value, caller string) error

Set writes a key/value pair to a scope and updates _meta.*. Returns ErrReservedKey if key starts with "_". Returns ErrInvalidKey if key does not match the allowed pattern.

Jump to

Keyboard shortcuts

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