Skip to content
Merged
Show file tree
Hide file tree
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: 5 additions & 3 deletions airflow/providers/google/common/hooks/base_google.py
Original file line number Diff line number Diff line change
Expand Up @@ -515,9 +515,6 @@ def provide_authorized_gcloud(self):
f"--key-file={os.environ[CREDENTIALS]}",
]
)
if project_id:
# Don't display stdout/stderr for security reason
check_output(["gcloud", "config", "set", "core/project", project_id])
elif os.path.exists(credentials_path):
# If we are logged in by `gcloud auth application-default` then we need to log in manually.
# This will make the `gcloud auth application-default` and `gcloud auth` credentials equals.
Expand All @@ -539,6 +536,11 @@ def provide_authorized_gcloud(self):
creds_content["refresh_token"],
]
)

if project_id:
# Don't display stdout/stderr for security reason
check_output(["gcloud", "config", "set", "core/project", project_id])

yield

@staticmethod
Expand Down
4 changes: 2 additions & 2 deletions tests/providers/google/common/hooks/test_base_google.py
Original file line number Diff line number Diff line change
Expand Up @@ -742,12 +742,12 @@ def test_provide_authorized_gcloud_via_gcloud_application_default(
# Do nothing
pass

mock_check_output.has_calls(
mock_check_output.assert_has_calls(
[
mock.call(['gcloud', 'config', 'set', 'auth/client_id', 'CLIENT_ID']),
mock.call(['gcloud', 'config', 'set', 'auth/client_secret', 'CLIENT_SECRET']),
mock.call(['gcloud', 'config', 'set', 'core/project', 'PROJECT_ID']),
mock.call(['gcloud', 'auth', 'activate-refresh-token', 'CLIENT_ID', 'REFRESH_TOKEN']),
mock.call(['gcloud', 'config', 'set', 'core/project', 'PROJECT_ID']),
],
any_order=False,
)
Expand Down