add missing scopes

This commit is contained in:
Matteo Rosati
2026-01-29 14:40:43 +01:00
parent ead140a2f4
commit da726dc777

7
lib.py
View File

@@ -32,6 +32,9 @@ def get_credentials():
Returns: Returns:
service_account.Credentials: The loaded credentials service_account.Credentials: The loaded credentials
""" """
# OAuth scopes required for Vertex AI API
SCOPES = ["https://www.googleapis.com/auth/cloud-platform"]
# Try to load credentials from JSON content directly # Try to load credentials from JSON content directly
credentials_json = os.getenv("GOOGLE_CREDENTIALS_JSON") credentials_json = os.getenv("GOOGLE_CREDENTIALS_JSON")
@@ -43,7 +46,7 @@ def get_credentials():
logger.info(f"creds JSON parsed: {credentials_info}") logger.info(f"creds JSON parsed: {credentials_info}")
return service_account.Credentials.from_service_account_info( return service_account.Credentials.from_service_account_info(
credentials_info credentials_info, scopes=SCOPES
) )
except json.JSONDecodeError as e: except json.JSONDecodeError as e:
raise ValueError(f"Invalid JSON in GOOGLE_CREDENTIALS_JSON: {e}") raise ValueError(f"Invalid JSON in GOOGLE_CREDENTIALS_JSON: {e}")
@@ -55,7 +58,7 @@ def get_credentials():
if credentials_path and os.path.exists(credentials_path): if credentials_path and os.path.exists(credentials_path):
return service_account.Credentials.from_service_account_file( return service_account.Credentials.from_service_account_file(
credentials_path credentials_path, scopes=SCOPES
) )
# If neither is provided, return None to let the client use default credentials # If neither is provided, return None to let the client use default credentials