File tree Expand file tree Collapse file tree 2 files changed +22
-1
lines changed
airflow/providers/google/cloud/utils
tests/providers/google/common/hooks Expand file tree Collapse file tree 2 files changed +22
-1
lines changed Original file line number Diff line number Diff line change @@ -241,7 +241,14 @@ def get_credentials_and_project_id(
241
241
project_id = credentials .project_id
242
242
243
243
if delegate_to :
244
- credentials = credentials .with_subject (delegate_to )
244
+ if hasattr (credentials , 'with_subject' ):
245
+ credentials = credentials .with_subject (delegate_to )
246
+ else :
247
+ raise AirflowException (
248
+ "The `delegate_to` parameter cannot be used here as the current "
249
+ "authentication method does not support account impersonate. "
250
+ "Please use service-account for authorization."
251
+ )
245
252
246
253
return credentials , project_id
247
254
Original file line number Diff line number Diff line change @@ -421,6 +421,20 @@ def test_get_credentials_and_project_id_with_default_auth_and_delegate(
421
421
)
422
422
self .assertEqual ((mock_credentials , "PROJECT_ID" ), result )
423
423
424
+ @mock .patch ('google.auth.default' )
425
+ def test_get_credentials_and_project_id_with_default_auth_and_unsupported_delegate (
426
+ self , mock_auth_default
427
+ ):
428
+ self .instance .delegate_to = "TEST_DELLEGATE_TO"
429
+ mock_credentials = mock .MagicMock (spec = google .auth .compute_engine .Credentials )
430
+ mock_auth_default .return_value = (mock_credentials , "PROJECT_ID" )
431
+
432
+ with self .assertRaisesRegex (AirflowException , re .escape (
433
+ "The `delegate_to` parameter cannot be used here as the current authentication method does not "
434
+ "support account impersonate. Please use service-account for authorization."
435
+ )):
436
+ self .instance ._get_credentials_and_project_id ()
437
+
424
438
@mock .patch ( # type: ignore
425
439
MODULE_NAME + '.get_credentials_and_project_id' ,
426
440
return_value = ("CREDENTIALS" , "PROJECT_ID" )
You can’t perform that action at this time.
0 commit comments