Check Store API key (#1693)
* Update Dockerfiles to include user creation and use --user flag for pip install * Add JavaScriptMIMETypeMiddleware to main.py * Update constants.py and run.py files * Update package versions in poetry.lock and pyproject.toml files * Refactor Dockerfile to optimize image building process * Fix import error in main.py * Update Dockerfiles to use logspace/langflow image * Fix decryption error handling in get_user_store_api_key function * Add error logging to JavaScriptMIMETypeMiddleware in main.py * Merge
This commit is contained in:
parent
1a021321a9
commit
06ea4529df
2 changed files with 17 additions and 5 deletions
|
|
@ -2,6 +2,7 @@ from typing import Annotated, List, Optional, Union
|
|||
from uuid import UUID
|
||||
|
||||
from fastapi import APIRouter, Depends, HTTPException, Query
|
||||
from loguru import logger
|
||||
|
||||
from langflow.api.utils import check_langflow_version
|
||||
from langflow.services.auth import utils as auth_utils
|
||||
|
|
@ -27,8 +28,11 @@ def get_user_store_api_key(
|
|||
):
|
||||
if not user.store_api_key:
|
||||
raise HTTPException(status_code=400, detail="You must have a store API key set.")
|
||||
decrypted = auth_utils.decrypt_api_key(user.store_api_key, settings_service)
|
||||
return decrypted
|
||||
try:
|
||||
decrypted = auth_utils.decrypt_api_key(user.store_api_key, settings_service)
|
||||
return decrypted
|
||||
except Exception as e:
|
||||
raise HTTPException(status_code=500, detail="Failed to decrypt API key. Please set a new one.") from e
|
||||
|
||||
|
||||
def get_optional_user_store_api_key(
|
||||
|
|
@ -37,8 +41,12 @@ def get_optional_user_store_api_key(
|
|||
):
|
||||
if not user.store_api_key:
|
||||
return None
|
||||
decrypted = auth_utils.decrypt_api_key(user.store_api_key, settings_service)
|
||||
return decrypted
|
||||
try:
|
||||
decrypted = auth_utils.decrypt_api_key(user.store_api_key, settings_service)
|
||||
return decrypted
|
||||
except Exception as e:
|
||||
logger.error(f"Failed to decrypt API key: {e}")
|
||||
return user.store_api_key
|
||||
|
||||
|
||||
@router.get("/check/")
|
||||
|
|
|
|||
|
|
@ -23,7 +23,11 @@ from langflow.utils.logger import configure
|
|||
|
||||
class JavaScriptMIMETypeMiddleware(BaseHTTPMiddleware):
|
||||
async def dispatch(self, request: Request, call_next):
|
||||
response = await call_next(request)
|
||||
try:
|
||||
response = await call_next(request)
|
||||
except Exception as exc:
|
||||
logger.error(exc)
|
||||
raise exc
|
||||
if "files/" not in request.url.path and request.url.path.endswith(".js") and response.status_code == 200:
|
||||
response.headers["Content-Type"] = "text/javascript"
|
||||
return response
|
||||
|
|
|
|||
Loading…
Add table
Add a link
Reference in a new issue