File tree Expand file tree Collapse file tree 1 file changed +5
-9
lines changed
Expand file tree Collapse file tree 1 file changed +5
-9
lines changed Original file line number Diff line number Diff line change 33
44import json
55import os
6- import tempfile
76from pathlib import Path
87
98import 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 :
You can’t perform that action at this time.
0 commit comments