File
The file source reads mappings from a text file. It has no external dependency, and suits deployments where the mappings are maintained by configuration management or generated by a migration script. The file is read into memory at startup and when it is reloaded, so lookups never read the disk.
[mapping]source = "file"normalize = "lowercase"
[mapping.file]path = "/etc/proxy/mappings/mappings.tsv"The only key of [mapping.file] is path.
File format
Section titled “File format”Each line holds an identifier and a destination, separated by white space. Further fields on the line are ignored, and so are empty lines and lines that start with #.
Two kinds of line stop the proxy from starting. A line with a single field fails with mapping file <path>:<line> is not <identifier> <destination>. A line naming a destination that is not declared fails with mapping file <path>:<line> references an undeclared destination.
# identifier destination[email protected] legacy[email protected] stalwart[email protected] stalwartUpdates
Section titled “Updates”The file can be changed in two ways: through the API, or by editing it.
The file source can be written through the management API. When a mapping changes through the API, the proxy writes the whole table to <path>.tmp, flushes it to disk, renames it over the file and then flushes the directory, so the file on disk is always complete, even after a power loss. The rewritten file holds one sorted entry per line, with a tab between identifier and destination. Comments, empty lines and further fields are not kept. The proxy’s user needs write access to the file’s directory. A change made through the web interface or the API may only set path to a file directly inside the mappings/ directory next to the configuration file, as described under path confinement; a path set by hand can be anywhere. A batch of changes, such as an import, is applied to the table and written to the file once. A change that leaves the table as it was does not rewrite the file.
An identifier that the file format cannot hold is rejected before anything is written: one that contains white space, or one that starts with #, which would turn its line into a comment. Writes through the API and reloads run one at a time, so a reload never discards a change made through the API while it runs.
The file can also be edited directly, and reloaded without a restart with the Reload store button of the web interface or POST /api/v1/mappings/reload. A reload reads the file, checks that every destination is declared, and replaces the table in memory only when the file is valid. A file with an undeclared destination is therefore rejected, and the previous table stays in use. When an identifier appears twice, the later line wins.
Mixing the two methods needs care. A change made through the API rewrites the file from the table in memory, so edits made to the file and not yet reloaded are lost. After editing the file, reload it before using the API. A reload does not clear the lookup cache either, so a changed entry takes effect when its cache entry expires or is invalidated from the web interface or with POST /api/v1/cache/invalidate. A configuration reload, by contrast, reads the file again and clears the cache when the file changed.