Spaces:
Sleeping
Sleeping
Create core/security.py
Browse files- src/core/security.py +24 -0
src/core/security.py
ADDED
|
@@ -0,0 +1,24 @@
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 1 |
+
from fastapi import Form, HTTPException
|
| 2 |
+
from src.core.config import DEFAULT_PINECONE_KEY, DEFAULT_CLOUDINARY_URL
|
| 3 |
+
from src.common.utils import get_cloudinary_creds
|
| 4 |
+
|
| 5 |
+
def get_verified_keys(
|
| 6 |
+
user_pinecone_key: str = Form(""),
|
| 7 |
+
user_cloudinary_url: str = Form("")
|
| 8 |
+
) -> dict:
|
| 9 |
+
"""Dependency to extract and validate keys."""
|
| 10 |
+
actual_pc_key = user_pinecone_key or DEFAULT_PINECONE_KEY
|
| 11 |
+
actual_cld_url = user_cloudinary_url or DEFAULT_CLOUDINARY_URL
|
| 12 |
+
|
| 13 |
+
creds = get_cloudinary_creds(actual_cld_url)
|
| 14 |
+
if not creds.get("cloud_name"):
|
| 15 |
+
raise HTTPException(400, "Invalid Cloudinary URL.")
|
| 16 |
+
|
| 17 |
+
if not actual_pc_key:
|
| 18 |
+
raise HTTPException(400, "Pinecone key is missing.")
|
| 19 |
+
|
| 20 |
+
return {
|
| 21 |
+
"pinecone_key": actual_pc_key,
|
| 22 |
+
"cloudinary_url": actual_cld_url,
|
| 23 |
+
"cloudinary_creds": creds
|
| 24 |
+
}
|