Skip to content

Commit fee6e69

Browse files
committed
fix: add pthe project to the initialize call
1 parent 30efece commit fee6e69

File tree

1 file changed

+5
-9
lines changed

1 file changed

+5
-9
lines changed

geetools/ee_initialize.py

Lines changed: 5 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -3,7 +3,6 @@
33

44
import json
55
import os
6-
import tempfile
76
from pathlib import Path
87

98
import ee
@@ -93,14 +92,11 @@ def from_service_account(private_key: str):
9392
# gather global variable to be modified
9493
global _project_id
9594

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

105101
@staticmethod
106102
def project_id() -> str:

0 commit comments

Comments
 (0)