Documentation
¶
Overview ¶
Package settings is the handful of host knobs an operator may change at RUNTIME, without restarting the control container.
── TWO KEYS, AND THE LIST IS CLOSED ─────────────────────────────────────────────────────────────
max_jobs integer >= 1 how many lifecycle jobs run at once across every stack default_role one of the four the role an account created with no role named gets
This is NOT a generic key-value store: Set validates both the key and the value, and an unknown key is REFUSED rather than stored. A settings table that accepts anything becomes the dumping ground the migration says it is not, and every "just one more key" arrives without a validator. Adding a key is an arm in Set's switch, a reader beside MaxJobs, and a permissions row.
It is also not a hole in invariant 10: every row is configuration an operator CHOSE. Nothing here describes what is running.
── PRECEDENCE, PER KEY ──────────────────────────────────────────────────────────────────────────
max_jobs database > PSTACK_MAX_JOBS (envMaxJobs) > jobs.DefaultMaxRunning default_role database > viewer — there is NO environment variable
The environment variable is the DEFAULT, not the authority. An operator who never opens the UI keeps exactly the behaviour they had, and one who sets the value in the UI is not overridden by the container's environment on the next restart. (`PSTACK_MAX_JOBS` is parsed once at boot by the API's TuningFromEnv and handed in here — this package reads no environment itself, so there is one parse of that variable and one place to find it.)
── A READ NEVER FAILS, IT RESOLVES DOWNWARD ─────────────────────────────────────────────────────
The readers return a value and no error. A database that will not answer, a missing row and a row an operator hand-edited to nonsense all fall to the next source down, because every caller's alternative is worse in exactly one direction:
- max_jobs — a zero cap would stall every job on the host. Falling back keeps it running.
- default_role — an unrankable role is refused by auth.Role.Rank, so a garbage row would mint accounts that can do nothing; falling back to `viewer` is the same least-privilege direction the rest of the auth code takes. It can never resolve UPWARD, and never to admin.
── NEVER CALL A READER FROM INSIDE store.Tx ─────────────────────────────────────────────────────
Every method here goes to Store.DB, and the pool is ONE connection (store's header, rule 16): a read from inside a transaction waits for the connection that transaction holds — a permanent self-deadlock. auth.SsoSignIn is one long transaction, so the SSO default role must be resolved BEFORE it is called and handed in as SsoSignInOpts.DefaultRole, never looked up in provision.
Index ¶
Constants ¶
const ( KeyMaxJobs = "max_jobs" KeyDefaultRole = "default_role" )
The keys. There are no others, and Set refuses anything that is not one of these.
Variables ¶
This section is empty.
Functions ¶
Types ¶
type Error ¶
type Error struct{ Msg string }
Error is a refused key or value. The API maps it to 400.
type Settings ¶
Settings is the table. Owner: the server; every method is one statement.
func New ¶
New wraps a store. envMaxJobs is api.Options.MaxJobs (PSTACK_MAX_JOBS), zero meaning unset.
func (*Settings) DefaultRole ¶
DefaultRole is the role for an account created with no role named: database > viewer.
It NEVER widens what a caller may do. It decides what accounts they create get, and creating an account is already admin-only; the SSO side asks for it only when a provider's own defaultRole is empty ("inherit the host default"). A stored value that is not one of the four is ignored, so this cannot resolve to anything unrankable — or to admin by omission.
func (*Settings) MaxJobs ¶
MaxJobs is the running-job cap: database > PSTACK_MAX_JOBS > jobs.DefaultMaxRunning.
The result is what jobs.Registry.SetMaxRunning is given, at boot and after every write. Lowering it cancels nothing that is already running — see that method.
func (*Settings) Set ¶
Set validates and stores one setting. The key must be one of the two and the value must be valid FOR that key; anything else returns *Error and writes nothing.
Values are stored in canonical form ("008" becomes "8"), so a reader never has to be lenient about what a writer accepted.