19 lines
670 B
Python
19 lines
670 B
Python
import os
|
|
from firebase_admin import credentials, initialize_app, firestore
|
|
|
|
# Load credentials
|
|
_creds = None
|
|
json_inline = os.environ.get("FIREBASE_SERVICE_ACCOUNT_JSON")
|
|
file_path = os.environ.get("GOOGLE_APPLICATION_CREDENTIALS")
|
|
if json_inline:
|
|
_creds = credentials.Certificate(json.loads(json_inline))
|
|
elif file_path and os.path.exists(file_path):
|
|
_creds = credentials.Certificate(file_path)
|
|
else:
|
|
raise RuntimeError("Firebase credentials not configured. Set GOOGLE_APPLICATION_CREDENTIALS or FIREBASE_SERVICE_ACCOUNT_JSON.")
|
|
|
|
# Initialize Firebase Admin SDK
|
|
firebase_admin_app = initialize_app(_creds)
|
|
|
|
# Create Firestore client
|
|
db = firestore.client() |