Testys commited on
Commit
79d1d64
1 Parent(s): 1469fc1

Update core/config.py

Browse files
Files changed (1) hide show
  1. core/config.py +20 -5
core/config.py CHANGED
@@ -2,16 +2,31 @@ import os
2
  from pathlib import Path
3
  from dotenv import load_dotenv
4
  from urllib.parse import quote_plus
5
- from pydantic_settings import BaseSettings
6
 
7
  load_dotenv()
8
 
9
-
10
  class Settings(BaseSettings):
11
- DATABASE_URL = "postgresql://snapfeast_db_owner:[email protected]/snapdb?sslmode=require"
 
 
 
 
 
 
 
 
 
 
 
 
 
12
  JWT_SECRET_KEY: str = os.getenv("JWT_SECRET")
13
  JWT_ALGORITHM: str = os.getenv("JWT_ALGORITHM")
14
- ACCESS_TOKEN_EXPIRE_MINUTES: int = os.getenv("ACCESS_TOKEN")
15
 
16
  def get_settings():
17
- return Settings()
 
 
 
 
2
  from pathlib import Path
3
  from dotenv import load_dotenv
4
  from urllib.parse import quote_plus
5
+ from pydantic import BaseSettings # Make sure this import is correct
6
 
7
  load_dotenv()
8
 
 
9
  class Settings(BaseSettings):
10
+ # Use environment variables to configure the database URL components
11
+ DATABASE_USER: str = os.getenv("PG_USER")
12
+ DATABASE_PASSWORD: str = os.getenv("PG_PASSWORD")
13
+ DATABASE_HOST: str = os.getenv("PG_HOST")
14
+ DATABASE_PORT: str = os.getenv("PG_PORT")
15
+ DATABASE_NAME: str = os.getenv("PG_NAME")
16
+
17
+ # Combine components into the full URL using a property
18
+ @property
19
+ def DATABASE_URL(self) -> str:
20
+ user = quote_plus(self.DATABASE_USER)
21
+ password = quote_plus(self.DATABASE_PASSWORD)
22
+ return f"postgresql://{user}:{password}@{self.DATABASE_HOST}:{self.DATABASE_PORT}/{self.DATABASE_NAME}?sslmode=require"
23
+
24
  JWT_SECRET_KEY: str = os.getenv("JWT_SECRET")
25
  JWT_ALGORITHM: str = os.getenv("JWT_ALGORITHM")
26
+ ACCESS_TOKEN_EXPIRE_MINUTES: int = int(os.getenv("ACCESS_TOKEN_EXPIRE_MINUTES", default="30")) # Default value as fallback
27
 
28
  def get_settings():
29
+ return Settings()
30
+
31
+ # Usage example
32
+ settings = get_settings()