Documentation
¶
Overview ¶
Package configs manages runtime-editable configuration stored in the `configs` table. Adding a new app-level knob is a two-step change:
- Declare a default in appDefaults() below + add its key constant.
- (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
- type Encryptor
- type Service
- func (s *Service) AdminPasswordChanged() bool
- func (s *Service) AppDescription() string
- func (s *Service) AppName() string
- func (s *Service) AppURL() string
- func (s *Service) Bootstrap(ctx context.Context, extras ...entity.Config) error
- func (s *Service) DeleteOwned(ctx context.Context, owner string) error
- func (s *Service) EncryptionKey() string
- func (s *Service) EnsureOwned(ctx context.Context, owner string, rows ...entity.Config) error
- func (s *Service) Get(key string) string
- func (s *Service) GetOwned(owner, key string) string
- func (s *Service) List() []entity.Config
- func (s *Service) ListOwned(owner string) []entity.Config
- func (s *Service) Missing(owner string) []string
- func (s *Service) Regenerate(ctx context.Context, key string) error
- func (s *Service) SessionSecret() string
- func (s *Service) Set(ctx context.Context, key, value string) error
- func (s *Service) SetEncryptor(e Encryptor)
- func (s *Service) SetOwned(ctx context.Context, owner, key, value string) error
Constants ¶
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 (*Service) AdminPasswordChanged ¶
func (*Service) AppDescription ¶
func (*Service) Bootstrap ¶
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
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
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
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 ¶
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 ¶
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 ¶
List returns every app-level variable. Kept for backward compatibility with the admin settings page.
func (*Service) Missing ¶
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 ¶
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 (*Service) Set ¶
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
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.