diff --git a/ingestion/src/metadata/utils/credentials.py b/ingestion/src/metadata/utils/credentials.py index 024d3afaf5d..c7e2580ef10 100644 --- a/ingestion/src/metadata/utils/credentials.py +++ b/ingestion/src/metadata/utils/credentials.py @@ -137,12 +137,21 @@ def set_google_credentials(gcp_credentials: GCPCredentials) -> None: os.environ[GOOGLE_CREDENTIALS] = str(gcp_credentials.gcpConfig.root) return - if gcp_credentials.gcpConfig.projectId is None: + if ( + isinstance(gcp_credentials.gcpConfig, GcpCredentialsValues) + and gcp_credentials.gcpConfig.projectId is None + ): logger.info( "No credentials available, using the current environment permissions authenticated via gcloud SDK." ) return + if isinstance(gcp_credentials.gcpConfig, GcpExternalAccount): + logger.info( + "Using External account credentials to authenticate with GCP services." + ) + return + if isinstance(gcp_credentials.gcpConfig, GcpCredentialsValues): if ( gcp_credentials.gcpConfig.projectId diff --git a/ingestion/tests/unit/test_credentials.py b/ingestion/tests/unit/test_credentials.py index 656f3f0d12d..f2c536847cb 100644 --- a/ingestion/tests/unit/test_credentials.py +++ b/ingestion/tests/unit/test_credentials.py @@ -15,6 +15,7 @@ from unittest import TestCase from pydantic import AnyUrl, SecretStr +from metadata.generated.schema.security.credentials.gcpCredentials import GCPCredentials from metadata.generated.schema.security.credentials.gcpExternalAccount import ( GcpExternalAccount, ) @@ -24,7 +25,9 @@ from metadata.generated.schema.security.credentials.gcpValues import ( from metadata.utils.credentials import ( InvalidPrivateKeyException, build_google_credentials_dict, + set_google_credentials, ) +from metadata.utils.logger import Loggers class TestCredentials(TestCase): @@ -105,3 +108,11 @@ VEhPQF0i0tUU7Fl071hcYaiQoZx4nIjN+NG6p5QKbl6k } self.assertEqual(expected_dict, build_google_credentials_dict(gcp_values)) + with self.assertLogs(Loggers.UTILS.value, level="INFO") as log: + set_google_credentials( + GCPCredentials(gcpConfig=gcp_values, gcpImpersonateServiceAccount=None) + ) + self.assertIn( + "Using External account credentials to authenticate with GCP services.", + log.output[0], + )