~sircmpwn/sr.ht-dev

core.sr.ht: config: allow spreading config over multiple files v1 APPLIED

Conrad Hoffmann: 1
 config: allow spreading config over multiple files

 1 files changed, 13 insertions(+), 6 deletions(-)
#1113335 alpine.yml success
#1113336 archlinux.yml failed
#1113337 debian.yml success
Export patchset (mbox)
How do I use this?

Copy & paste the following snippet into your terminal to import this patchset into git:

curl -s https://lists.sr.ht/~sircmpwn/sr.ht-dev/patches/47657/mbox | git am -3
Learn more about email & git

[PATCH core.sr.ht] config: allow spreading config over multiple files Export this patch

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 glob
from 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:
            pass

load_config()

-- 
2.43.0
Merged

to git@git.sr.ht:~sircmpwn/core.sr.ht
  30ca690..bb005f2  master -> master
Thanks!

To git@git.sr.ht:~sircmpwn/core.sr.ht
   8ee2f5b..8c9fb04  master -> master
core.sr.ht/patches: FAILED in 3m23s

[config: allow spreading config over multiple files][0] from [Conrad Hoffmann][1]

[0]: https://lists.sr.ht/~sircmpwn/sr.ht-dev/patches/47657
[1]: mailto:ch@bitfehler.net

✓ #1113335 SUCCESS core.sr.ht/patches/alpine.yml    https://builds.sr.ht/~sircmpwn/job/1113335
✓ #1113337 SUCCESS core.sr.ht/patches/debian.yml    https://builds.sr.ht/~sircmpwn/job/1113337
✗ #1113336 FAILED  core.sr.ht/patches/archlinux.yml https://builds.sr.ht/~sircmpwn/job/1113336