Skip to content

Commit

Permalink
disable the use of env file
Browse files Browse the repository at this point in the history
  • Loading branch information
WasinUddy committed Oct 16, 2023
1 parent 21ea5ed commit 9d624bb
Show file tree
Hide file tree
Showing 2 changed files with 10 additions and 19 deletions.
10 changes: 4 additions & 6 deletions app/auth/jwt.py
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,7 @@
auth/jwt.py
This module is responsible for handling JSON Web Tokens (JWT) for user authentication within the FastAPI application.
It utilizes the python-jose library to encode and decode JWT, and python-dotenv to manage environment variables.
It utilizes the python-jose library to encode and decode JWT.
Functions:
- create_access_token: Generates a JWT using user data and expiration details.
Expand All @@ -18,23 +18,21 @@
- datetime: A module to work with dates and times.
- timedelta: A class for representing differences between dates.
- Optional: A special typing construct to denote optional values.
- load_dotenv: A function to load environment variables from a file.
- HTTPException: An exception class for HTTP status codes.
- os: A module providing a way of using operating system dependent functionality.
"""

from jose import JWSError, jwt
from datetime import datetime, timedelta
from typing import Optional
from dotenv import load_dotenv
from fastapi import HTTPException
import os


# Retrieve environment variables related to JWT.
SECRET_KEY = os.getenv("SECRET_KEY")
ALGORITHM = os.getenv("ALGORITHM")
ACCESS_TOKEN_EXPIRE_MINUTES = int(os.getenv("ACCESS_TOKEN_EXPIRE_MINUTES"))
SECRET_KEY = os.environ.get("SECRET_KEY")
ALGORITHM = os.environ.get("ALGORITHM")
ACCESS_TOKEN_EXPIRE_MINUTES = int(os.environ.get("ACCESS_TOKEN_EXPIRE_MINUTES"))

def create_access_token(data: dict) -> str:
"""
Expand Down
19 changes: 6 additions & 13 deletions app/core/db_config.py
Original file line number Diff line number Diff line change
Expand Up @@ -8,8 +8,6 @@
Classes:
- DBConfig: Manages database configuration settings and constructs the SQLAlchemy database URI.
Functions:
- load_dotenv: Loads environment variables from a specified file into the system environment.
Variables:
- POSTGRES_USER: The username used to authenticate with the PostgreSQL database.
Expand All @@ -24,10 +22,9 @@

from pydantic import SecretStr, PostgresDsn
from pydantic_settings import BaseSettings
from dotenv import load_dotenv

# Load environment variables from the specified file.
load_dotenv("environments/db.env")
import os


class DBConfig(BaseSettings):
"""
Expand All @@ -46,17 +43,13 @@ class DBConfig(BaseSettings):
- sqlalchemy_database_uri(self) -> str: Constructs and returns the SQLAlchemy database URI.
"""

POSTGRES_USER: str
POSTGRES_PASSWORD: SecretStr
POSTGRES_HOST: str
POSTGRES_DB: str
POSTGRES_USER: str = os.environ.get("POSTGRES_USER")
POSTGRES_PASSWORD: SecretStr = SecretStr(os.environ.get("POSTGRES_PASSWORD"))
POSTGRES_HOST: str = os.environ.get("POSTGRES_HOST")
POSTGRES_DB: str = os.environ.get("POSTGRES_DB")

SQLALCHEMY_DATABASE_URI: PostgresDsn = "postgresql://none:none@none:5432/none"

class Config:
# Specify the file path for environment variables.
env_file = "environments/db.env"

@property
def sqlalchemy_database_uri(self) -> str:
"""
Expand Down

0 comments on commit 9d624bb

Please sign in to comment.