-
Notifications
You must be signed in to change notification settings - Fork 0
/
config.py
40 lines (33 loc) · 1.19 KB
/
config.py
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
import os
from typing import Optional, Any, Dict
from pydantic import BaseSettings, PostgresDsn, validator
class Settings(BaseSettings):
DEBUG: bool
VERSION: str = '0.0.1'
SERVER_NAME: str
PROJECT_NAME: str
API_PREFIX: str = '/api'
STORAGE_DIR: str = 'D:/FILE_STORAGE'
MAIN_PREFIX: str = ''
ALLOWED_HOSTS: str = None
POSTGRES_USER: str
POSTGRES_PASSWORD: str
POSTGRES_DB: str
POSTGRES_HOST: str
POSTGRES_PORT: str
SQLALCHEMY_DATABASE_URI: Optional[PostgresDsn] = None
@validator('SQLALCHEMY_DATABASE_URI', pre=True)
def assemble_db_connection(cls, v: Optional[str],
values: Dict[str, Any]) -> Any:
if isinstance(v, str):
return v
return PostgresDsn.build(
scheme='postgresql+psycopg2',
user=values.get('POSTGRES_USER'),
password=values.get('POSTGRES_PASSWORD'),
host=values.get('POSTGRES_HOST'),
path=f'/{values.get("POSTGRES_DB") or ""}',
port=f'{values.get("POSTGRES_PORT") or ""}',
)
def get_settings():
return Settings(_env_file=os.getenv('ENV_FILE', '../.env'))