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

[AIRFLOW-7085] Cache credentials, project_id in GCP Base Hook #7759

Merged
merged 1 commit into from
Mar 19, 2020
Merged
Changes from all 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
8 changes: 8 additions & 0 deletions airflow/providers/google/cloud/hooks/base.py
Original file line number Diff line number Diff line change
Expand Up @@ -141,11 +141,16 @@ def __init__(self, gcp_conn_id: str = 'google_cloud_default', delegate_to: Optio
self.gcp_conn_id = gcp_conn_id
self.delegate_to = delegate_to
self.extras = self.get_connection(self.gcp_conn_id).extra_dejson # type: Dict
self._cached_credentials: Optional[google.auth.credentials.Credentials] = None
self._cached_project_id: Optional[str] = None

def _get_credentials_and_project_id(self) -> Tuple[google.auth.credentials.Credentials, Optional[str]]:
"""
Returns the Credentials object for Google API and the associated project_id
"""
if self._cached_credentials is not None:
return self._cached_credentials, self._cached_project_id

key_path = self._get_field('key_path', None) # type: Optional[str]
keyfile_dict = self._get_field('keyfile_dict', None) # type: Optional[str]
if key_path and keyfile_dict:
Expand Down Expand Up @@ -200,6 +205,9 @@ def _get_credentials_and_project_id(self) -> Tuple[google.auth.credentials.Crede
if overridden_project_id:
project_id = overridden_project_id

self._cached_credentials = credentials
self._cached_project_id = project_id

return credentials, project_id

def _get_credentials(self) -> google.auth.credentials.Credentials:
Expand Down