-
Notifications
You must be signed in to change notification settings - Fork 1
/
Copy pathconfig.py
71 lines (54 loc) · 2.32 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
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
import os
from typing import List
from dotenv import load_dotenv
from pydantic_settings import BaseSettings
load_dotenv()
class AppConfig(BaseSettings):
"""Base configuration settings."""
# General settings
env: str = os.getenv("ENV", "dev")
api: str = "/api"
prefix: str = "/api/v1"
project_name: str = "APIs Characters"
datetime_format: str = "%Y-%m-%dT%H:%M:%S"
date_format: str = "%Y-%m-%d"
project_root: str = os.path.dirname(os.path.dirname(os.path.dirname(os.path.abspath(__file__))))
# AUTH
secret_key: str = os.getenv("SECRET_KEY")
access_token_expire: int = 60 * 24 * 30 # 60 minutes * 24 hours * 30 days = 30 days
backend_cors_origins: List[str] = ["*"]
# Database settings
engine: str = os.getenv("ENGINE", "postgresql")
user: str = os.getenv("POSTGRES_USER", "postgres")
password: str = os.getenv("POSTGRES_PASSWORD", "password")
database_name: str = os.getenv("POSTGRES_DB", "characters_db")
host: str = os.getenv("POSTGRES_HOST", "localhost")
port: int = int(os.getenv("POSTGRES_PORT", 5432))
database_url: str = f"{engine}://{user}:{password}@{host}:{port}/{database_name}"
rabbit_user: str = os.getenv("RABBITMQ_DEFAULT_USER")
rabbit_pass: str = os.getenv("RABBITMQ_DEFAULT_PASS")
rabbit_host: str = "rabbitmq"
rabbit_url: str = f"amqp://{rabbit_user}:{rabbit_pass}@{rabbit_host}:5672"
characters_queue: str = os.getenv("CHARACTERS_QUEUE")
exchange: str = os.getenv("EXCHANGE")
routing_key: str = os.getenv("ROUTING_KEY")
# SMTP settings
smtp_server: str = os.getenv("SMTP_SERVER", "smtp.example.com")
smtp_port: int = int(os.getenv("SMTP_PORT", 587))
smtp_username: str = os.getenv("SMTP_USERNAME")
smtp_password: str = os.getenv("SMTP_PASSWORD")
# Template and email
template_dir: str = os.getenv("TEMPLATE_DIR")
sendgrid_api_key: str = os.getenv("SENDGRID_API_KEY")
sendgrid_default_sender: str = os.getenv("SENDGRID_DEFAULT_SENDER")
class TestConfig(AppConfig):
"""Test configuration settings."""
env: str = "test"
sqlite_file_name: str = "character.db"
database_url: str = f"sqlite:///{sqlite_file_name}"
def get_settings() -> AppConfig:
env = os.getenv("ENV", "dev")
if env == "test":
return TestConfig()
return AppConfig()
settings = get_settings()