Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Add impersonation_scopes to BigQuery #38169

Merged
merged 10 commits into from
Mar 30, 2024
Merged
Changes from 2 commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
12 changes: 9 additions & 3 deletions airflow/providers/google/common/hooks/base_google.py
Original file line number Diff line number Diff line change
Expand Up @@ -190,6 +190,7 @@ class GoogleBaseHook(BaseHook):
If set as a sequence, the identities from the list must grant
Service Account Token Creator IAM role to the directly preceding identity, with first
account from the list granting this role to the originating account.
:param impersonation_scopes: Optional list of scopes for impersonated account. Will override scopes from connection.
eladkal marked this conversation as resolved.
Show resolved Hide resolved
"""

conn_name_attr = "gcp_conn_id"
Expand Down Expand Up @@ -243,11 +244,13 @@ def __init__(
gcp_conn_id: str = "google_cloud_default",
delegate_to: str | None = None,
impersonation_chain: str | Sequence[str] | None = None,
impersonation_scopes: str | Sequence[str] | None = None,
) -> None:
super().__init__()
self.gcp_conn_id = gcp_conn_id
self.delegate_to = delegate_to
self.impersonation_chain = impersonation_chain
self.impersonation_scopes = impersonation_scopes
self.extras: dict = self.get_connection(self.gcp_conn_id).extra_dejson
self._cached_credentials: google.auth.credentials.Credentials | None = None
self._cached_project_id: str | None = None
Expand Down Expand Up @@ -415,10 +418,13 @@ def scopes(self) -> Sequence[str]:
"""
Return OAuth 2.0 scopes.

:return: Returns the scope defined in the connection configuration, or the default scope
:return: Returns the scope defined in impersonation_scopes, the connection configuration, or the default scope
"""
scope_value: str | None = self._get_field("scope", None)

scope_value: str | None
if self.impersonation_chain and self.impersonation_scopes:
scope_value = ",".join(self.impersonation_scopes)
else:
scope_value = self._get_field("scope", None)
return _get_scopes(scope_value)

@staticmethod
Expand Down
Loading