-
-
Notifications
You must be signed in to change notification settings - Fork 60
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
!feat: secure most of api behind api_key
- Loading branch information
Gaisberg
authored and
Gaisberg
committed
Oct 18, 2024
1 parent
8501c36
commit c65d817
Showing
18 changed files
with
457 additions
and
412 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,14 @@ | ||
from fastapi import HTTPException, Security, status | ||
from fastapi.security import APIKeyHeader | ||
from program.settings.manager import settings_manager | ||
|
||
api_key_header = APIKeyHeader(name="x-api-key") | ||
|
||
def resolve_api_key(api_key_header: str = Security(api_key_header)): | ||
if api_key_header == settings_manager.settings.api_key: | ||
return True | ||
else: | ||
raise HTTPException( | ||
status_code=status.HTTP_401_UNAUTHORIZED, | ||
detail="Missing or invalid API key" | ||
) |
This file was deleted.
Oops, something went wrong.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,30 @@ | ||
from auth import resolve_api_key | ||
from fastapi import Depends, Request | ||
from fastapi.routing import APIRouter | ||
from program.settings.manager import settings_manager | ||
from routers.models.shared import RootResponse | ||
from routers.secure.default import router as default_router | ||
from routers.secure.items import router as items_router | ||
from routers.secure.scrape import router as scrape_router | ||
from routers.secure.settings import router as settings_router | ||
from routers.secure.tmdb import router as tmdb_router | ||
from routers.secure.webhooks import router as webooks_router | ||
from routers.secure.ws import router as ws_router | ||
|
||
API_VERSION = "v1" | ||
|
||
app_router = APIRouter(prefix=f"/api/{API_VERSION}") | ||
@app_router.get("/", operation_id="root") | ||
async def root(_: Request) -> RootResponse: | ||
return { | ||
"message": "Riven is running!", | ||
"version": settings_manager.settings.version, | ||
} | ||
|
||
app_router.include_router(default_router, dependencies=[Depends(resolve_api_key)]) | ||
app_router.include_router(items_router, dependencies=[Depends(resolve_api_key)]) | ||
app_router.include_router(scrape_router, dependencies=[Depends(resolve_api_key)]) | ||
app_router.include_router(settings_router, dependencies=[Depends(resolve_api_key)]) | ||
app_router.include_router(tmdb_router, dependencies=[Depends(resolve_api_key)]) | ||
app_router.include_router(webooks_router, dependencies=[Depends(resolve_api_key)]) | ||
app_router.include_router(ws_router, dependencies=[Depends(resolve_api_key)]) |
File renamed without changes.
File renamed without changes.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,8 @@ | ||
from pydantic import BaseModel | ||
|
||
|
||
class MessageResponse(BaseModel): | ||
message: str | ||
|
||
class RootResponse(MessageResponse): | ||
version: str |
Empty file.
Oops, something went wrong.