mirror of
https://github.com/KohakuBlueleaf/KohakuHub.git
synced 2026-04-28 09:57:43 -05:00
add auth usage in operations
This commit is contained in:
@@ -2,27 +2,7 @@
|
||||
|
||||
Integrates with the new auth system in kohakuhub.auth module.
|
||||
"""
|
||||
|
||||
from ..db import db, User
|
||||
from ..auth.dependencies import (
|
||||
get_current_user as auth_get_current_user,
|
||||
get_current_user,
|
||||
get_optional_user,
|
||||
)
|
||||
|
||||
|
||||
def get_db():
|
||||
"""Database connection dependency for FastAPI."""
|
||||
try:
|
||||
db.connect(reuse_if_open=True)
|
||||
yield db
|
||||
finally:
|
||||
if not db.is_closed():
|
||||
db.close()
|
||||
|
||||
|
||||
def get_current_user():
|
||||
"""Get current authenticated user.
|
||||
|
||||
Now delegates to the real auth system.
|
||||
"""
|
||||
return auth_get_current_user()
|
||||
|
||||
@@ -7,7 +7,7 @@ from lakefs_client.models import RepositoryCreation
|
||||
from pydantic import BaseModel
|
||||
|
||||
from ..config import cfg
|
||||
from ..db import Repository, init_db, File, StagingUpload
|
||||
from ..db import Repository, init_db, File, StagingUpload, User
|
||||
from .auth import get_current_user
|
||||
from .hf_utils import (
|
||||
HFErrorCode,
|
||||
@@ -38,7 +38,7 @@ class CreateRepoPayload(BaseModel):
|
||||
|
||||
|
||||
@router.post("/repos/create")
|
||||
def create_repo(payload: CreateRepoPayload, user=Depends(get_current_user)):
|
||||
def create_repo(payload: CreateRepoPayload, user: User = Depends(get_current_user)):
|
||||
"""Create a new repository.
|
||||
|
||||
Args:
|
||||
@@ -103,7 +103,7 @@ class DeleteRepoPayload(BaseModel):
|
||||
@router.delete("/repos/delete")
|
||||
async def delete_repo(
|
||||
payload: DeleteRepoPayload,
|
||||
user=Depends(get_current_user),
|
||||
user: User = Depends(get_current_user),
|
||||
):
|
||||
"""Delete a repository. (NOTE: This is IRREVERSIBLE)
|
||||
|
||||
|
||||
@@ -12,7 +12,7 @@ from fastapi import APIRouter, Depends, HTTPException, Request, Header
|
||||
from lakefs_client.models import CommitCreation, StagingLocation, StagingMetadata
|
||||
|
||||
from ..config import cfg
|
||||
from ..db import File, Repository, StagingUpload
|
||||
from ..db import File, Repository, StagingUpload, User
|
||||
from .auth import get_current_user
|
||||
from .lakefs_utils import get_lakefs_client, lakefs_repo_name
|
||||
from .s3_utils import get_s3_client
|
||||
@@ -376,7 +376,7 @@ async def commit(
|
||||
name: str,
|
||||
revision: str,
|
||||
request: Request,
|
||||
user=Depends(get_current_user),
|
||||
user: User = Depends(get_current_user),
|
||||
):
|
||||
"""Create atomic commit with multiple file operations.
|
||||
|
||||
@@ -447,7 +447,7 @@ async def commit(
|
||||
content_b64 = value.get("content")
|
||||
encoding = (value.get("encoding") or "").lower()
|
||||
|
||||
if not content_b64 or not encoding.startswith("base64"):
|
||||
if not encoding.startswith("base64"):
|
||||
raise HTTPException(
|
||||
400, detail={"error": f"Invalid file operation for {path}"}
|
||||
)
|
||||
@@ -456,6 +456,7 @@ async def commit(
|
||||
try:
|
||||
data = base64.b64decode(content_b64)
|
||||
except Exception as e:
|
||||
raise e
|
||||
raise HTTPException(
|
||||
400, detail={"error": f"Failed to decode base64: {e}"}
|
||||
)
|
||||
|
||||
@@ -14,6 +14,11 @@ def get_current_user(
|
||||
) -> User:
|
||||
"""Get current authenticated user from session or token."""
|
||||
|
||||
session_id = str(session_id) if session_id is not None else None
|
||||
authorization = str(authorization) if authorization is not None else None
|
||||
|
||||
print(f"session_id: {session_id}, authorization: {authorization}")
|
||||
|
||||
# Try session-based auth first (web UI)
|
||||
if session_id:
|
||||
session = Session.get_or_none(
|
||||
|
||||
Reference in New Issue
Block a user