You can not select more than 25 topics Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.

22 lines
827 B

# app/vertex_client.py
from google.oauth2 import service_account
import google.auth.transport.requests
import os
def get_access_token():
# Try environment variable first
creds_path = os.getenv("GOOGLE_APPLICATION_CREDENTIALS")
# Fallback to absolute path
if not creds_path or not os.path.exists(creds_path):
creds_path = r"C:\Users\rithv\OneDrive\Desktop\decision_engine_project\app\service-account.json"
if not os.path.exists(creds_path):
raise FileNotFoundError(f"Service account file not found at: {creds_path}")
credentials = service_account.Credentials.from_service_account_file(
creds_path,
scopes=["https://www.googleapis.com/auth/cloud-platform"]
)
credentials.refresh(google.auth.transport.requests.Request())
return credentials.token