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
  • Loading branch information
jobegrabber committed Dec 31, 2021
1 parent 83f8e17 commit 4233ebe
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
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
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 4233ebe

Please sign in to comment.