Skip to content

Commit

Permalink
fix(storage): preserve full Status in default creds (#13897)
Browse files Browse the repository at this point in the history
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.
  • Loading branch information
coryan authored Mar 30, 2024
1 parent dadeb07 commit 1515de3
Show file tree
Hide file tree
Showing 2 changed files with 3 additions and 10 deletions.
9 changes: 1 addition & 8 deletions google/cloud/storage/oauth2/google_credentials.cc
Original file line number Diff line number Diff line change
Expand Up @@ -59,14 +59,7 @@ StatusOr<std::unique_ptr<Credentials>> 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<ServiceAccountCredentials<>>(*info);
Expand Down
4 changes: 2 additions & 2 deletions google/cloud/storage/oauth2/google_credentials_test.cc
Original file line number Diff line number Diff line change
Expand Up @@ -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)));
}
}

Expand Down

0 comments on commit 1515de3

Please sign in to comment.