Skip to content

Commit

Permalink
feat: add secrets for frontend to access methods
Browse files Browse the repository at this point in the history
  • Loading branch information
TrueRou committed Dec 7, 2023
1 parent bb1c160 commit f26585a
Show file tree
Hide file tree
Showing 2 changed files with 13 additions and 0 deletions.
4 changes: 4 additions & 0 deletions .env.example
Original file line number Diff line number Diff line change
Expand Up @@ -73,3 +73,7 @@ AUTOMATICALLY_REPORT_PROBLEMS=False
## read through what it enables.
## you could put your server at risk.
DEVELOPER_MODE=False

# secrets settings
TRUSTED_SECRET = ""
LOCAL_ONLY = True
9 changes: 9 additions & 0 deletions app/api/v2/common/secrets.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,9 @@
from fastapi import HTTPException, Request

from app import settings

def validate_secret(request: Request, secret: str | None):
if secret != settings.TRUSTED_SECRET:
raise HTTPException(status_code=403, detail="Invaild secret.")
if settings.LOCAL_ONLY and request.client.host not in ("127.0.0.1", "localhost"):
raise HTTPException(status_code=403, detail="Invaild request.")

0 comments on commit f26585a

Please sign in to comment.