From 9d7d0ee6ca9efb97d19cc1107453a5a54f5786d0 Mon Sep 17 00:00:00 2001 From: jo Date: Fri, 18 Feb 2022 23:33:00 +0100 Subject: [PATCH] feat(shared): create general config model --- shared/libretime_shared/config.py | 19 +++++++++++++++++++ 1 file changed, 19 insertions(+) diff --git a/shared/libretime_shared/config.py b/shared/libretime_shared/config.py index 343f9ac6b..a7d27336e 100644 --- a/shared/libretime_shared/config.py +++ b/shared/libretime_shared/config.py @@ -3,6 +3,7 @@ from configparser import ConfigParser from os import environ from pathlib import Path from typing import Any, Dict, Optional, Union +from urllib.parse import urlunsplit from loguru import logger @@ -98,6 +99,24 @@ class BaseConfig(BaseModel): sys.exit(1) +# pylint: disable=too-few-public-methods +class GeneralConfig(BaseModel): + api_key: str + + protocol: str = "http" + base_url: str = "localhost" + base_port: int = 80 + base_dir: str = "/" + force_ssl: bool = False + + @property + def public_url(self) -> str: + scheme = "https" if self.force_ssl else self.protocol + + url = urlunsplit((scheme, self.base_url, self.base_dir, None, None)) + return url.rstrip("/") + + # pylint: disable=too-few-public-methods class DatabaseConfig(BaseModel): host: str = "localhost"