feat(shared): create general config model
This commit is contained in:
parent
d9852940d6
commit
9d7d0ee6ca
|
@ -3,6 +3,7 @@ from configparser import ConfigParser
|
||||||
from os import environ
|
from os import environ
|
||||||
from pathlib import Path
|
from pathlib import Path
|
||||||
from typing import Any, Dict, Optional, Union
|
from typing import Any, Dict, Optional, Union
|
||||||
|
from urllib.parse import urlunsplit
|
||||||
|
|
||||||
from loguru import logger
|
from loguru import logger
|
||||||
|
|
||||||
|
@ -98,6 +99,24 @@ class BaseConfig(BaseModel):
|
||||||
sys.exit(1)
|
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
|
# pylint: disable=too-few-public-methods
|
||||||
class DatabaseConfig(BaseModel):
|
class DatabaseConfig(BaseModel):
|
||||||
host: str = "localhost"
|
host: str = "localhost"
|
||||||
|
|
Loading…
Reference in New Issue