configs

package
v0.9.2 Latest Latest
Warning

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

Go to latest
Published: May 10, 2026 License: MIT Imports: 10 Imported by: 0

Documentation

Overview

Package configs manages runtime-editable configuration stored in the `configs` table. Adding a new app-level knob is a two-step change:

  1. Declare a default in appDefaults() below + add its key constant.
  2. (Optional) Add a typed accessor on Service — e.g. AppURL(), SessionSecret() — so callers don't juggle strings.

Module-level configs live in each module's Config struct; the framework reflects those at boot via entity.StructToConfigs.

Values live in a cache guarded by RWMutex, populated at startup and refreshed on every Set() — so hot-reload is transparent to callers.

Index

Constants

View Source
const (
	KeyAppName              = "app_name"
	DefaultAppName          = "Wick Mini Tools"
	KeyAppDescription       = "app_description"
	DefaultAppDescription   = "A lightweight internal tooling platform — build, deploy, and run custom tools for your team in minutes."
	KeyAppURL               = "app_url"
	KeySessionSecret        = "session_secret"
	KeyAdminPasswordChanged = "admin_password_changed"
	KeyEncryptionKey        = "encryption_key"
)

Canonical key constants. Always reference a variable by these rather than the string literal — renaming then becomes a one-line change the compiler catches everywhere.

Variables

This section is empty.

Functions

This section is empty.

Types

type Encryptor added in v0.6.1

type Encryptor interface {
	EncryptMaster(plain string) (string, error)
	DecryptMaster(token string) (string, error)
	Disabled() bool
}

Encryptor is the subset of *enc.Service the configs layer uses for at-rest encryption of `secret`-tagged rows. Set once after boot via SetEncryptor; reconcile/setOwned check it before encrypting writes or decrypting reads.

type Service

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

Service exposes typed, cached access to runtime variables. The cache is loaded once at startup by Bootstrap() and refreshed on every Set() / Regenerate() call, so reads never touch the DB.

func NewService

func NewService(db *gorm.DB) *Service

func (*Service) AdminPasswordChanged

func (s *Service) AdminPasswordChanged() bool

func (*Service) AppDescription

func (s *Service) AppDescription() string

func (*Service) AppName

func (s *Service) AppName() string

func (*Service) AppURL

func (s *Service) AppURL() string

func (*Service) Bootstrap

func (s *Service) Bootstrap(ctx context.Context, extras ...entity.Config) error

Bootstrap reconciles the given extras plus the app-level defaults with the DB and seeds the in-memory cache. Pass module-declared Configs collected from every registered tool/job — wick assigns Owner before handing them off. Call once at startup, before anything else reads config.

func (*Service) DeleteOwned added in v0.6.1

func (s *Service) DeleteOwned(ctx context.Context, owner string) error

DeleteOwned removes every row scoped to owner from the DB and the in-memory cache. Used when a connector / tool / job instance is destroyed. Returns nil when owner has no rows.

func (*Service) EncryptionKey added in v0.6.0

func (s *Service) EncryptionKey() string

EncryptionKey returns the master key for the encrypted-fields layer. WICK_ENC_KEY in the environment wins when set — production deploys inject from a vault here so the secret never lands in the DB. Falls back to the DB-stored value (auto-generated on first boot via the generators map in spec.go).

func (*Service) EnsureOwned added in v0.6.1

func (s *Service) EnsureOwned(ctx context.Context, owner string, rows ...entity.Config) error

EnsureOwned reconciles a runtime-declared set of rows for owner. Used when a connector / tool / job instance is created after boot: the caller stamps Owner on each row and hands them in; the rows that already exist are left alone (metadata is refreshed, value preserved), missing rows are created.

The owner string scopes the rows — by convention "connector:{id}" for connector instances. Any owner string is accepted.

func (*Service) Get

func (s *Service) Get(key string) string

Get returns the cached value for the app-level key (Owner==""). Callers should prefer typed accessors (AppURL, SessionSecret) so renames are compiler-enforced.

func (*Service) GetOwned

func (s *Service) GetOwned(owner, key string) string

GetOwned returns the cached value for (owner, key), or empty string if missing. Tool/job handlers use this via Ctx helpers; cross-owner reads are allowed but should be rare and intentional.

func (*Service) List

func (s *Service) List() []entity.Config

List returns every app-level variable. Kept for backward compatibility with the admin settings page.

func (*Service) ListOwned

func (s *Service) ListOwned(owner string) []entity.Config

ListOwned returns every config scoped to owner in declaration order.

func (*Service) Missing

func (s *Service) Missing(owner string) []string

Missing returns the keys of every Required row in owner that has no value stored. Tool handlers call this via Ctx.Missing() to render a "setup required" banner before doing any work.

func (*Service) Regenerate

func (s *Service) Regenerate(ctx context.Context, key string) error

Regenerate replaces an app-level key's value by running its registered generator. Fails if the key is unknown, has no generator, or is not flagged CanRegenerate.

func (*Service) SessionSecret

func (s *Service) SessionSecret() string

func (*Service) Set

func (s *Service) Set(ctx context.Context, key, value string) error

Set persists a new value for the app-level key and refreshes the cache. Returns an error if the key is unknown.

func (*Service) SetEncryptor added in v0.6.1

func (s *Service) SetEncryptor(e Encryptor)

SetEncryptor wires the at-rest cipher. Call once at boot after the enc service is built (which itself depends on Bootstrap having reconciled the encryption_key row). After this point, every Set against an IsSecret row writes ciphertext to the DB and the cache holds the decrypted plaintext.

Calling with a Disabled() encryptor is a no-op — the layer behaves as if SetEncryptor was never called.

func (*Service) SetOwned

func (s *Service) SetOwned(ctx context.Context, owner, key, value string) error

SetOwned persists a new value for (owner, key) and refreshes the cache. Returns an error if that pair was never declared.

Jump to

Keyboard shortcuts

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