This commit enables spreading the config in /etc/sr.ht - and, crucially,
_only_ in /etc/sr.ht - over multiple .ini files.
As before, if a file ./config.ini is found, it (and only it) is loaded
and any config in /etc is ignored.
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.
---
The behavior of not loading ./*.ini is my suggestion. In my opinion
loading ./config.ini is more of a dev environment thing, and I have
various .ini files in the base folder for different scenarios, which
would clash. But I am open to suggestions.
If this is accepted, I already have the same patch for core-go ready.
srht/config.py | 19 +++++++++++++------
1 file changed, 13 insertions(+), 6 deletions(-)
diff --git a/srht/config.py b/srht/config.py
index db180a2..4504769 100644
--- a/srht/config.py+++ b/srht/config.py
@@ -1,3 +1,4 @@
+from glob import globfrom urllib.parse import urlparse
from configparser import ConfigParser
from werkzeug.local import LocalProxy
@@ -11,17 +12,23 @@ _config = None
config = LocalProxy(lambda: _config)
+def load_one(path):+ try:+ with open(path) as f:+ _config.read_file(f)+ return True+ except FileNotFoundError:+ return False+def load_config():
global _config
_config = ConfigParser()
- paths = ["config.ini", "/etc/sr.ht/config.ini"]+ # Loads _either_ config.ini _or_ all .ini files in /etc/sr.ht+ paths = ["config.ini", "/etc/sr.ht/*.ini"] for path in paths:
- try:- with open(path) as f:- _config.read_file(f)+ loaded = any(map(lambda p: load_one(p), glob(path)))+ if loaded: break
- except FileNotFoundError:- passload_config()
--
2.43.0
On Tuesday, December 12th, 2023 at 12:26, Conrad Hoffmann <ch@bitfehler.net> wrote:
> This commit enables spreading the config in /etc/sr.ht - and, crucially,> _only_ in /etc/sr.ht - over multiple .ini files.> > As before, if a file ./config.ini is found, it (and only it) is loaded> and any config in /etc is ignored.> > 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.
Makes sense to me.
> The behavior of not loading ./*.ini is my suggestion. In my opinion> loading ./config.ini is more of a dev environment thing, and I have> various .ini files in the base folder for different scenarios, which> would clash. But I am open to suggestions.
Yeah, I agree we shouldn't load random ini files from the current directory.
There is also SRHT_CONFIG that IIRC we use in a daemon somewhere…
On Tuesday, December 12th, 2023 at 12:34, Simon Ser <contact@emersion.fr> wrote:
> There is also SRHT_CONFIG that IIRC we use in a daemon somewhere…
There it is:
gitsrht-shell/main.go:82: for _, path := range []string{os.Getenv("SRHT_CONFIG"), "/etc/sr.ht/config.ini"} {
gitsrht-update-hook/main.go:50: for _, path := range []string{os.Getenv("SRHT_CONFIG"), "/etc/sr.ht/config.ini"} {
On 12/12/23 12:34, Simon Ser wrote:
> There is also SRHT_CONFIG that IIRC we use in a daemon somewhere…
TIL. Looks like gitsrht-shell & gitsrht-update-hook do their own
loading, so they would also need a patch. Different repo however, so it
doesn't really affect this patch. Thanks for pointing it out, though!
On Tuesday, December 12th, 2023 at 12:39, Conrad Hoffmann <ch@bitfehler.net> wrote:
> On 12/12/23 12:34, Simon Ser wrote:> > > There is also SRHT_CONFIG that IIRC we use in a daemon somewhere…> > TIL. Looks like gitsrht-shell & gitsrht-update-hook do their own> loading, so they would also need a patch. Different repo however, so it> doesn't really affect this patch. Thanks for pointing it out, though!
Yeah. I wonder if it would make sense to unify things a bit and handle
SRHT_CONFIG inside core-go. But that's definitely orthogonal to this
patch.