~sircmpwn/sr.ht-dev

This thread contains a patchset. You're looking at the original emails, but you may wish to use the patch review UI. Review patch
7 4

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

Details
Message ID
<20231212112608.130916-1-ch@bitfehler.net>
DKIM signature
missing
Download raw message
Patch: +13 -6
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

[core.sr.ht/patches] build failed

builds.sr.ht <builds@sr.ht>
Details
Message ID
<CXMBJT5QYR61.34BS617HXDN09@cirno2>
In-Reply-To
<20231212112608.130916-1-ch@bitfehler.net> (view parent)
DKIM signature
missing
Download raw message
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]: 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
Details
Message ID
<V-ZArustR2uvqpJUSRtbBcOpY35fn-BGW6bPhXiM7Eodb1tK5SB9jm_9zKVLqvvGxONcsFDn85TbS5JskLWX0xRyVh5HjalfkWWDs82CqwQ=@emersion.fr>
In-Reply-To
<20231212112608.130916-1-ch@bitfehler.net> (view parent)
DKIM signature
missing
Download raw message
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…
Details
Message ID
<iMzp89gnMr95kAAOkYhIf-dceLcOaKD5ByfC1CoSJSgK56L2Pef_jaHFWbP5TJ_QscD_wDZCePgyLK-9m_BhDma--h3NuqIcIpAGvY2P73k=@emersion.fr>
In-Reply-To
<V-ZArustR2uvqpJUSRtbBcOpY35fn-BGW6bPhXiM7Eodb1tK5SB9jm_9zKVLqvvGxONcsFDn85TbS5JskLWX0xRyVh5HjalfkWWDs82CqwQ=@emersion.fr> (view parent)
DKIM signature
missing
Download raw message
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"} {
Details
Message ID
<69bc6435-602c-4113-870c-9be220c68d4c@bitfehler.net>
In-Reply-To
<V-ZArustR2uvqpJUSRtbBcOpY35fn-BGW6bPhXiM7Eodb1tK5SB9jm_9zKVLqvvGxONcsFDn85TbS5JskLWX0xRyVh5HjalfkWWDs82CqwQ=@emersion.fr> (view parent)
DKIM signature
missing
Download raw message
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!
Details
Message ID
<P2czw-5VgXmYiSA4UlfT7aZsH9JQn3gxWECYAw7getF6k8wtYFIpvsyHYqmgkCXjQhY8hNizTZKs6I_lOaLn-qglqrnMo5N1j7rpTiaiRe4=@emersion.fr>
In-Reply-To
<69bc6435-602c-4113-870c-9be220c68d4c@bitfehler.net> (view parent)
DKIM signature
missing
Download raw message
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.
Details
Message ID
<CYY19E5IK7CN.38GOJ0DHKM2QZ@bitfehler.net>
In-Reply-To
<20231212112608.130916-1-ch@bitfehler.net> (view parent)
DKIM signature
pass
Download raw message
Merged

to git@git.sr.ht:~sircmpwn/core.sr.ht
  30ca690..bb005f2  master -> master
Details
Message ID
<D0H61DVE1J42.2R9TU2S2BD2SP@cmpwn.com>
In-Reply-To
<20231212112608.130916-1-ch@bitfehler.net> (view parent)
DKIM signature
pass
Download raw message
Thanks!

To git@git.sr.ht:~sircmpwn/core.sr.ht
   8ee2f5b..8c9fb04  master -> master
Reply to thread Export thread (mbox)