diff --git a/src/cpp/client/secure_credentials.cc b/src/cpp/client/secure_credentials.cc index 5de5a76194e..ebff8af3e5a 100644 --- a/src/cpp/client/secure_credentials.cc +++ b/src/cpp/client/secure_credentials.cc @@ -23,7 +23,7 @@ #include #include #include -#include +#include #include #include @@ -139,7 +139,8 @@ grpc::Status StsCredentialsOptionsFromJson(const grpc::string& json_string, void operator()(grpc_json* json) { grpc_json_destroy(json); } }; if (options == nullptr) { - return grpc::Status(grpc::INVALID_ARGUMENT, "options cannot be nullptr."); + return grpc::Status(grpc::StatusCode::INVALID_ARGUMENT, + "options cannot be nullptr."); } ClearStsCredentialsOptions(options); std::vector scratchpad(json_string.c_str(), @@ -147,7 +148,7 @@ grpc::Status StsCredentialsOptionsFromJson(const grpc::string& json_string, std::unique_ptr json( grpc_json_parse_string(&scratchpad[0])); if (json == nullptr) { - return grpc::Status(grpc::INVALID_ARGUMENT, "Invalid json."); + return grpc::Status(grpc::StatusCode::INVALID_ARGUMENT, "Invalid json."); } // Required fields. @@ -155,7 +156,7 @@ grpc::Status StsCredentialsOptionsFromJson(const grpc::string& json_string, json.get(), "token_exchange_service_uri", nullptr); if (value == nullptr) { ClearStsCredentialsOptions(options); - return grpc::Status(grpc::INVALID_ARGUMENT, + return grpc::Status(grpc::StatusCode::INVALID_ARGUMENT, "token_exchange_service_uri must be specified."); } options->token_exchange_service_uri.assign(value); @@ -163,7 +164,7 @@ grpc::Status StsCredentialsOptionsFromJson(const grpc::string& json_string, grpc_json_get_string_property(json.get(), "subject_token_path", nullptr); if (value == nullptr) { ClearStsCredentialsOptions(options); - return grpc::Status(grpc::INVALID_ARGUMENT, + return grpc::Status(grpc::StatusCode::INVALID_ARGUMENT, "subject_token_path must be specified."); } options->subject_token_path.assign(value); @@ -171,7 +172,7 @@ grpc::Status StsCredentialsOptionsFromJson(const grpc::string& json_string, grpc_json_get_string_property(json.get(), "subject_token_type", nullptr); if (value == nullptr) { ClearStsCredentialsOptions(options); - return grpc::Status(grpc::INVALID_ARGUMENT, + return grpc::Status(grpc::StatusCode::INVALID_ARGUMENT, "subject_token_type must be specified."); } options->subject_token_type.assign(value); @@ -199,7 +200,8 @@ grpc::Status StsCredentialsOptionsFromJson(const grpc::string& json_string, // Builds STS credentials Options from the $STS_CREDENTIALS env var. grpc::Status StsCredentialsOptionsFromEnv(StsCredentialsOptions* options) { if (options == nullptr) { - return grpc::Status(grpc::INVALID_ARGUMENT, "options cannot be nullptr."); + return grpc::Status(grpc::StatusCode::INVALID_ARGUMENT, + "options cannot be nullptr."); } ClearStsCredentialsOptions(options); grpc_slice json_string = grpc_empty_slice(); @@ -214,13 +216,14 @@ grpc::Status StsCredentialsOptionsFromEnv(StsCredentialsOptions* options) { }; if (sts_creds_path == nullptr) { - status = grpc::Status(grpc::NOT_FOUND, + status = grpc::Status(grpc::StatusCode::NOT_FOUND, "STS_CREDENTIALS environment variable not set."); return cleanup(); } error = grpc_load_file(sts_creds_path, 1, &json_string); if (error != GRPC_ERROR_NONE) { - status = grpc::Status(grpc::NOT_FOUND, grpc_error_string(error)); + status = + grpc::Status(grpc::StatusCode::NOT_FOUND, grpc_error_string(error)); return cleanup(); } status = StsCredentialsOptionsFromJson( diff --git a/test/cpp/client/credentials_test.cc b/test/cpp/client/credentials_test.cc index d560fb6d8e8..ba004efe0d9 100644 --- a/test/cpp/client/credentials_test.cc +++ b/test/cpp/client/credentials_test.cc @@ -119,7 +119,7 @@ TEST_F(CredentialsTest, StsCredentialsOptionsJson) { I'm not a valid JSON. )"; EXPECT_EQ( - grpc::INVALID_ARGUMENT, + grpc::StatusCode::INVALID_ARGUMENT, grpc::experimental::StsCredentialsOptionsFromJson(invalid_json, &options) .error_code()); @@ -130,7 +130,7 @@ TEST_F(CredentialsTest, StsCredentialsOptionsJson) { })"; auto status = grpc::experimental::StsCredentialsOptionsFromJson( invalid_json_missing_subject_token_type, &options); - EXPECT_EQ(grpc::INVALID_ARGUMENT, status.error_code()); + EXPECT_EQ(grpc::StatusCode::INVALID_ARGUMENT, status.error_code()); EXPECT_THAT(status.error_message(), ::testing::HasSubstr("subject_token_type")); @@ -141,7 +141,7 @@ TEST_F(CredentialsTest, StsCredentialsOptionsJson) { })"; status = grpc::experimental::StsCredentialsOptionsFromJson( invalid_json_missing_subject_token_path, &options); - EXPECT_EQ(grpc::INVALID_ARGUMENT, status.error_code()); + EXPECT_EQ(grpc::StatusCode::INVALID_ARGUMENT, status.error_code()); EXPECT_THAT(status.error_message(), ::testing::HasSubstr("subject_token_path")); @@ -152,7 +152,7 @@ TEST_F(CredentialsTest, StsCredentialsOptionsJson) { })"; status = grpc::experimental::StsCredentialsOptionsFromJson( invalid_json_missing_token_exchange_uri, &options); - EXPECT_EQ(grpc::INVALID_ARGUMENT, status.error_code()); + EXPECT_EQ(grpc::StatusCode::INVALID_ARGUMENT, status.error_code()); EXPECT_THAT(status.error_message(), ::testing::HasSubstr("token_exchange_service_uri")); } @@ -162,7 +162,7 @@ TEST_F(CredentialsTest, StsCredentialsOptionsFromEnv) { gpr_unsetenv("STS_CREDENTIALS"); grpc::experimental::StsCredentialsOptions options; auto status = grpc::experimental::StsCredentialsOptionsFromEnv(&options); - EXPECT_EQ(grpc::NOT_FOUND, status.error_code()); + EXPECT_EQ(grpc::StatusCode::NOT_FOUND, status.error_code()); // Set env and check for success. const char valid_json[] = R"(