Skip to content

Commit

Permalink
Remove: .env File
Browse files Browse the repository at this point in the history
  • Loading branch information
XYZLassi committed Mar 10, 2024
1 parent 021722e commit da3fb35
Show file tree
Hide file tree
Showing 9 changed files with 37 additions and 31 deletions.
2 changes: 1 addition & 1 deletion .gitignore
Original file line number Diff line number Diff line change
Expand Up @@ -148,7 +148,7 @@ node_modules/
/flask_session

# Project
**/foo.db
**/*.db
/alembic
alembic.ini
/uploads
Expand Down
12 changes: 7 additions & 5 deletions Dockerfile
Original file line number Diff line number Diff line change
Expand Up @@ -4,12 +4,14 @@ ARG INSTALL_PYTHON_VERSION=3.10
FROM python:${INSTALL_PYTHON_VERSION}-slim-buster as production

WORKDIR /app
COPY requirements requirements
COPY requirements.txt requirements.txt
RUN pip3 install --upgrade pip
RUN pip3 install -r requirements/backend.txt
RUN pip3 install -r requirements/cli.txt
RUN pip3 install -r requirements/data.txt
RUN pip install --no-cache --user -r requirements/data.txt
RUN pip3 install -r requirements.txt

ENV PYTHONUNBUFFERED=1
ENV SECRET_KEY='My-Secret-Key'
ENV DATABASE_URL="sqlite:///./sql_app.db"
ENV CREATE_DB='False'

ENV PYTHONUNBUFFERED=1

Expand Down
8 changes: 7 additions & 1 deletion requirements/backend.txt → requirements.txt
Original file line number Diff line number Diff line change
Expand Up @@ -4,10 +4,16 @@ uvicorn==0.20.0
python-multipart==0.0.5
Pillow==9.4.0
fastapi-camelcase==1.0.5
Werkzeug==2.2.2
strawberry-graphql[fastapi]==0.151.2

# CLI
cmd2~=2.4

# Security
pyjwt==2.6.0

# Database
psycopg2-binary==2.9.5
psycopg2-binary~=2.9
SQLAlchemy==1.4.46
alembic==1.9.1
1 change: 0 additions & 1 deletion requirements/cli.txt

This file was deleted.

10 changes: 0 additions & 10 deletions requirements/data.txt

This file was deleted.

15 changes: 13 additions & 2 deletions src/mylassi_backend/__init__.py
Original file line number Diff line number Diff line change
@@ -1,9 +1,12 @@
__all__ = ['create_app']

from dotenv import load_dotenv
import os

from fastapi import FastAPI, APIRouter
from fastapi.responses import RedirectResponse

from mylassi_data.db import Base, engine

general_router = APIRouter()


Expand All @@ -13,13 +16,21 @@ def index_redirect():


def create_app() -> FastAPI:
load_dotenv('.env')
app = FastAPI(title="MyLassi.xyz - API")

bind(app)

# General
app.include_router(general_router)

from .api import api_v1
app.mount('/api', api_v1)

return app


def bind(app: FastAPI):
@app.on_event("startup")
def on_startup() -> None:
if os.environ.get('CREATE_DB', 'True') == 'True':
Base.metadata.create_all(bind=engine)
14 changes: 7 additions & 7 deletions src/mylassi_backend/api/file.py
Original file line number Diff line number Diff line change
Expand Up @@ -19,7 +19,7 @@

router = APIRouter(tags=['Files'])

upload_path = os.environ['UPLOAD_DIR']
upload_path = os.environ.get('UPLOAD_DIR', 'upload')


def delete_file(file_id: int):
Expand Down Expand Up @@ -56,10 +56,10 @@ def check_file(file_id: int):

def upload_file():
async def upload_file_helper(
file: UploadFile,
task: BackgroundTasks,
session: Session = Depends(get_db),
current_user: UserModel = Depends(get_current_active_user)) -> str:
file: UploadFile,
task: BackgroundTasks,
session: Session = Depends(get_db),
current_user: UserModel = Depends(get_current_active_user)) -> str:

fs_file = FSFileModel()
fs_file.mimetype = mimetypes.guess_type(file.filename)[0]
Expand Down Expand Up @@ -106,8 +106,8 @@ async def upload_file_helper(
@router.post('/files', response_model=FileRestType,
operation_id='uploadFile')
async def upload_file_to_filesystem(
session: Session = Depends(get_db),
file: str = Depends(upload_file())):
session: Session = Depends(get_db),
file: str = Depends(upload_file())):
file = FileModel.get_or_404(session, file)
return file.rest_type()

Expand Down
2 changes: 1 addition & 1 deletion src/mylassi_backend/api/security.py
Original file line number Diff line number Diff line change
Expand Up @@ -18,7 +18,7 @@
from mylassi_data.models import *
from mylassi_data.restschema import *

SECRET_KEY = os.environ['SECRET_KEY']
SECRET_KEY = os.environ.get('SECRET_KEY', 'My-Secret-Key')
ALGORITHM = os.environ.get('ALGORITHM', "HS256")
ACCESS_TOKEN_EXPIRE_MINUTES = int(os.environ.get('ACCESS_TOKEN_EXPIRE_MINUTES', '30'))

Expand Down
4 changes: 1 addition & 3 deletions src/mylassi_data/db.py
Original file line number Diff line number Diff line change
Expand Up @@ -2,13 +2,11 @@

import os

from dotenv import load_dotenv
from sqlalchemy import create_engine, MetaData
from sqlalchemy.ext.declarative import declarative_base
from sqlalchemy.orm import sessionmaker, scoped_session

load_dotenv('.env')
SQLALCHEMY_DATABASE_URL = os.environ['DATABASE_URL']
SQLALCHEMY_DATABASE_URL = os.environ.get('DATABASE_URL', "sqlite:///./sql_app.db")

convention = {
"ix": 'ix_%(column_0_label)s',
Expand Down

0 comments on commit da3fb35

Please sign in to comment.