Skip to content

Commit

Permalink
Fix setting of project ID in provide_authorized_gcloud (#20428)
Browse files Browse the repository at this point in the history
fixes: #20426 and change in logic introduced (seemingly accidentally) in 2fadf3c
GitOrigin-RevId: 4233ebe5cea4862dbf16c9d7c72c4fdd11db9774
  • Loading branch information
jobegrabber authored and Cloud Composer Team committed Oct 7, 2022
1 parent e7da7c4 commit 29d3e1f
Show file tree
Hide file tree
Showing 2 changed files with 7 additions and 5 deletions.
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

0 comments on commit 29d3e1f

Please sign in to comment.