File size: 1,197 Bytes
571122c
 
 
 
fd26033
571122c
e1c6d87
571122c
f1fbb28
79d1d64
 
 
 
 
 
 
 
 
 
 
 
 
 
571122c
 
79d1d64
571122c
 
79d1d64
 
 
 
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
import os
from pathlib import Path
from dotenv import load_dotenv
from urllib.parse import quote_plus
from pydantic_settings import BaseSettings  # Make sure this import is correct

load_dotenv()

class Settings(BaseSettings):
    # Use environment variables to configure the database URL components
    DATABASE_USER: str = os.getenv("PG_USER")
    DATABASE_PASSWORD: str = os.getenv("PG_PASSWORD")
    DATABASE_HOST: str = os.getenv("PG_HOST")
    DATABASE_PORT: str = os.getenv("PG_PORT")
    DATABASE_NAME: str = os.getenv("PG_NAME")
    
    # Combine components into the full URL using a property
    @property
    def DATABASE_URL(self) -> str:
        user = quote_plus(self.DATABASE_USER)
        password = quote_plus(self.DATABASE_PASSWORD)
        return f"postgresql://{user}:{password}@{self.DATABASE_HOST}:{self.DATABASE_PORT}/{self.DATABASE_NAME}?sslmode=require"

    JWT_SECRET_KEY: str = os.getenv("JWT_SECRET")
    JWT_ALGORITHM: str = os.getenv("JWT_ALGORITHM")
    ACCESS_TOKEN_EXPIRE_MINUTES: int = int(os.getenv("ACCESS_TOKEN_EXPIRE_MINUTES", default="30"))  # Default value as fallback

def get_settings():
    return Settings()

# Usage example
settings = get_settings()