config: add global internal-ipnet setting
Add support for a general [sr.ht]internal-ipnet list of networks that
can be considered OK for internal operations.
The default is loopback addresses (127.0.0.0/8 and ::1/128) and private
routable unicast addresses (192.168.0.0/16, 10.0.0.0/8 and fc00::/7)
Since parsing IP networks and addresses can be costly, store the result
of [sr.ht]internal-ipnet into a global list of net.IPNet and
a convenience IsInternalIP() function to be called by services.
Signed-off-by: Robin Jarry <robin@jarry.cc>
config: factorize integer parsing
Add a new GetInt() function to parse an integer value from a parsed
ini.File. Use that function instead of duplicated code.
Signed-off-by: Robin Jarry <robin@jarry.cc>
config: decouple file loading from crypto init
Now that the algorithm for loading the config is non-trivial, the code
for it should be re-used everywhere. However, it is currently coupled
with a call to `InitCrypto()`, which requires certain things like
webhook keys to be configured. This is not suitable for many components
that still need the configuration.
This commit introduces `config.LoadFiles()` to do only the file loading.
`LoadConfig()` uses it, and so can any components that do not care about
crypto initialization.
config: print loaded config(s) to log
config: allow spreading config over multiple files
This is the Go-equivalent to
https://lists.sr.ht/~sircmpwn/sr.ht-dev/patches/47657
This commit enables spreading the config in /etc/sr.ht - and, crucially,
_only_ in /etc/sr.ht - over multiple .ini files.
If a file config.ini is found (either in current or parent directory, or
/etc/sr.ht) it (and only it) is loaded and any other ini files are
ignored. To utilize multiple configs, they must be in /etc/sr.ht, and
none of them must be called config.ini.
Spreading the config over multiple files will make it much easier to
create containerized versions, where e.g. different secrets can be made
available in different files, but rendering it all into one big file
would require some preprocessing.
Various bug fixes per pages.sr.ht
config: add GetOrigin function
This implements the same behavior as Python's srht.config.get_origin.