Skip to content

Commit

Permalink
fix: add pthe project to the initialize call (#426)
Browse files Browse the repository at this point in the history
  • Loading branch information
12rambau authored Jan 30, 2025
2 parents 30efece + fee6e69 commit fb1c82c
Showing 1 changed file with 5 additions and 9 deletions.
14 changes: 5 additions & 9 deletions geetools/ee_initialize.py
Original file line number Diff line number Diff line change
Expand Up @@ -3,7 +3,6 @@

import json
import os
import tempfile
from pathlib import Path

import ee
Expand Down Expand Up @@ -93,14 +92,11 @@ def from_service_account(private_key: str):
# gather global variable to be modified
global _project_id

# connect to GEE using a temp file to avoid writing the key to disk
with tempfile.TemporaryDirectory() as temp_dir:
file = Path(temp_dir) / "private_key.json"
file.write_text(private_key)
ee_user = json.loads(private_key)["client_email"]
_project_id = json.loads(private_key)["project_id"]
credentials = ee.ServiceAccountCredentials(ee_user, str(file))
ee.Initialize(credentials=credentials, http_transport=httplib2.Http())
# connect to GEE using a ServiceAccountCredential object
ee_user = json.loads(private_key)["client_email"]
credentials = ee.ServiceAccountCredentials(ee_user, key_data=private_key)
_project_id = credentials.project_id
ee.Initialize(credentials=credentials, project=_project_id, http_transport=httplib2.Http())

@staticmethod
def project_id() -> str:
Expand Down

0 comments on commit fb1c82c

Please sign in to comment.