mirror of
https://github.com/avatao-content/baseimage-tutorial-framework
synced 2024-11-22 19:31:33 +00:00
Separate the handling of envvars by prefix
This commit is contained in:
parent
2499c4759e
commit
4f181b8f09
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')
|
||||
|
@ -1,7 +1,8 @@
|
||||
from tornado.ioloop import IOLoop
|
||||
from tornado.web import Application
|
||||
|
||||
from tfw.config import tfwenv, AVATAO_SECRET
|
||||
from tao.config import taoenv
|
||||
from tfw.config import tfwenv
|
||||
from handlers import SolutionCheckHandler, TestHandler
|
||||
from tfw.networking.solvable_connector import SolvableConnector
|
||||
|
||||
@ -11,8 +12,8 @@ log = logging.getLogger(__name__)
|
||||
if __name__ == '__main__':
|
||||
solvable_connector = SolvableConnector()
|
||||
routes = [
|
||||
(r'/{secret}/?'.format(secret=AVATAO_SECRET), SolutionCheckHandler, {'solvable_connector': solvable_connector}),
|
||||
(r'/{secret}/test/?'.format(secret=AVATAO_SECRET), TestHandler, {'solvable_connector': solvable_connector})
|
||||
(r'/{secret}/?'.format(secret=taoenv.SECRET), SolutionCheckHandler, {'solvable_connector': solvable_connector}),
|
||||
(r'/{secret}/test/?'.format(secret=taoenv.SECRET), TestHandler, {'solvable_connector': solvable_connector})
|
||||
]
|
||||
app = Application(
|
||||
routes
|
||||
|
Loading…
Reference in New Issue
Block a user