26 lines
760 B
Python
26 lines
760 B
Python
import yaml
|
|
from fastapi import FastAPI
|
|
|
|
from mash.feature import Feature
|
|
|
|
|
|
class MaSH:
|
|
def __init__(self, config_path: str) -> None:
|
|
self.server: FastAPI = FastAPI()
|
|
self.config: dict = None
|
|
|
|
self._load_config_(config_path)
|
|
|
|
def _load_config_(self, config_path: str) -> None:
|
|
try:
|
|
with open(config_path, "r", encoding="UTF-8") as fp:
|
|
self.config = yaml.safe_load(fp)
|
|
except FileNotFoundError:
|
|
raise f"Config file for MaSH server could not be opened at [{config_path}]."
|
|
|
|
def add_integration(self, feature: Feature) -> None:
|
|
feature.add_routes(self.server)
|
|
self.server.include_router(feature.get_router())
|
|
|
|
def run(self):
|
|
self.server.run()
|