-
Notifications
You must be signed in to change notification settings - Fork 4
/
Copy pathconfig.py
55 lines (43 loc) · 1.67 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
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
from typing import List, Union
from dotenv import load_dotenv
from pydantic import BaseSettings, validator
load_dotenv()
class Settings(BaseSettings):
# BACKEND_CORS_ORIGINS is a JSON-formatted list of origins
BACKEND_CORS_ORIGINS: List[str] = [
"http://localhost:8000",
"https://your-app.com",
]
# allow any localhost port
BACKEND_CORS_ORIGINS_REGEX: str = r"^(http://localhost:\d+|https://your-app\.com)$"
@validator("BACKEND_CORS_ORIGINS", pre=True)
def assemble_cors_origins(cls, v: Union[str, List[str]]) -> Union[List[str], str]:
if isinstance(v, str) and not v.startswith("["):
return [i.strip() for i in v.split(",")]
elif isinstance(v, (list, str)):
return v
raise ValueError(v)
# redis credentials
REDISUSER: str = ""
REDISPASSWORD: str = ""
REDISHOST: str = "localhost"
REDISPORT: str = "6379"
@validator("REDISHOST", "REDISPORT")
def check_redis(cls, v, field):
if not v:
raise ValueError(
f"{field.name} must be defined. For local development, you can use the default value in your .env '{field.name}={field.default}'"
)
return v
LOG_LEVEL: str = "info"
@validator("LOG_LEVEL")
def check_log_level(cls, v, field):
if v not in ["debug", "info", "warning", "error", "critical"]:
raise ValueError(
f"{field.name} must be a standard log level. For local development, you can use the default value in your .env '{field.name}={field.default}'"
)
return v
class Config:
case_sensitive = True
env_file = ".env"
settings = Settings()