3
0

initial commit

This commit is contained in:
2022-04-04 19:21:51 +02:00
commit d1050d2ee4
34 changed files with 2223 additions and 0 deletions
+34
View File
@@ -0,0 +1,34 @@
from __future__ import annotations
import dataclasses
import os.path
import typing
import yaml
@dataclasses.dataclass
class Config:
controllers: typing.List[str]
secret: str
venue_info_url: typing.Optional[str]
session_timeout: int # in seconds
debug: bool
@staticmethod
def load(filename: typing.Optional[str]=None) -> 'Config':
if filename is None:
for name in ('capport.yaml', '/etc/capport.yaml'):
if os.path.exists(name):
return Config.load(name)
raise RuntimeError("Missing config file")
with open(filename) as f:
data = yaml.safe_load(f)
controllers = list(map(str, data['controllers']))
return Config(
controllers=controllers,
secret=str(data['secret']),
venue_info_url=str(data.get('venue-info-url')),
session_timeout=data.get('session-timeout', 3600),
debug=data.get('debug', False)
)