From 1515de3a75f69e80b806ec0eab090006b607c2df Mon Sep 17 00:00:00 2001 From: Carlos O'Ryan Date: Sat, 30 Mar 2024 00:15:42 +0000 Subject: [PATCH] fix(storage): preserve full Status in default creds (#13897) We no longer encourage using `google::cloud::storage::oauth2::GoogleDefaultCredentials()`, but in this case the function was dropping details about an error condition that are probably useful. --- google/cloud/storage/oauth2/google_credentials.cc | 9 +-------- google/cloud/storage/oauth2/google_credentials_test.cc | 4 ++-- 2 files changed, 3 insertions(+), 10 deletions(-) diff --git a/google/cloud/storage/oauth2/google_credentials.cc b/google/cloud/storage/oauth2/google_credentials.cc index 433a7c9351423..d032706ad96e1 100644 --- a/google/cloud/storage/oauth2/google_credentials.cc +++ b/google/cloud/storage/oauth2/google_credentials.cc @@ -59,14 +59,7 @@ StatusOr> LoadCredsFromPath( if (!cred_json.is_object()) { // This is not a JSON file, try to load it as a P12 service account. auto info = ParseServiceAccountP12File(path); - if (!info) { - return Status( - StatusCode::kInvalidArgument, - "Cannot open credentials file " + path + - ", it does not contain a JSON object, nor can be parsed " - "as a PKCS#12 file. " + - info.status().message()); - } + if (!info) return std::move(info).status(); info->subject = std::move(service_account_subject); info->scopes = std::move(service_account_scopes); auto credentials = std::make_unique>(*info); diff --git a/google/cloud/storage/oauth2/google_credentials_test.cc b/google/cloud/storage/oauth2/google_credentials_test.cc index 4d924eb305744..cfdc703bb5c64 100644 --- a/google/cloud/storage/oauth2/google_credentials_test.cc +++ b/google/cloud/storage/oauth2/google_credentials_test.cc @@ -460,8 +460,8 @@ TEST_F(GoogleCredentialsTest, LoadInvalidCredentials) { ScopedEnvironment adc_env_var(GoogleAdcEnvVar(), filename.c_str()); auto creds = GoogleDefaultCredentials(); - EXPECT_THAT(creds, StatusIs(StatusCode::kInvalidArgument, - HasSubstr("credentials file " + filename))); + EXPECT_THAT(creds, + StatusIs(StatusCode::kInvalidArgument, HasSubstr(filename))); } }