diff --git a/javascript/build/ee_api_js.js b/javascript/build/ee_api_js.js index 422e36012..367e5aa8b 100644 --- a/javascript/build/ee_api_js.js +++ b/javascript/build/ee_api_js.js @@ -453,7 +453,7 @@ Wc(p,f[m]))});return b?b(l):l};return this.callback?(Ij(d,null,function(f,l){ret Jj.prototype.send=function(a,b){var c=[a.B+" "+a.path+" HTTP/1.1"];c.push("Content-Type: application/json; charset=utf-8");var d=Lj();null!=d&&c.push("Authorization: "+d);a=a.body?JSON.stringify(a.body):"";return[c.join("\r\n")+"\r\n\r\n"+a,b]}; var Mj=function(a,b,c){a=n(b.split("--"+a.split("; boundary=")[1]));for(b=a.next();!b.done;b=a.next())if(b=b.value.split("\r\n\r\n"),!(3>b.length)){var d=b[0].match(/\r\nContent-ID: ]*)>/)[1],e=Number(b[1].match(/^HTTP\S*\s(\d+)\s/)[1]);c(d,e,b.slice(2).join("\r\n\r\n"))}},Gj=function(){var a=Nj.replace(/\/api$/,"");return"window"in r&&!a.match(/^https?:\/\/content-/)?a.replace(/^(https?:\/\/)(.*\.googleapis\.com)$/,"$1content-$2"):a},Pj=function(a,b,c){var d=[];a&&(d=d.concat(Oj)); b&&d.push("https://www.googleapis.com/auth/devstorage.read_write");a=d=d.concat(c);c=b=0;for(var e={};cg)break;z++}return kk(C.status,function(Q){try{return C.getResponseHeader(Q)}catch(oa){return null}},C.responseText,l,void 0,e,d,f)},ik=function(a,b,c,d,e,g,f){var l=0,m={url:a,method:c,content:d,headers:e},p=ck,v=null!=g?g:10; m.callback=function(z){z=z.target;if(429==z.getStatus()&&la.y||a.y>=1< credentials_lib.Credentials: args = oauth.get_credentials_arguments() except IOError: pass + if args.get('refresh_token'): credentials = credentials_lib.Credentials(None, **args) else: # If EE credentials aren't available, try application default credentials. try: - credentials, unused_project_id = google.auth.default() + with warnings.catch_warnings(): + # _default.py gives incorrect advice here: gcloud config set project + # sets the default resource project but we need the quota project. + warnings.filterwarnings('ignore', '.*(No project ID|quota project).*') + + credentials, unused_project_id = google.auth.default() except google.auth.exceptions.DefaultCredentialsError: pass + if credentials: # earthengine set_project always overrides gcloud set-quota-project project = args.get('quota_project_id') or oauth.get_appdefault_project() diff --git a/python/ee/oauth.py b/python/ee/oauth.py index afc924706..3fbabaf47 100644 --- a/python/ee/oauth.py +++ b/python/ee/oauth.py @@ -95,7 +95,11 @@ def get_credentials_arguments() -> Dict[str, Any]: def is_sdk_credentials(credentials: Optional[Any]) -> bool: client = (credentials and getattr(credentials, 'client_id', None)) or '' - return client.split('-')[0] in SDK_PROJECTS + return is_sdk_project(client.split('-')[0]) + + +def is_sdk_project(project: str) -> bool: + return project in SDK_PROJECTS def get_appdefault_project() -> Optional[str]: diff --git a/python/ee/tests/_cloud_api_utils_test.py b/python/ee/tests/_cloud_api_utils_test.py index 860cbca7e..46b503a0f 100644 --- a/python/ee/tests/_cloud_api_utils_test.py +++ b/python/ee/tests/_cloud_api_utils_test.py @@ -22,7 +22,7 @@ def setUp(self): def test_build_cloud_resource(self): base = 'https://earthengine.basetest' - path = '$discovery/rest?version=v1&labels=GOOGLE_INTERNAL&prettyPrint=false' + path = '$discovery/rest?version=v1&prettyPrint=false' def check_build(api, unused_version, **kwargs): self.assertEqual('earthengine', api) self.assertEqual(base + '/' + path, kwargs.get('discoveryServiceUrl')) diff --git a/python/ee/tests/ee_test.py b/python/ee/tests/ee_test.py index fc23155c8..974086585 100644 --- a/python/ee/tests/ee_test.py +++ b/python/ee/tests/ee_test.py @@ -53,47 +53,6 @@ def MockAlgorithms(): self.assertEqual(ee.ApiFunction._api, {}) self.assertFalse(ee.Image._initialized) - def testProjectInitialization(self): - """Verifies that we can fetch the client project from many locations. - - This also exercises the logic in data.get_persistent_credentials. - """ - - cred_args = dict(refresh_token='rt', quota_project_id='qp1') - google_creds = credentials.Credentials(token=None, quota_project_id='qp2') - expected_project = None - - def CheckDataInit(**kwargs): - self.assertEqual(expected_project, kwargs.get('project')) - - moc = mock.patch.object - with (moc(ee.oauth, 'get_credentials_arguments', new=lambda: cred_args), - moc(google.auth, 'default', new=lambda: (google_creds, None)), - moc(ee.data, 'initialize', side_effect=CheckDataInit) as inits): - expected_project = 'qp0' - ee.Initialize(project='qp0') - - expected_project = 'qp1' - ee.Initialize() - - cred_args['refresh_token'] = None - ee.Initialize() - - cred_args['quota_project_id'] = None - expected_project = 'qp2' - ee.Initialize() - - google_creds = google_creds.with_quota_project(None) - expected_project = None - ee.Initialize() - self.assertEqual(5, inits.call_count) - - cred_args['client_id'] = '764086051850-xxx' # dummy usable-auth client - cred_args['refresh_token'] = 'rt' - with self.assertRaisesRegex(ee.EEException, '.*no project found..*'): - ee.Initialize() - self.assertEqual(5, inits.call_count) - def testCallAndApply(self): """Verifies library initialization.""" diff --git a/python/pyproject.toml b/python/pyproject.toml index 4b5fc58a7..045b3c55e 100644 --- a/python/pyproject.toml +++ b/python/pyproject.toml @@ -1,6 +1,6 @@ [project] name = "earthengine-api" -version = "0.1.388" +version = "0.1.389" description = "Earth Engine Python API" requires-python = ">=3.7" keywords = [