mirror of
https://github.com/avatao-content/baseimage-tutorial-framework
synced 2025-06-28 14:25:12 +00:00
Separate the handling of envvars by prefix
This commit is contained in:
9
lib/envvars.py
Normal file
9
lib/envvars.py
Normal file
@ -0,0 +1,9 @@
|
||||
from collections import namedtuple
|
||||
from os import environ
|
||||
|
||||
|
||||
def generate_namedtuple_from_prefixed_envvars(prefix: str, tuple_name: str):
|
||||
envvars = {envvar.replace(prefix, '', 1): environ.get(envvar)
|
||||
for envvar in environ.keys()
|
||||
if envvar.startswith(prefix)}
|
||||
return namedtuple(tuple_name, envvars)(**envvars)
|
0
lib/tao/__init__.py
Normal file
0
lib/tao/__init__.py
Normal file
1
lib/tao/config/__init__.py
Normal file
1
lib/tao/config/__init__.py
Normal file
@ -0,0 +1 @@
|
||||
from .envvars import *
|
3
lib/tao/config/envvars.py
Normal file
3
lib/tao/config/envvars.py
Normal file
@ -0,0 +1,3 @@
|
||||
from envvars import generate_namedtuple_from_prefixed_envvars
|
||||
|
||||
taoenv = generate_namedtuple_from_prefixed_envvars('AVATAO_', 'taoenvtuple')
|
@ -1,10 +1,3 @@
|
||||
from os import environ, getenv
|
||||
from collections import namedtuple
|
||||
from envvars import generate_namedtuple_from_prefixed_envvars
|
||||
|
||||
TFW_PREFIX = 'TFW_'
|
||||
tfwenvvars = {envvar.replace(TFW_PREFIX, '', 1): environ.get(envvar)
|
||||
for envvar in environ.keys()
|
||||
if envvar.startswith(TFW_PREFIX)}
|
||||
tfwenv = namedtuple('tfwenvtuple', tfwenvvars)(**tfwenvvars)
|
||||
|
||||
AVATAO_SECRET = getenv('AVATAO_SECRET', 'secret')
|
||||
tfwenv = generate_namedtuple_from_prefixed_envvars('TFW_', 'tfwenvtuple')
|
||||
|
Reference in New Issue
Block a user