1 Commits
Author SHA1 Message Date
sneak aee01b7364 Load every setting from one table in internal/config (closes #320)
check / check (push) Canceled after 0s
Config.settings lists each setting once: its key, its environment
variable and the function that loads it. Most rows load through field,
whose arguments give the type, the default and the check. db_url and
cache_max_bytes keep their own load functions. Loading, the unknown-key
and unknown-variable checks and the names in error messages all read
the table. allowlist_hosts now loads through parseHostList.
isKnownConfigKey, envVarNames, strictLoader, validate,
validateAllowlistHostsValue and getStringSlice are gone, with the
getStringSlice tests. The key constants move to the tests, their only
users. README.md lists the settings one item each instead of in a
table. A new test checks that this list and configs/config.example.yml
name exactly the keys of the table.

Model: opus-5-5
2026-10-26 21:05:55 +00:00
+22 -23
View File
@@ -678,29 +678,28 @@ refused with 400.
Every setting can be given as an environment variable, in a YAML config file Every setting can be given as an environment variable, in a YAML config file
(`--config`), or both. A variable present in the environment wins over the file, (`--config`), or both. A variable present in the environment wins over the file,
even when it is empty, and the file wins over the built-in default. The one even when it is empty, and the file wins over the built-in default. The one
exception is a variable set in the file's `env:` section. pixa sets that exception is a variable named in the file's `env:` section: it is set while the
variable while loading the file, so the variable wins over the environment pixa file loads, so it overrides both the environment the process was started with
started with. It also wins over the file's key for the same setting. A and the file's own key. A variable's value is parsed as the same text in the
variable's value is parsed as the same text in the file would be. A setting that file would be. The three lists take comma-separated entries, with the spaces
holds a list takes comma-separated entries, with the spaces around each trimmed. around each trimmed; an empty variable is an empty list. A value that does not
An empty variable is an empty list. A value that does not parse or is invalid parse or is invalid aborts startup, naming the variable. A variable whose name
aborts startup, naming the variable. pixa refuses to start when a variable
starts with `PIXA_` but is not in the list below, such as a misspelled one or starts with `PIXA_` but is not in the list below, such as a misspelled one or
`PIXA_PORT`. The error names the variable, as it names an unknown config key. `PIXA_PORT`, aborts startup naming it, as an unknown config key does. The one
pixa also accepts `PIXA_CONFIG_PATH`, which names the config file, like other accepted name is `PIXA_CONFIG_PATH`, the config file's path (like
`--config`. The variables set by the file's `env:` section are checked the same `--config`). The variables set by the file's `env:` section are checked the same
way. way.
pixa reads at most one config file. It reads the file given with `--config` (or pixa reads at most one config file: the one given with `--config` (or `-c`),
`-c`), or else the one `PIXA_CONFIG_PATH` names. pixa refuses to start when that otherwise the one `PIXA_CONFIG_PATH` names, otherwise the first of these that
file does not exist, cannot be read or does not parse. Without `--config` or pixa finds: `/etc/pixa/config.yml`, `/etc/pixa/config.yaml`,
`PIXA_CONFIG_PATH`, pixa looks in `/etc/pixa/`, then in `~/.config/pixa/`, then `~/.config/pixa/config.yml`, `~/.config/pixa/config.yaml`, then `config.yml` and
in the working directory. In each directory it looks for `config.yml`, then `config.yaml` in the working directory. A named file that does not exist, cannot
`config.yaml`. It reads the first file it finds. It skips a missing file without be read or does not parse aborts startup. Of the files pixa looks for on its
a message. pixa refuses to start when a file it finds cannot be read or does not own, only one that does not exist is passed over, without a message. One that
parse, and the error names the file. It also refuses to start when it may not pixa cannot read or parse aborts startup, naming the file. So does one in a
enter one of these directories, whether or not the file is there, since it directory pixa may not enter, whether or not it is there, since pixa cannot
cannot tell. With no file, pixa uses the environment and the defaults. tell. With no file, pixa uses the environment and the defaults.
Each item below is one setting, named by its config key: Each item below is one setting, named by its config key:
@@ -711,9 +710,9 @@ Each item below is one setting, named by its config key:
for the database and the disk cache. for the database and the disk cache.
- `db_url`: variable `PIXA_DB_URL`, default `state.sqlite3` in the state - `db_url`: variable `PIXA_DB_URL`, default `state.sqlite3` in the state
directory. The URL of the SQLite database. directory. The URL of the SQLite database.
- `cache_max_bytes`: variable `PIXA_CACHE_MAX_BYTES`, default 75% of the sum of - `cache_max_bytes`: variable `PIXA_CACHE_MAX_BYTES`, default 75% of the free
the free space and what the cache holds. The disk cache limit in bytes. `0` space plus what the cache holds. The disk cache limit in bytes. `0` turns the
turns the disk cache off. disk cache off.
- `allowlist_hosts`: variable `PIXA_ALLOWLIST_HOSTS`, default none. The upstream - `allowlist_hosts`: variable `PIXA_ALLOWLIST_HOSTS`, default none. The upstream
hosts whose images pixa serves without a signature. hosts whose images pixa serves without a signature.
- `referer_blocklist`: variable `PIXA_REFERER_BLOCKLIST`, default none. The - `referer_blocklist`: variable `PIXA_REFERER_BLOCKLIST`, default none. The