-
Notifications
You must be signed in to change notification settings - Fork 1
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Browse files
Browse the repository at this point in the history
- Loading branch information
1 parent
a10e8c4
commit 354bf4c
Showing
4 changed files
with
41 additions
and
29 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
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,7 @@ | ||
from fastapi.security import APIKeyHeader | ||
|
||
# Define the header key | ||
API_KEY_NAME = "X-API-Key" | ||
|
||
# Create a security dependency for API key | ||
api_key_header = APIKeyHeader(name=API_KEY_NAME, auto_error=True) |
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 |
---|---|---|
@@ -1,7 +1,8 @@ | ||
from fastapi import APIRouter, Depends | ||
from sqlalchemy.orm import Session | ||
|
||
from app.api.v1.schemas.user import ApiKeyCreate, ApiKeyResponse, CreditInfo, DetailData, UserPayload, UserResponse | ||
from app.api.deps import api_key_header | ||
from app.api.v1.schemas.user import ApiKeyCreate, ApiKeyResponse, UserResponse | ||
from app.services.user import user_service | ||
from netspresso.utils.db.session import get_db | ||
|
||
|
@@ -16,19 +17,7 @@ def generate_api_key(*, db: Session = Depends(get_db), request_body: ApiKeyCreat | |
|
||
|
||
@router.get("/me", response_model=UserResponse) | ||
def get_user() -> UserResponse: | ||
user = UserPayload( | ||
user_id="e8e8df79-2a62-4562-8e4d-06f51dd795b2", | ||
email="[email protected]", | ||
detail_data=DetailData( | ||
first_name="Byeongman", | ||
last_name="Lee", | ||
company="Nota AI", | ||
), | ||
credit_info=CreditInfo( | ||
free=1000, | ||
total=1000, | ||
), | ||
) | ||
def get_user(*, db: Session = Depends(get_db), api_key: str = Depends(api_key_header)) -> UserResponse: | ||
user = user_service.get_user_info(db=db, api_key=api_key) | ||
|
||
return UserResponse(data=user) |
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 |
---|---|---|
@@ -1,12 +1,6 @@ | ||
import hashlib | ||
|
||
from nanoid import generate | ||
|
||
|
||
def generate_id(entity: str, size: int = 10) -> str: | ||
nano_id = generate(size=size) | ||
return f"{entity}_{nano_id}" | ||
|
||
|
||
def hash_password(password: str) -> str: | ||
return hashlib.sha256(password.encode()).hexdigest() |