Skip to content
This repository was archived by the owner on Jul 3, 2026. It is now read-only.

Commit 5bd48e8

Browse files
committed
feat(auth): verification key를 통해 허가된 장소에서만 사용 가능하도록 수정
1 parent 393aa41 commit 5bd48e8

5 files changed

Lines changed: 37 additions & 4 deletions

File tree

‎.github/workflows/deploy.yaml‎

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -29,6 +29,10 @@ jobs:
2929
- name: Login to Amazon ECR
3030
uses: aws-actions/amazon-ecr-login@v2
3131

32+
- name: Create .env from secret
33+
run: |
34+
echo "${{ secrets.ENV }}" > .env
35+
3236
- name: Build and push Docker image
3337
run: |
3438
docker build -t classpick/ocr .

‎.gitignore‎

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,3 +1,4 @@
11
.idea/
22
*.iml
3-
.DS_Store
3+
.DS_Store
4+
.env

‎Pipfile‎

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -11,6 +11,7 @@ paddlepaddle = "*"
1111
opencv-python-headless = "*"
1212
numpy = "*"
1313
python-multipart = "*"
14+
python-dotenv = "*"
1415

1516
[dev-packages]
1617

‎Pipfile.lock‎

Lines changed: 10 additions & 1 deletion
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

‎app.py‎

Lines changed: 20 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,19 +1,37 @@
1+
import os
12
from datetime import datetime, timezone, timedelta
23

34
import cv2
45
import numpy as np
56
import uvicorn
7+
from dotenv import load_dotenv
68
from fastapi import FastAPI, HTTPException, Request
79
from fastapi.exceptions import RequestValidationError
810
from fastapi.responses import JSONResponse
911
from paddleocr import PaddleOCR
1012
from starlette.exceptions import HTTPException as StarletteHTTPException
13+
from starlette.middleware.base import BaseHTTPMiddleware
1114

12-
app = FastAPI(docs_url=None, redoc_url=None, openapi_url=None)
13-
ocr = PaddleOCR(use_angle_cls=True, lang="korean")
15+
load_dotenv()
1416

1517
KST = timezone(timedelta(hours=9))
1618

19+
VERIFICATION_KEY = os.getenv("VERIFICATION_KEY")
20+
21+
ocr = PaddleOCR(use_angle_cls=True, lang="korean")
22+
23+
24+
class VerificationKeyMiddleware(BaseHTTPMiddleware):
25+
async def dispatch(self, request: Request, call_next):
26+
key = request.headers.get("X-CLASSPICK-VERIFICATION-KEY")
27+
if key != VERIFICATION_KEY:
28+
return response(403, error="Invalid verification key")
29+
return await call_next(request)
30+
31+
32+
app = FastAPI(docs_url=None, redoc_url=None, openapi_url=None)
33+
app.add_middleware(VerificationKeyMiddleware)
34+
1735

1836
def response(status_code: int, *, error: str = None, data=None):
1937
return JSONResponse(

0 commit comments

Comments
 (0)