Spaces:
Paused
Paused
Commit
·
c86a50e
1
Parent(s):
3d75c7f
fixing project id env variable loading
Browse files- src/auth.py +7 -4
- src/main.py +11 -0
src/auth.py
CHANGED
|
@@ -506,16 +506,19 @@ def onboard_user(creds, project_id):
|
|
| 506 |
def get_user_project_id(creds):
|
| 507 |
"""Gets the user's project ID matching gemini-cli setupUser logic."""
|
| 508 |
global user_project_id
|
| 509 |
-
|
| 510 |
-
|
| 511 |
-
|
| 512 |
-
# Priority 1: Check environment variable first
|
| 513 |
env_project_id = os.getenv("GOOGLE_CLOUD_PROJECT")
|
| 514 |
if env_project_id:
|
| 515 |
logging.info(f"Using project ID from GOOGLE_CLOUD_PROJECT environment variable: {env_project_id}")
|
| 516 |
user_project_id = env_project_id
|
| 517 |
save_credentials(creds, user_project_id)
|
| 518 |
return user_project_id
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 519 |
|
| 520 |
# Priority 2: Check cached project ID in credential file
|
| 521 |
if os.path.exists(CREDENTIAL_FILE):
|
|
|
|
| 506 |
def get_user_project_id(creds):
|
| 507 |
"""Gets the user's project ID matching gemini-cli setupUser logic."""
|
| 508 |
global user_project_id
|
| 509 |
+
|
| 510 |
+
# Priority 1: Check environment variable first (always check, even if user_project_id is set)
|
|
|
|
|
|
|
| 511 |
env_project_id = os.getenv("GOOGLE_CLOUD_PROJECT")
|
| 512 |
if env_project_id:
|
| 513 |
logging.info(f"Using project ID from GOOGLE_CLOUD_PROJECT environment variable: {env_project_id}")
|
| 514 |
user_project_id = env_project_id
|
| 515 |
save_credentials(creds, user_project_id)
|
| 516 |
return user_project_id
|
| 517 |
+
|
| 518 |
+
# If we already have a cached project_id and no env var override, use it
|
| 519 |
+
if user_project_id:
|
| 520 |
+
logging.info(f"Using cached project ID: {user_project_id}")
|
| 521 |
+
return user_project_id
|
| 522 |
|
| 523 |
# Priority 2: Check cached project ID in credential file
|
| 524 |
if os.path.exists(CREDENTIAL_FILE):
|
src/main.py
CHANGED
|
@@ -1,10 +1,21 @@
|
|
| 1 |
import logging
|
|
|
|
| 2 |
from fastapi import FastAPI, Request, Response
|
| 3 |
from fastapi.middleware.cors import CORSMiddleware
|
| 4 |
from .gemini_routes import router as gemini_router
|
| 5 |
from .openai_routes import router as openai_router
|
| 6 |
from .auth import get_credentials, get_user_project_id, onboard_user
|
| 7 |
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 8 |
# Configure logging
|
| 9 |
logging.basicConfig(
|
| 10 |
level=logging.INFO,
|
|
|
|
| 1 |
import logging
|
| 2 |
+
import os
|
| 3 |
from fastapi import FastAPI, Request, Response
|
| 4 |
from fastapi.middleware.cors import CORSMiddleware
|
| 5 |
from .gemini_routes import router as gemini_router
|
| 6 |
from .openai_routes import router as openai_router
|
| 7 |
from .auth import get_credentials, get_user_project_id, onboard_user
|
| 8 |
|
| 9 |
+
# Load environment variables from .env file
|
| 10 |
+
try:
|
| 11 |
+
from dotenv import load_dotenv
|
| 12 |
+
load_dotenv()
|
| 13 |
+
logging.info("Environment variables loaded from .env file")
|
| 14 |
+
except ImportError:
|
| 15 |
+
logging.warning("python-dotenv not installed, .env file will not be loaded automatically")
|
| 16 |
+
except Exception as e:
|
| 17 |
+
logging.warning(f"Could not load .env file: {e}")
|
| 18 |
+
|
| 19 |
# Configure logging
|
| 20 |
logging.basicConfig(
|
| 21 |
level=logging.INFO,
|