add api-port and controller-port config options
This commit is contained in:
+19
-8
@@ -1,6 +1,7 @@
|
||||
from __future__ import annotations
|
||||
|
||||
import dataclasses
|
||||
import logging
|
||||
import os.path
|
||||
import typing
|
||||
|
||||
@@ -8,6 +9,7 @@ import yaml
|
||||
|
||||
|
||||
_cached_config: typing.Optional[Config] = None
|
||||
_logger = logging.getLogger(__name__)
|
||||
|
||||
|
||||
@dataclasses.dataclass
|
||||
@@ -19,6 +21,8 @@ class Config:
|
||||
cookie_secret: str
|
||||
venue_info_url: typing.Optional[str]
|
||||
session_timeout: int # in seconds
|
||||
api_port: int
|
||||
controller_port: int
|
||||
debug: bool
|
||||
|
||||
@staticmethod
|
||||
@@ -41,14 +45,21 @@ class Config:
|
||||
raise RuntimeError("Missing config file")
|
||||
with open(filename) as f:
|
||||
data = yaml.safe_load(f)
|
||||
controllers = list(map(str, data['controllers']))
|
||||
return Config(
|
||||
if not isinstance(data, dict):
|
||||
raise RuntimeError(f"Invalid yaml config data, expected dict: {data!r}")
|
||||
controllers = list(map(str, data.pop('controllers')))
|
||||
config = Config(
|
||||
_source_filename=filename,
|
||||
controllers=controllers,
|
||||
server_names=data.get('server-names', []),
|
||||
comm_secret=str(data.get('comm-secret', None) or data['secret']),
|
||||
cookie_secret=str(data['cookie-secret']),
|
||||
venue_info_url=str(data.get('venue-info-url')),
|
||||
session_timeout=data.get('session-timeout', 3600),
|
||||
debug=data.get('debug', False)
|
||||
server_names=data.pop('server-names', []),
|
||||
comm_secret=str(data.pop('comm-secret')),
|
||||
cookie_secret=str(data.pop('cookie-secret')),
|
||||
venue_info_url=str(data.pop('venue-info-url')),
|
||||
session_timeout=data.pop('session-timeout', 3600),
|
||||
api_port=data.pop('api-port', 8000),
|
||||
controller_port=data.pop('controller-port', 5000),
|
||||
debug=data.pop('debug', False)
|
||||
)
|
||||
if data:
|
||||
_logger.error(f"Unknown config elements: {list(data.keys())}")
|
||||
return config
|
||||
|
||||
Reference in New Issue
Block a user