Skip to content

Commit

Permalink
fix: attempting another fix at impersonating service account (#2081)
Browse files Browse the repository at this point in the history
* Provide an escape hatch for development if the impersonation env
  variable is not set
* Fix default credential fetching
  • Loading branch information
ryscheng authored Sep 6, 2024
1 parent fc28ad3 commit bfc9db3
Showing 1 changed file with 6 additions and 4 deletions.
10 changes: 6 additions & 4 deletions warehouse/oso_dagster/resources/bq_dts.py
Original file line number Diff line number Diff line change
Expand Up @@ -71,17 +71,19 @@ def get_client(self) -> Iterator[DataTransferServiceClient]:
with setup_gcp_creds(self.gcp_credentials):
yield DataTransferServiceClient()

else:
elif impersonate_service_account != "":
# By default, create an impersonated credential for a service account.
# This is necessary to create BigQuery DataTransfer jobs
credentials = auth.default()
credentials, project_id = auth.default()
target_credentials = impersonated_credentials.Credentials(
source_credentials=credentials,
target_principal=impersonate_service_account,
delegates=[],
target_scopes=IMPERSONATE_SCOPES,
lifetime=IMPERSONATE_LIFETIME)
lifetime=IMPERSONATE_LIFETIME
)
yield DataTransferServiceClient(credentials=target_credentials)
else:
yield DataTransferServiceClient()

def get_object_to_set_on_execution_context(self) -> Any:
with self.get_client() as client:
Expand Down

0 comments on commit bfc9db3

Please sign in to comment.