23 lines
No EOL
848 B
Python
23 lines
No EOL
848 B
Python
import json
|
|
from google.oauth2 import service_account
|
|
from google.auth.exceptions import DefaultCredentialsError
|
|
from config import Config
|
|
|
|
def get_google_credentials():
|
|
"""Get Google Cloud credentials based on configuration."""
|
|
credentials = None
|
|
|
|
if Config.SERVICE_ACCOUNT_KEY_PATH:
|
|
try:
|
|
credentials = service_account.Credentials.from_service_account_file(
|
|
Config.SERVICE_ACCOUNT_KEY_PATH,
|
|
scopes=['https://www.googleapis.com/auth/cloud-platform']
|
|
)
|
|
print(f"Using service account key file: {Config.SERVICE_ACCOUNT_KEY_PATH}")
|
|
except Exception as e:
|
|
print(f"Error loading service account file: {e}")
|
|
raise
|
|
else:
|
|
print("Using default credentials (environment variable or gcloud CLI)")
|
|
|
|
return credentials |