From 3a8f4996452e41fccb261189d72d671e2b139409 Mon Sep 17 00:00:00 2001 From: "Mark D. Roth" Date: Thu, 30 Mar 2023 07:13:15 -0700 Subject: [PATCH] [JSON] Rename some accessor methods for consistency (#32740) A bit of cleanup in preparation for making this a public API. --- .../client_channel_service_config.cc | 4 +- .../client_channel/lb_policy/grpclb/grpclb.cc | 4 +- .../outlier_detection/outlier_detection.cc | 7 +- .../lb_policy/priority/priority.cc | 4 +- .../client_channel/lb_policy/rls/rls.cc | 22 ++- .../weighted_target/weighted_target.cc | 4 +- .../lb_policy/xds/xds_cluster_impl.cc | 6 +- .../lb_policy/xds/xds_cluster_manager.cc | 4 +- .../lb_policy/xds/xds_cluster_resolver.cc | 12 +- .../lb_policy/xds/xds_override_host.cc | 6 +- .../lb_policy/xds/xds_wrr_locality.cc | 4 +- .../resolver/dns/c_ares/dns_resolver_ares.cc | 26 ++-- .../client_channel/retry_service_config.cc | 12 +- .../fault_injection_service_config_parser.cc | 2 +- .../rbac/rbac_service_config_parser.cc | 137 +++++++++--------- .../ext/xds/certificate_provider_store.cc | 6 +- ...le_watcher_certificate_provider_factory.cc | 12 +- ...le_mesh_ca_certificate_provider_factory.cc | 12 +- src/core/ext/xds/xds_api.cc | 8 +- src/core/ext/xds/xds_bootstrap_grpc.cc | 13 +- src/core/lib/gprpp/validation_errors.h | 10 +- src/core/lib/json/json.h | 8 +- src/core/lib/json/json_object_loader.cc | 16 +- src/core/lib/json/json_reader.cc | 2 +- src/core/lib/json/json_util.cc | 4 +- src/core/lib/json/json_util.h | 4 +- src/core/lib/json/json_writer.cc | 8 +- .../lib/load_balancing/lb_policy_registry.cc | 8 +- .../security/authorization/rbac_translator.cc | 50 +++---- .../aws_external_account_credentials.cc | 54 ++++--- .../external/external_account_credentials.cc | 97 ++++++------- .../file_external_account_credentials.cc | 28 ++-- .../url_external_account_credentials.cc | 38 ++--- .../security/credentials/jwt/jwt_verifier.cc | 48 +++--- .../credentials/oauth2/oauth2_credentials.cc | 21 ++- src/core/lib/security/util/json_util.cc | 6 +- .../lib/service_config/service_config_impl.cc | 2 +- test/core/channel/channel_trace_test.cc | 6 +- test/core/channel/channelz_test.cc | 37 +++-- test/core/json/json_object_loader_test.cc | 12 +- test/core/json/json_test.cc | 6 +- test/core/security/json_token_test.cc | 22 +-- test/core/util/test_lb_policies.cc | 2 +- test/core/xds/xds_bootstrap_test.cc | 10 +- test/core/xds/xds_client_test.cc | 6 +- 45 files changed, 397 insertions(+), 413 deletions(-) diff --git a/src/core/ext/filters/client_channel/client_channel_service_config.cc b/src/core/ext/filters/client_channel/client_channel_service_config.cc index d37376afd9e..679be210743 100644 --- a/src/core/ext/filters/client_channel/client_channel_service_config.cc +++ b/src/core/ext/filters/client_channel/client_channel_service_config.cc @@ -76,8 +76,8 @@ void ClientChannelGlobalParsedConfig::JsonPostLoad(const Json& json, // Parse LB config. { ValidationErrors::ScopedField field(errors, ".loadBalancingConfig"); - auto it = json.object_value().find("loadBalancingConfig"); - if (it != json.object_value().end()) { + auto it = json.object().find("loadBalancingConfig"); + if (it != json.object().end()) { auto config = lb_policy_registry.ParseLoadBalancingConfig(it->second); if (!config.ok()) { errors->AddError(config.status().message()); diff --git a/src/core/ext/filters/client_channel/lb_policy/grpclb/grpclb.cc b/src/core/ext/filters/client_channel/lb_policy/grpclb/grpclb.cc index 6e35f067886..5256ffaf3c9 100644 --- a/src/core/ext/filters/client_channel/lb_policy/grpclb/grpclb.cc +++ b/src/core/ext/filters/client_channel/lb_policy/grpclb/grpclb.cc @@ -188,8 +188,8 @@ class GrpcLbConfig : public LoadBalancingPolicy::Config { ValidationErrors::ScopedField field(errors, ".childPolicy"); Json child_policy_config_json_tmp; const Json* child_policy_config_json; - auto it = json.object_value().find("childPolicy"); - if (it == json.object_value().end()) { + auto it = json.object().find("childPolicy"); + if (it == json.object().end()) { child_policy_config_json_tmp = Json::Array{Json::Object{ {"round_robin", Json::Object()}, }}; diff --git a/src/core/ext/filters/client_channel/lb_policy/outlier_detection/outlier_detection.cc b/src/core/ext/filters/client_channel/lb_policy/outlier_detection/outlier_detection.cc index e013286e3d0..68337eeba99 100644 --- a/src/core/ext/filters/client_channel/lb_policy/outlier_detection/outlier_detection.cc +++ b/src/core/ext/filters/client_channel/lb_policy/outlier_detection/outlier_detection.cc @@ -1009,8 +1009,8 @@ class OutlierDetectionLbFactory : public LoadBalancingPolicyFactory { // Parse childPolicy manually. { ValidationErrors::ScopedField field(&errors, ".childPolicy"); - auto it = json.object_value().find("childPolicy"); - if (it == json.object_value().end()) { + auto it = json.object().find("childPolicy"); + if (it == json.object().end()) { errors.AddError("field not present"); } else { auto child_policy_config = CoreConfiguration::Get() @@ -1107,8 +1107,7 @@ const JsonLoaderInterface* OutlierDetectionConfig::JsonLoader(const JsonArgs&) { void OutlierDetectionConfig::JsonPostLoad(const Json& json, const JsonArgs&, ValidationErrors* errors) { - if (json.object_value().find("maxEjectionTime") == - json.object_value().end()) { + if (json.object().find("maxEjectionTime") == json.object().end()) { max_ejection_time = std::max(base_ejection_time, Duration::Seconds(300)); } if (max_ejection_percent > 100) { diff --git a/src/core/ext/filters/client_channel/lb_policy/priority/priority.cc b/src/core/ext/filters/client_channel/lb_policy/priority/priority.cc index e5f66e1a493..5d7fe5c5d35 100644 --- a/src/core/ext/filters/client_channel/lb_policy/priority/priority.cc +++ b/src/core/ext/filters/client_channel/lb_policy/priority/priority.cc @@ -853,8 +853,8 @@ void PriorityLbConfig::PriorityLbChild::JsonPostLoad(const Json& json, const JsonArgs&, ValidationErrors* errors) { ValidationErrors::ScopedField field(errors, ".config"); - auto it = json.object_value().find("config"); - if (it == json.object_value().end()) { + auto it = json.object().find("config"); + if (it == json.object().end()) { errors->AddError("field not present"); return; } diff --git a/src/core/ext/filters/client_channel/lb_policy/rls/rls.cc b/src/core/ext/filters/client_channel/lb_policy/rls/rls.cc index 687a7d8fc5c..1f79cc1e81f 100644 --- a/src/core/ext/filters/client_channel/lb_policy/rls/rls.cc +++ b/src/core/ext/filters/client_channel/lb_policy/rls/rls.cc @@ -759,7 +759,7 @@ bool InsertOrUpdateChildPolicyField(const std::string& field, return false; } bool success = true; - for (size_t i = 0; i < config->array_value().size(); ++i) { + for (size_t i = 0; i < config->array().size(); ++i) { Json& child_json = (*config->mutable_array())[i]; ValidationErrors::ScopedField json_field(errors, absl::StrCat("[", i, "]")); if (child_json.type() != Json::Type::OBJECT) { @@ -2333,7 +2333,7 @@ void RlsLbConfig::RouteLookupConfig::JsonPostLoad(const Json& json, ValidationErrors* errors) { // Parse grpcKeybuilders. auto grpc_keybuilders = LoadJsonObjectField>( - json.object_value(), args, "grpcKeybuilders", errors); + json.object(), args, "grpcKeybuilders", errors); if (grpc_keybuilders.has_value()) { ValidationErrors::ScopedField field(errors, ".grpcKeybuilders"); for (size_t i = 0; i < grpc_keybuilders->size(); ++i) { @@ -2378,8 +2378,8 @@ void RlsLbConfig::RouteLookupConfig::JsonPostLoad(const Json& json, // Clamp maxAge to the max allowed value. if (max_age > kMaxMaxAge) max_age = kMaxMaxAge; // If staleAge is set, then maxAge must also be set. - if (json.object_value().find("staleAge") != json.object_value().end() && - json.object_value().find("maxAge") == json.object_value().end()) { + if (json.object().find("staleAge") != json.object().end() && + json.object().find("maxAge") == json.object().end()) { ValidationErrors::ScopedField field(errors, ".maxAge"); errors->AddError("must be set if staleAge is set"); } @@ -2400,8 +2400,7 @@ void RlsLbConfig::RouteLookupConfig::JsonPostLoad(const Json& json, { ValidationErrors::ScopedField field(errors, ".defaultTarget"); if (!errors->FieldHasErrors() && - json.object_value().find("defaultTarget") != - json.object_value().end() && + json.object().find("defaultTarget") != json.object().end() && default_target.empty()) { errors->AddError("must be non-empty if set"); } @@ -2423,8 +2422,8 @@ const JsonLoaderInterface* RlsLbConfig::JsonLoader(const JsonArgs&) { void RlsLbConfig::JsonPostLoad(const Json& json, const JsonArgs&, ValidationErrors* errors) { // Parse routeLookupChannelServiceConfig. - auto it = json.object_value().find("routeLookupChannelServiceConfig"); - if (it != json.object_value().end()) { + auto it = json.object().find("routeLookupChannelServiceConfig"); + if (it != json.object().end()) { ValidationErrors::ScopedField field(errors, ".routeLookupChannelServiceConfig"); // Don't need to save the result here, just need the errors (if any). @@ -2442,8 +2441,8 @@ void RlsLbConfig::JsonPostLoad(const Json& json, const JsonArgs&, // Parse childPolicy. { ValidationErrors::ScopedField field(errors, ".childPolicy"); - auto it = json.object_value().find("childPolicy"); - if (it == json.object_value().end()) { + auto it = json.object().find("childPolicy"); + if (it == json.object().end()) { errors->AddError("field not present"); } else { // Add target to all child policy configs in the list. @@ -2468,8 +2467,7 @@ void RlsLbConfig::JsonPostLoad(const Json& json, const JsonArgs&, // This slightly optimizes what we need to do later when we update // a child policy for a given target. for (Json& config : *(child_policy_config_.mutable_array())) { - if (config.object_value().begin()->first == - (*parsed_config)->name()) { + if (config.object().begin()->first == (*parsed_config)->name()) { Json save_config = std::move(config); child_policy_config_.mutable_array()->clear(); child_policy_config_.mutable_array()->push_back( diff --git a/src/core/ext/filters/client_channel/lb_policy/weighted_target/weighted_target.cc b/src/core/ext/filters/client_channel/lb_policy/weighted_target/weighted_target.cc index 0eb9db32b35..23a63618a13 100644 --- a/src/core/ext/filters/client_channel/lb_policy/weighted_target/weighted_target.cc +++ b/src/core/ext/filters/client_channel/lb_policy/weighted_target/weighted_target.cc @@ -730,8 +730,8 @@ const JsonLoaderInterface* WeightedTargetLbConfig::ChildConfig::JsonLoader( void WeightedTargetLbConfig::ChildConfig::JsonPostLoad( const Json& json, const JsonArgs&, ValidationErrors* errors) { ValidationErrors::ScopedField field(errors, ".childPolicy"); - auto it = json.object_value().find("childPolicy"); - if (it == json.object_value().end()) { + auto it = json.object().find("childPolicy"); + if (it == json.object().end()) { errors->AddError("field not present"); return; } diff --git a/src/core/ext/filters/client_channel/lb_policy/xds/xds_cluster_impl.cc b/src/core/ext/filters/client_channel/lb_policy/xds/xds_cluster_impl.cc index 1f2929108ed..8797f942558 100644 --- a/src/core/ext/filters/client_channel/lb_policy/xds/xds_cluster_impl.cc +++ b/src/core/ext/filters/client_channel/lb_policy/xds/xds_cluster_impl.cc @@ -728,8 +728,8 @@ void XdsClusterImplLbConfig::JsonPostLoad(const Json& json, // Parse "childPolicy" field. { ValidationErrors::ScopedField field(errors, ".childPolicy"); - auto it = json.object_value().find("childPolicy"); - if (it == json.object_value().end()) { + auto it = json.object().find("childPolicy"); + if (it == json.object().end()) { errors->AddError("field not present"); } else { auto lb_config = CoreConfiguration::Get() @@ -745,7 +745,7 @@ void XdsClusterImplLbConfig::JsonPostLoad(const Json& json, // Parse "dropCategories" field. { auto value = LoadJsonObjectField>( - json.object_value(), args, "dropCategories", errors); + json.object(), args, "dropCategories", errors); if (value.has_value()) { drop_config_ = MakeRefCounted(); for (size_t i = 0; i < value->size(); ++i) { diff --git a/src/core/ext/filters/client_channel/lb_policy/xds/xds_cluster_manager.cc b/src/core/ext/filters/client_channel/lb_policy/xds/xds_cluster_manager.cc index ea2a5151130..a00eacf502d 100644 --- a/src/core/ext/filters/client_channel/lb_policy/xds/xds_cluster_manager.cc +++ b/src/core/ext/filters/client_channel/lb_policy/xds/xds_cluster_manager.cc @@ -637,8 +637,8 @@ void XdsClusterManagerLbConfig::Child::JsonPostLoad(const Json& json, const JsonArgs&, ValidationErrors* errors) { ValidationErrors::ScopedField field(errors, ".childPolicy"); - auto it = json.object_value().find("childPolicy"); - if (it == json.object_value().end()) { + auto it = json.object().find("childPolicy"); + if (it == json.object().end()) { errors->AddError("field not present"); return; } diff --git a/src/core/ext/filters/client_channel/lb_policy/xds/xds_cluster_resolver.cc b/src/core/ext/filters/client_channel/lb_policy/xds/xds_cluster_resolver.cc index d3a7209ef4d..6091597415b 100644 --- a/src/core/ext/filters/client_channel/lb_policy/xds/xds_cluster_resolver.cc +++ b/src/core/ext/filters/client_channel/lb_policy/xds/xds_cluster_resolver.cc @@ -1060,8 +1060,8 @@ void XdsClusterResolverLbConfig::DiscoveryMechanism::JsonPostLoad( const Json& json, const JsonArgs& args, ValidationErrors* errors) { // Parse "type". { - auto type_field = LoadJsonObjectField(json.object_value(), - args, "type", errors); + auto type_field = + LoadJsonObjectField(json.object(), args, "type", errors); if (type_field.has_value()) { if (*type_field == "EDS") { type = DiscoveryMechanismType::EDS; @@ -1075,14 +1075,14 @@ void XdsClusterResolverLbConfig::DiscoveryMechanism::JsonPostLoad( } // Parse "edsServiceName" if type is EDS. if (type == DiscoveryMechanismType::EDS) { - auto value = LoadJsonObjectField(json.object_value(), args, + auto value = LoadJsonObjectField(json.object(), args, "edsServiceName", errors, /*required=*/false); if (value.has_value()) eds_service_name = std::move(*value); } // Parse "dnsHostname" if type is LOGICAL_DNS. if (type == DiscoveryMechanismType::LOGICAL_DNS) { - auto value = LoadJsonObjectField(json.object_value(), args, + auto value = LoadJsonObjectField(json.object(), args, "dnsHostname", errors); if (value.has_value()) dns_hostname = std::move(*value); } @@ -1112,8 +1112,8 @@ void XdsClusterResolverLbConfig::JsonPostLoad(const Json& json, const JsonArgs&, // Parse "xdsLbPolicy". { ValidationErrors::ScopedField field(errors, ".xdsLbPolicy"); - auto it = json.object_value().find("xdsLbPolicy"); - if (it == json.object_value().end()) { + auto it = json.object().find("xdsLbPolicy"); + if (it == json.object().end()) { errors->AddError("field not present"); } else { auto lb_config = CoreConfiguration::Get() diff --git a/src/core/ext/filters/client_channel/lb_policy/xds/xds_override_host.cc b/src/core/ext/filters/client_channel/lb_policy/xds/xds_override_host.cc index 4133bed11d0..4f9dea20e65 100644 --- a/src/core/ext/filters/client_channel/lb_policy/xds/xds_override_host.cc +++ b/src/core/ext/filters/client_channel/lb_policy/xds/xds_override_host.cc @@ -777,8 +777,8 @@ void XdsOverrideHostLbConfig::JsonPostLoad(const Json& json, ValidationErrors* errors) { { ValidationErrors::ScopedField field(errors, ".childPolicy"); - auto it = json.object_value().find("childPolicy"); - if (it == json.object_value().end()) { + auto it = json.object().find("childPolicy"); + if (it == json.object().end()) { errors->AddError("field not present"); } else { auto child_policy_config = CoreConfiguration::Get() @@ -794,7 +794,7 @@ void XdsOverrideHostLbConfig::JsonPostLoad(const Json& json, { ValidationErrors::ScopedField field(errors, ".overrideHostStatus"); auto host_status_list = LoadJsonObjectField>( - json.object_value(), args, "overrideHostStatus", errors, + json.object(), args, "overrideHostStatus", errors, /*required=*/false); if (host_status_list.has_value()) { for (size_t i = 0; i < host_status_list->size(); ++i) { diff --git a/src/core/ext/filters/client_channel/lb_policy/xds/xds_wrr_locality.cc b/src/core/ext/filters/client_channel/lb_policy/xds/xds_wrr_locality.cc index 44c86e4e8f9..8841344290a 100644 --- a/src/core/ext/filters/client_channel/lb_policy/xds/xds_wrr_locality.cc +++ b/src/core/ext/filters/client_channel/lb_policy/xds/xds_wrr_locality.cc @@ -86,8 +86,8 @@ class XdsWrrLocalityLbConfig : public LoadBalancingPolicy::Config { void JsonPostLoad(const Json& json, const JsonArgs&, ValidationErrors* errors) { ValidationErrors::ScopedField field(errors, ".childPolicy"); - auto it = json.object_value().find("childPolicy"); - if (it == json.object_value().end()) { + auto it = json.object().find("childPolicy"); + if (it == json.object().end()) { errors->AddError("field not present"); return; } diff --git a/src/core/ext/filters/client_channel/resolver/dns/c_ares/dns_resolver_ares.cc b/src/core/ext/filters/client_channel/resolver/dns/c_ares/dns_resolver_ares.cc index 0291b656a43..663911c0c81 100644 --- a/src/core/ext/filters/client_channel/resolver/dns/c_ares/dns_resolver_ares.cc +++ b/src/core/ext/filters/client_channel/resolver/dns/c_ares/dns_resolver_ares.cc @@ -237,7 +237,7 @@ OrphanablePtr AresClientChannelDNSResolver::StartRequest() { bool ValueInJsonArray(const Json::Array& array, const char* value) { for (const Json& entry : array) { - if (entry.type() == Json::Type::STRING && entry.string_value() == value) { + if (entry.type() == Json::Type::STRING && entry.string() == value) { return true; } } @@ -258,46 +258,46 @@ std::string ChooseServiceConfig(char* service_config_choice_json, } const Json* service_config = nullptr; std::vector error_list; - for (const Json& choice : json->array_value()) { + for (const Json& choice : json->array()) { if (choice.type() != Json::Type::OBJECT) { error_list.push_back(GRPC_ERROR_CREATE( "Service Config Choice, error: should be of type object")); continue; } // Check client language, if specified. - auto it = choice.object_value().find("clientLanguage"); - if (it != choice.object_value().end()) { + auto it = choice.object().find("clientLanguage"); + if (it != choice.object().end()) { if (it->second.type() != Json::Type::ARRAY) { error_list.push_back(GRPC_ERROR_CREATE( "field:clientLanguage error:should be of type array")); - } else if (!ValueInJsonArray(it->second.array_value(), "c++")) { + } else if (!ValueInJsonArray(it->second.array(), "c++")) { continue; } } // Check client hostname, if specified. - it = choice.object_value().find("clientHostname"); - if (it != choice.object_value().end()) { + it = choice.object().find("clientHostname"); + if (it != choice.object().end()) { if (it->second.type() != Json::Type::ARRAY) { error_list.push_back(GRPC_ERROR_CREATE( "field:clientHostname error:should be of type array")); } else { char* hostname = grpc_gethostname(); if (hostname == nullptr || - !ValueInJsonArray(it->second.array_value(), hostname)) { + !ValueInJsonArray(it->second.array(), hostname)) { continue; } } } // Check percentage, if specified. - it = choice.object_value().find("percentage"); - if (it != choice.object_value().end()) { + it = choice.object().find("percentage"); + if (it != choice.object().end()) { if (it->second.type() != Json::Type::NUMBER) { error_list.push_back(GRPC_ERROR_CREATE( "field:percentage error:should be of type number")); } else { int random_pct = rand() % 100; int percentage; - if (sscanf(it->second.string_value().c_str(), "%d", &percentage) != 1) { + if (sscanf(it->second.string().c_str(), "%d", &percentage) != 1) { error_list.push_back(GRPC_ERROR_CREATE( "field:percentage error:should be of type integer")); } else if (random_pct > percentage || percentage == 0) { @@ -306,8 +306,8 @@ std::string ChooseServiceConfig(char* service_config_choice_json, } } // Found service config. - it = choice.object_value().find("serviceConfig"); - if (it == choice.object_value().end()) { + it = choice.object().find("serviceConfig"); + if (it == choice.object().end()) { error_list.push_back(GRPC_ERROR_CREATE( "field:serviceConfig error:required field missing")); } else if (it->second.type() != Json::Type::OBJECT) { diff --git a/src/core/ext/filters/client_channel/retry_service_config.cc b/src/core/ext/filters/client_channel/retry_service_config.cc index 82831ddadb5..3de1161e31f 100644 --- a/src/core/ext/filters/client_channel/retry_service_config.cc +++ b/src/core/ext/filters/client_channel/retry_service_config.cc @@ -56,8 +56,8 @@ const JsonLoaderInterface* RetryGlobalConfig::JsonLoader(const JsonArgs&) { void RetryGlobalConfig::JsonPostLoad(const Json& json, const JsonArgs& args, ValidationErrors* errors) { // Parse maxTokens. - auto max_tokens = LoadJsonObjectField(json.object_value(), args, - "maxTokens", errors); + auto max_tokens = + LoadJsonObjectField(json.object(), args, "maxTokens", errors); if (max_tokens.has_value()) { ValidationErrors::ScopedField field(errors, ".maxTokens"); if (*max_tokens == 0) { @@ -69,8 +69,8 @@ void RetryGlobalConfig::JsonPostLoad(const Json& json, const JsonArgs& args, } // Parse tokenRatio. ValidationErrors::ScopedField field(errors, ".tokenRatio"); - auto it = json.object_value().find("tokenRatio"); - if (it == json.object_value().end()) { + auto it = json.object().find("tokenRatio"); + if (it == json.object().end()) { errors->AddError("field not present"); return; } @@ -79,7 +79,7 @@ void RetryGlobalConfig::JsonPostLoad(const Json& json, const JsonArgs& args, errors->AddError("is not a number"); return; } - absl::string_view buf = it->second.string_value(); + absl::string_view buf = it->second.string(); uint32_t multiplier = 1; uint32_t decimal_value = 0; auto decimal_point = buf.find('.'); @@ -171,7 +171,7 @@ void RetryMethodConfig::JsonPostLoad(const Json& json, const JsonArgs& args, } // Parse retryableStatusCodes. auto status_code_list = LoadJsonObjectField>( - json.object_value(), args, "retryableStatusCodes", errors, + json.object(), args, "retryableStatusCodes", errors, /*required=*/false); if (status_code_list.has_value()) { for (size_t i = 0; i < status_code_list->size(); ++i) { diff --git a/src/core/ext/filters/fault_injection/fault_injection_service_config_parser.cc b/src/core/ext/filters/fault_injection/fault_injection_service_config_parser.cc index cf7352957b0..9e12ce0b093 100644 --- a/src/core/ext/filters/fault_injection/fault_injection_service_config_parser.cc +++ b/src/core/ext/filters/fault_injection/fault_injection_service_config_parser.cc @@ -58,7 +58,7 @@ void FaultInjectionMethodParsedConfig::FaultInjectionPolicy::JsonPostLoad( const Json& json, const JsonArgs& args, ValidationErrors* errors) { // Parse abort_code. auto abort_code_string = LoadJsonObjectField( - json.object_value(), args, "abortCode", errors, /*required=*/false); + json.object(), args, "abortCode", errors, /*required=*/false); if (abort_code_string.has_value() && !grpc_status_code_from_string(abort_code_string->c_str(), &abort_code)) { ValidationErrors::ScopedField field(errors, ".abortCode"); diff --git a/src/core/ext/filters/rbac/rbac_service_config_parser.cc b/src/core/ext/filters/rbac/rbac_service_config_parser.cc index a598fbc57df..38a5d799336 100644 --- a/src/core/ext/filters/rbac/rbac_service_config_parser.cc +++ b/src/core/ext/filters/rbac/rbac_service_config_parser.cc @@ -219,10 +219,10 @@ RbacConfig::RbacPolicy::Rules::Policy::CidrRange::JsonLoader(const JsonArgs&) { void RbacConfig::RbacPolicy::Rules::Policy::CidrRange::JsonPostLoad( const Json& json, const JsonArgs& args, ValidationErrors* errors) { auto address_prefix = LoadJsonObjectField( - json.object_value(), args, "addressPrefix", errors); - auto prefix_len = LoadJsonObjectField(json.object_value(), args, - "prefixLen", errors, - /*required=*/false); + json.object(), args, "addressPrefix", errors); + auto prefix_len = + LoadJsonObjectField(json.object(), args, "prefixLen", errors, + /*required=*/false); cidr_range = Rbac::CidrRange(address_prefix.value_or(""), prefix_len.value_or(0)); } @@ -269,13 +269,13 @@ RbacConfig::RbacPolicy::Rules::Policy::HeaderMatch::JsonLoader( void RbacConfig::RbacPolicy::Rules::Policy::HeaderMatch::JsonPostLoad( const Json& json, const JsonArgs& args, ValidationErrors* errors) { const size_t original_error_size = errors->size(); - std::string name = LoadJsonObjectField(json.object_value(), args, - "name", errors) - .value_or(""); - bool invert_match = LoadJsonObjectField(json.object_value(), args, - "invertMatch", errors, - /*required=*/false) - .value_or(false); + std::string name = + LoadJsonObjectField(json.object(), args, "name", errors) + .value_or(""); + bool invert_match = + LoadJsonObjectField(json.object(), args, "invertMatch", errors, + /*required=*/false) + .value_or(false); auto set_header_matcher = [&](absl::StatusOr header_matcher) { if (header_matcher.ok()) { matcher = *header_matcher; @@ -285,7 +285,7 @@ void RbacConfig::RbacPolicy::Rules::Policy::HeaderMatch::JsonPostLoad( }; auto check_match = [&](absl::string_view field_name, HeaderMatcher::Type type) { - auto match = LoadJsonObjectField(json.object_value(), args, + auto match = LoadJsonObjectField(json.object(), args, field_name, errors, /*required=*/false); if (match.has_value()) { @@ -301,9 +301,9 @@ void RbacConfig::RbacPolicy::Rules::Policy::HeaderMatch::JsonPostLoad( check_match("containsMatch", HeaderMatcher::Type::kContains)) { return; } - auto present_match = LoadJsonObjectField(json.object_value(), args, - "presentMatch", errors, - /*required=*/false); + auto present_match = + LoadJsonObjectField(json.object(), args, "presentMatch", errors, + /*required=*/false); if (present_match.has_value()) { set_header_matcher( HeaderMatcher::Create(name, HeaderMatcher::Type::kPresent, "", 0, 0, @@ -311,7 +311,7 @@ void RbacConfig::RbacPolicy::Rules::Policy::HeaderMatch::JsonPostLoad( return; } auto regex_match = LoadJsonObjectField( - json.object_value(), args, "safeRegexMatch", errors, + json.object(), args, "safeRegexMatch", errors, /*required=*/false); if (regex_match.has_value()) { set_header_matcher( @@ -319,9 +319,9 @@ void RbacConfig::RbacPolicy::Rules::Policy::HeaderMatch::JsonPostLoad( regex_match->regex, 0, 0, false, invert_match)); return; } - auto range_match = LoadJsonObjectField(json.object_value(), args, - "rangeMatch", errors, - /*required=*/false); + auto range_match = + LoadJsonObjectField(json.object(), args, "rangeMatch", errors, + /*required=*/false); if (range_match.has_value()) { set_header_matcher(HeaderMatcher::Create(name, HeaderMatcher::Type::kRange, "", range_match->start, @@ -349,7 +349,7 @@ void RbacConfig::RbacPolicy::Rules::Policy::StringMatch::JsonPostLoad( const Json& json, const JsonArgs& args, ValidationErrors* errors) { const size_t original_error_size = errors->size(); bool ignore_case = - LoadJsonObjectField(json.object_value(), args, "ignoreCase", errors, + LoadJsonObjectField(json.object(), args, "ignoreCase", errors, /*required=*/false) .value_or(false); auto set_string_matcher = [&](absl::StatusOr string_matcher) { @@ -361,7 +361,7 @@ void RbacConfig::RbacPolicy::Rules::Policy::StringMatch::JsonPostLoad( }; auto check_match = [&](absl::string_view field_name, StringMatcher::Type type) { - auto match = LoadJsonObjectField(json.object_value(), args, + auto match = LoadJsonObjectField(json.object(), args, field_name, errors, /*required=*/false); if (match.has_value()) { @@ -376,9 +376,9 @@ void RbacConfig::RbacPolicy::Rules::Policy::StringMatch::JsonPostLoad( check_match("contains", StringMatcher::Type::kContains)) { return; } - auto regex_match = LoadJsonObjectField( - json.object_value(), args, "safeRegex", errors, - /*required=*/false); + auto regex_match = LoadJsonObjectField(json.object(), args, + "safeRegex", errors, + /*required=*/false); if (regex_match.has_value()) { set_string_matcher(StringMatcher::Create(StringMatcher::Type::kSafeRegex, regex_match->regex, ignore_case)); @@ -450,32 +450,32 @@ RbacConfig::RbacPolicy::Rules::Policy::Permission::JsonLoader(const JsonArgs&) { void RbacConfig::RbacPolicy::Rules::Policy::Permission::JsonPostLoad( const Json& json, const JsonArgs& args, ValidationErrors* errors) { const size_t original_error_size = errors->size(); - auto any = LoadJsonObjectField(json.object_value(), args, "any", errors, + auto any = LoadJsonObjectField(json.object(), args, "any", errors, /*required=*/false); if (any.has_value()) { permission = std::make_unique( Rbac::Permission::MakeAnyPermission()); return; } - auto header = LoadJsonObjectField(json.object_value(), args, - "header", errors, - /*required=*/false); + auto header = + LoadJsonObjectField(json.object(), args, "header", errors, + /*required=*/false); if (header.has_value()) { permission = std::make_unique( Rbac::Permission::MakeHeaderPermission(std::move(header->matcher))); return; } - auto url_path = LoadJsonObjectField(json.object_value(), args, - "urlPath", errors, - /*required=*/false); + auto url_path = + LoadJsonObjectField(json.object(), args, "urlPath", errors, + /*required=*/false); if (url_path.has_value()) { permission = std::make_unique( Rbac::Permission::MakePathPermission(url_path->path.matcher)); return; } - auto destination_ip = LoadJsonObjectField( - json.object_value(), args, "destinationIp", errors, - /*required=*/false); + auto destination_ip = LoadJsonObjectField(json.object(), args, + "destinationIp", errors, + /*required=*/false); if (destination_ip.has_value()) { permission = std::make_unique( Rbac::Permission::MakeDestIpPermission( @@ -483,23 +483,23 @@ void RbacConfig::RbacPolicy::Rules::Policy::Permission::JsonPostLoad( return; } auto destination_port = LoadJsonObjectField( - json.object_value(), args, "destinationPort", errors, + json.object(), args, "destinationPort", errors, /*required=*/false); if (destination_port.has_value()) { permission = std::make_unique( Rbac::Permission::MakeDestPortPermission(*destination_port)); return; } - auto metadata = LoadJsonObjectField(json.object_value(), args, - "metadata", errors, - /*required=*/false); + auto metadata = + LoadJsonObjectField(json.object(), args, "metadata", errors, + /*required=*/false); if (metadata.has_value()) { permission = std::make_unique( Rbac::Permission::MakeMetadataPermission(metadata->invert)); return; } auto requested_server_name = LoadJsonObjectField( - json.object_value(), args, "requestedServerName", errors, + json.object(), args, "requestedServerName", errors, /*required=*/false); if (requested_server_name.has_value()) { permission = std::make_unique( @@ -507,7 +507,7 @@ void RbacConfig::RbacPolicy::Rules::Policy::Permission::JsonPostLoad( std::move(requested_server_name->matcher))); return; } - auto rules = LoadJsonObjectField(json.object_value(), args, + auto rules = LoadJsonObjectField(json.object(), args, "andRules", errors, /*required=*/false); if (rules.has_value()) { @@ -516,8 +516,8 @@ void RbacConfig::RbacPolicy::Rules::Policy::Permission::JsonPostLoad( MakeRbacPermissionList(std::move(rules->rules)))); return; } - rules = LoadJsonObjectField(json.object_value(), args, - "orRules", errors, + rules = LoadJsonObjectField(json.object(), args, "orRules", + errors, /*required=*/false); if (rules.has_value()) { permission = @@ -525,9 +525,9 @@ void RbacConfig::RbacPolicy::Rules::Policy::Permission::JsonPostLoad( MakeRbacPermissionList(std::move(rules->rules)))); return; } - auto not_rule = LoadJsonObjectField(json.object_value(), args, - "notRule", errors, - /*required=*/false); + auto not_rule = + LoadJsonObjectField(json.object(), args, "notRule", errors, + /*required=*/false); if (not_rule.has_value()) { permission = std::make_unique( Rbac::Permission::MakeNotPermission(std::move(*not_rule->permission))); @@ -590,7 +590,7 @@ RbacConfig::RbacPolicy::Rules::Policy::Principal::JsonLoader(const JsonArgs&) { void RbacConfig::RbacPolicy::Rules::Policy::Principal::JsonPostLoad( const Json& json, const JsonArgs& args, ValidationErrors* errors) { const size_t original_error_size = errors->size(); - auto any = LoadJsonObjectField(json.object_value(), args, "any", errors, + auto any = LoadJsonObjectField(json.object(), args, "any", errors, /*required=*/false); if (any.has_value()) { principal = @@ -598,7 +598,7 @@ void RbacConfig::RbacPolicy::Rules::Policy::Principal::JsonPostLoad( return; } auto authenticated = LoadJsonObjectField( - json.object_value(), args, "authenticated", errors, + json.object(), args, "authenticated", errors, /*required=*/false); if (authenticated.has_value()) { if (authenticated->principal_name.has_value()) { @@ -612,16 +612,16 @@ void RbacConfig::RbacPolicy::Rules::Policy::Principal::JsonPostLoad( } return; } - auto cidr_range = LoadJsonObjectField(json.object_value(), args, - "sourceIp", errors, - /*required=*/false); + auto cidr_range = + LoadJsonObjectField(json.object(), args, "sourceIp", errors, + /*required=*/false); if (cidr_range.has_value()) { principal = std::make_unique( Rbac::Principal::MakeSourceIpPrincipal( std::move(cidr_range->cidr_range))); return; } - cidr_range = LoadJsonObjectField(json.object_value(), args, + cidr_range = LoadJsonObjectField(json.object(), args, "directRemoteIp", errors, /*required=*/false); if (cidr_range.has_value()) { @@ -630,50 +630,49 @@ void RbacConfig::RbacPolicy::Rules::Policy::Principal::JsonPostLoad( std::move(cidr_range->cidr_range))); return; } - cidr_range = LoadJsonObjectField(json.object_value(), args, - "remoteIp", errors, - /*required=*/false); + cidr_range = + LoadJsonObjectField(json.object(), args, "remoteIp", errors, + /*required=*/false); if (cidr_range.has_value()) { principal = std::make_unique( Rbac::Principal::MakeRemoteIpPrincipal( std::move(cidr_range->cidr_range))); return; } - auto header = LoadJsonObjectField(json.object_value(), args, - "header", errors, - /*required=*/false); + auto header = + LoadJsonObjectField(json.object(), args, "header", errors, + /*required=*/false); if (header.has_value()) { principal = std::make_unique( Rbac::Principal::MakeHeaderPrincipal(std::move(header->matcher))); return; } - auto url_path = LoadJsonObjectField(json.object_value(), args, - "urlPath", errors, - /*required=*/false); + auto url_path = + LoadJsonObjectField(json.object(), args, "urlPath", errors, + /*required=*/false); if (url_path.has_value()) { principal = std::make_unique( Rbac::Principal::MakePathPrincipal(std::move(url_path->path.matcher))); return; } - auto metadata = LoadJsonObjectField(json.object_value(), args, - "metadata", errors, - /*required=*/false); + auto metadata = + LoadJsonObjectField(json.object(), args, "metadata", errors, + /*required=*/false); if (metadata.has_value()) { principal = std::make_unique( Rbac::Principal::MakeMetadataPrincipal(metadata->invert)); return; } - auto ids = LoadJsonObjectField(json.object_value(), args, - "andIds", errors, - /*required=*/false); + auto ids = + LoadJsonObjectField(json.object(), args, "andIds", errors, + /*required=*/false); if (ids.has_value()) { principal = std::make_unique(Rbac::Principal::MakeAndPrincipal( MakeRbacPrincipalList(std::move(ids->ids)))); return; } - ids = LoadJsonObjectField(json.object_value(), args, "orIds", - errors, + ids = LoadJsonObjectField(json.object(), args, "orIds", errors, /*required=*/false); if (ids.has_value()) { principal = @@ -682,7 +681,7 @@ void RbacConfig::RbacPolicy::Rules::Policy::Principal::JsonPostLoad( return; } auto not_rule = - LoadJsonObjectField(json.object_value(), args, "notId", errors, + LoadJsonObjectField(json.object(), args, "notId", errors, /*required=*/false); if (not_rule.has_value()) { principal = std::make_unique( diff --git a/src/core/ext/xds/certificate_provider_store.cc b/src/core/ext/xds/certificate_provider_store.cc index 96d6ee551b8..9720cf64e44 100644 --- a/src/core/ext/xds/certificate_provider_store.cc +++ b/src/core/ext/xds/certificate_provider_store.cc @@ -61,16 +61,16 @@ void CertificateProviderStore::PluginDefinition::JsonPostLoad( // Parse the config field. { ValidationErrors::ScopedField field(errors, ".config"); - auto it = json.object_value().find("config"); + auto it = json.object().find("config"); // The config field is optional; if not present, we use an empty JSON // object. Json::Object config_json; - if (it != json.object_value().end()) { + if (it != json.object().end()) { if (it->second.type() != Json::Type::OBJECT) { errors->AddError("is not an object"); return; // No point parsing config. } else { - config_json = it->second.object_value(); + config_json = it->second.object(); } } if (factory == nullptr) return; diff --git a/src/core/ext/xds/file_watcher_certificate_provider_factory.cc b/src/core/ext/xds/file_watcher_certificate_provider_factory.cc index 6f9613d7fa2..376d5655688 100644 --- a/src/core/ext/xds/file_watcher_certificate_provider_factory.cc +++ b/src/core/ext/xds/file_watcher_certificate_provider_factory.cc @@ -80,9 +80,9 @@ FileWatcherCertificateProviderFactory::Config::Parse(const Json& config_json, return nullptr; } std::vector error_list; - ParseJsonObjectField(config_json.object_value(), "certificate_file", + ParseJsonObjectField(config_json.object(), "certificate_file", &config->identity_cert_file_, &error_list, false); - ParseJsonObjectField(config_json.object_value(), "private_key_file", + ParseJsonObjectField(config_json.object(), "private_key_file", &config->private_key_file_, &error_list, false); if (config->identity_cert_file_.empty() != config->private_key_file_.empty()) { @@ -90,16 +90,16 @@ FileWatcherCertificateProviderFactory::Config::Parse(const Json& config_json, "fields \"certificate_file\" and \"private_key_file\" must be both set " "or both unset.")); } - ParseJsonObjectField(config_json.object_value(), "ca_certificate_file", + ParseJsonObjectField(config_json.object(), "ca_certificate_file", &config->root_cert_file_, &error_list, false); if (config->identity_cert_file_.empty() && config->root_cert_file_.empty()) { error_list.push_back(GRPC_ERROR_CREATE( "At least one of \"certificate_file\" and \"ca_certificate_file\" must " "be specified.")); } - if (!ParseJsonObjectFieldAsDuration( - config_json.object_value(), "refresh_interval", - &config->refresh_interval_, &error_list, false)) { + if (!ParseJsonObjectFieldAsDuration(config_json.object(), "refresh_interval", + &config->refresh_interval_, &error_list, + false)) { config->refresh_interval_ = Duration::Minutes(10); // 10 minutes default } if (!error_list.empty()) { diff --git a/src/core/ext/xds/google_mesh_ca_certificate_provider_factory.cc b/src/core/ext/xds/google_mesh_ca_certificate_provider_factory.cc index e7e3f9c9b4e..d37eb3ea00e 100644 --- a/src/core/ext/xds/google_mesh_ca_certificate_provider_factory.cc +++ b/src/core/ext/xds/google_mesh_ca_certificate_provider_factory.cc @@ -197,7 +197,7 @@ GoogleMeshCaCertificateProviderFactory::Config::Parse( } std::vector error_list; const Json::Object* server = nullptr; - if (ParseJsonObjectField(config_json.object_value(), "server", &server, + if (ParseJsonObjectField(config_json.object(), "server", &server, &error_list)) { std::vector error_list_server = config->ParseJsonObjectServer(*server); @@ -207,28 +207,28 @@ GoogleMeshCaCertificateProviderFactory::Config::Parse( } } if (!ParseJsonObjectFieldAsDuration( - config_json.object_value(), "certificate_lifetime", + config_json.object(), "certificate_lifetime", &config->certificate_lifetime_, &error_list, false)) { config->certificate_lifetime_ = Duration::Hours(24); // 24hrs default } if (!ParseJsonObjectFieldAsDuration( - config_json.object_value(), "renewal_grace_period", + config_json.object(), "renewal_grace_period", &config->renewal_grace_period_, &error_list, false)) { config->renewal_grace_period_ = Duration::Hours(12); // 12hrs default } std::string key_type; - if (ParseJsonObjectField(config_json.object_value(), "key_type", &key_type, + if (ParseJsonObjectField(config_json.object(), "key_type", &key_type, &error_list, false)) { if (key_type != "RSA") { error_list.push_back( GRPC_ERROR_CREATE("field:key_type error:Only RSA is supported.")); } } - if (!ParseJsonObjectField(config_json.object_value(), "key_size", + if (!ParseJsonObjectField(config_json.object(), "key_size", &config->key_size_, &error_list, false)) { config->key_size_ = 2048; // default 2048 bit key size } - if (!ParseJsonObjectField(config_json.object_value(), "location", + if (!ParseJsonObjectField(config_json.object(), "location", &config->location_, &error_list, false)) { // GCE/GKE Metadata server needs to be contacted to get the value. } diff --git a/src/core/ext/xds/xds_api.cc b/src/core/ext/xds/xds_api.cc index 9c0355746e2..94efd016973 100644 --- a/src/core/ext/xds/xds_api.cc +++ b/src/core/ext/xds/xds_api.cc @@ -108,11 +108,11 @@ void PopulateMetadataValue(const XdsApiContext& context, break; case Json::Type::NUMBER: google_protobuf_Value_set_number_value( - value_pb, strtod(value.string_value().c_str(), nullptr)); + value_pb, strtod(value.string().c_str(), nullptr)); break; case Json::Type::STRING: google_protobuf_Value_set_string_value( - value_pb, StdStringToUpbString(value.string_value())); + value_pb, StdStringToUpbString(value.string())); break; case Json::Type::JSON_TRUE: google_protobuf_Value_set_bool_value(value_pb, true); @@ -123,13 +123,13 @@ void PopulateMetadataValue(const XdsApiContext& context, case Json::Type::OBJECT: { google_protobuf_Struct* struct_value = google_protobuf_Value_mutable_struct_value(value_pb, context.arena); - PopulateMetadata(context, struct_value, value.object_value()); + PopulateMetadata(context, struct_value, value.object()); break; } case Json::Type::ARRAY: { google_protobuf_ListValue* list_value = google_protobuf_Value_mutable_list_value(value_pb, context.arena); - PopulateListValue(context, list_value, value.array_value()); + PopulateListValue(context, list_value, value.array()); break; } } diff --git a/src/core/ext/xds/xds_bootstrap_grpc.cc b/src/core/ext/xds/xds_bootstrap_grpc.cc index 10fa5599460..a487172e9bb 100644 --- a/src/core/ext/xds/xds_bootstrap_grpc.cc +++ b/src/core/ext/xds/xds_bootstrap_grpc.cc @@ -126,7 +126,7 @@ void GrpcXdsBootstrap::GrpcXdsServer::JsonPostLoad(const Json& json, ValidationErrors* errors) { // Parse "channel_creds". auto channel_creds_list = LoadJsonObjectField>( - json.object_value(), args, "channel_creds", errors); + json.object(), args, "channel_creds", errors); if (channel_creds_list.has_value()) { ValidationErrors::ScopedField field(errors, ".channel_creds"); for (size_t i = 0; i < channel_creds_list->size(); ++i) { @@ -153,17 +153,16 @@ void GrpcXdsBootstrap::GrpcXdsServer::JsonPostLoad(const Json& json, // Parse "server_features". { ValidationErrors::ScopedField field(errors, ".server_features"); - auto it = json.object_value().find("server_features"); - if (it != json.object_value().end()) { + auto it = json.object().find("server_features"); + if (it != json.object().end()) { if (it->second.type() != Json::Type::ARRAY) { errors->AddError("is not an array"); } else { - const Json::Array& array = it->second.array_value(); + const Json::Array& array = it->second.array(); for (const Json& feature_json : array) { if (feature_json.type() == Json::Type::STRING && - (feature_json.string_value() == - kServerFeatureIgnoreResourceDeletion)) { - server_features_.insert(feature_json.string_value()); + (feature_json.string() == kServerFeatureIgnoreResourceDeletion)) { + server_features_.insert(feature_json.string()); } } } diff --git a/src/core/lib/gprpp/validation_errors.h b/src/core/lib/gprpp/validation_errors.h index 14a3458d62b..9ab3d54075e 100644 --- a/src/core/lib/gprpp/validation_errors.h +++ b/src/core/lib/gprpp/validation_errors.h @@ -40,21 +40,21 @@ namespace grpc_core { // ValidationErrors errors; // { // ValidationErrors::ScopedField field("foo"); -// auto it = json.object_value().find("foo"); -// if (it == json.object_value().end()) { +// auto it = json.object().find("foo"); +// if (it == json.object().end()) { // errors.AddError("field not present"); // } else if (it->second.type() != Json::Type::OBJECT) { // errors.AddError("must be a JSON object"); // } else { // const Json& foo = it->second; // ValidationErrors::ScopedField field(".bar"); -// auto it = foo.object_value().find("bar"); -// if (it == json.object_value().end()) { +// auto it = foo.object().find("bar"); +// if (it == json.object().end()) { // errors.AddError("field not present"); // } else if (it->second.type() != Json::Type::STRING) { // errors.AddError("must be a JSON string"); // } else { -// return it->second.string_value(); +// return it->second.string(); // } // } // } diff --git a/src/core/lib/json/json.h b/src/core/lib/json/json.h index dcd3288c7cb..dd632489cf2 100644 --- a/src/core/lib/json/json.h +++ b/src/core/lib/json/json.h @@ -169,11 +169,11 @@ class Json { // Accessor methods. Type type() const { return type_; } - const std::string& string_value() const { return string_value_; } - std::string* mutable_string_value() { return &string_value_; } - const Object& object_value() const { return object_value_; } + const std::string& string() const { return string_value_; } + std::string* mutable_string() { return &string_value_; } + const Object& object() const { return object_value_; } Object* mutable_object() { return &object_value_; } - const Array& array_value() const { return array_value_; } + const Array& array() const { return array_value_; } Array* mutable_array() { return &array_value_; } bool operator==(const Json& other) const { diff --git a/src/core/lib/json/json_object_loader.cc b/src/core/lib/json/json_object_loader.cc index b9d49b76a78..bab4432c567 100644 --- a/src/core/lib/json/json_object_loader.cc +++ b/src/core/lib/json/json_object_loader.cc @@ -35,7 +35,7 @@ void LoadScalar::LoadInto(const Json& json, const JsonArgs& /*args*/, void* dst, absl::StrCat("is not a ", IsNumber() ? "number" : "string")); return; } - return LoadInto(json.string_value(), dst, errors); + return LoadInto(json.string(), dst, errors); } bool LoadString::IsNumber() const { return false; } @@ -107,7 +107,7 @@ void LoadUnprocessedJsonObject::LoadInto(const Json& json, const JsonArgs&, errors->AddError("is not an object"); return; } - *static_cast(dst) = json.object_value(); + *static_cast(dst) = json.object(); } void LoadUnprocessedJsonArray::LoadInto(const Json& json, const JsonArgs&, @@ -117,7 +117,7 @@ void LoadUnprocessedJsonArray::LoadInto(const Json& json, const JsonArgs&, errors->AddError("is not an array"); return; } - *static_cast(dst) = json.array_value(); + *static_cast(dst) = json.array(); } void LoadVector::LoadInto(const Json& json, const JsonArgs& args, void* dst, @@ -126,7 +126,7 @@ void LoadVector::LoadInto(const Json& json, const JsonArgs& args, void* dst, errors->AddError("is not an array"); return; } - const auto& array = json.array_value(); + const auto& array = json.array(); const LoaderInterface* element_loader = ElementLoader(); for (size_t i = 0; i < array.size(); ++i) { ValidationErrors::ScopedField field(errors, absl::StrCat("[", i, "]")); @@ -142,7 +142,7 @@ void AutoLoader>::LoadInto(const Json& json, errors->AddError("is not an array"); return; } - const auto& array = json.array_value(); + const auto& array = json.array(); const LoaderInterface* element_loader = LoaderForType(); std::vector* vec = static_cast*>(dst); for (size_t i = 0; i < array.size(); ++i) { @@ -160,7 +160,7 @@ void LoadMap::LoadInto(const Json& json, const JsonArgs& args, void* dst, return; } const LoaderInterface* element_loader = ElementLoader(); - for (const auto& pair : json.object_value()) { + for (const auto& pair : json.object()) { ValidationErrors::ScopedField field(errors, absl::StrCat("[\"", pair.first, "\"]")); void* element = Insert(pair.first, dst); @@ -190,8 +190,8 @@ bool LoadObject(const Json& json, const JsonArgs& args, const Element* elements, } ValidationErrors::ScopedField field(errors, absl::StrCat(".", element.name)); - const auto& it = json.object_value().find(element.name); - if (it == json.object_value().end()) { + const auto& it = json.object().find(element.name); + if (it == json.object().end()) { if (element.optional) continue; errors->AddError("field not present"); continue; diff --git a/src/core/lib/json/json_reader.cc b/src/core/lib/json/json_reader.cc index 527ce2fdc80..957baa7789d 100644 --- a/src/core/lib/json/json_reader.cc +++ b/src/core/lib/json/json_reader.cc @@ -235,7 +235,7 @@ Json* JsonReader::CreateAndLinkValue() { } else { Json* parent = stack_.back(); if (parent->type() == Json::Type::OBJECT) { - if (parent->object_value().find(key_) != parent->object_value().end()) { + if (parent->object().find(key_) != parent->object().end()) { if (errors_.size() == GRPC_JSON_MAX_ERRORS) { truncated_errors_ = true; } else { diff --git a/src/core/lib/json/json_util.cc b/src/core/lib/json/json_util.cc index b4477c67803..4c0386948a9 100644 --- a/src/core/lib/json/json_util.cc +++ b/src/core/lib/json/json_util.cc @@ -60,7 +60,7 @@ bool ExtractJsonArray(const Json& json, absl::string_view field_name, absl::StrCat("field:", field_name, " error:type should be ARRAY"))); return false; } - *output = &json.array_value(); + *output = &json.array(); return true; } @@ -73,7 +73,7 @@ bool ExtractJsonObject(const Json& json, absl::string_view field_name, absl::StrCat("field:", field_name, " error:type should be OBJECT"))); return false; } - *output = &json.object_value(); + *output = &json.object(); return true; } diff --git a/src/core/lib/json/json_util.h b/src/core/lib/json/json_util.h index 3fd8cc31f83..f5e556e9a0e 100644 --- a/src/core/lib/json/json_util.h +++ b/src/core/lib/json/json_util.h @@ -59,7 +59,7 @@ bool ExtractJsonNumber(const Json& json, absl::string_view field_name, "field:", field_name, " error:type should be NUMBER or STRING"))); return false; } - if (!absl::SimpleAtoi(json.string_value(), output)) { + if (!absl::SimpleAtoi(json.string(), output)) { error_list->push_back(GRPC_ERROR_CREATE( absl::StrCat("field:", field_name, " error:failed to parse."))); return false; @@ -81,7 +81,7 @@ bool ExtractJsonString(const Json& json, absl::string_view field_name, absl::StrCat("field:", field_name, " error:type should be STRING"))); return false; } - *output = json.string_value(); + *output = json.string(); return true; } diff --git a/src/core/lib/json/json_writer.cc b/src/core/lib/json/json_writer.cc index fb0a070cade..fbbe27e372d 100644 --- a/src/core/lib/json/json_writer.cc +++ b/src/core/lib/json/json_writer.cc @@ -300,16 +300,16 @@ void JsonWriter::DumpArray(const Json::Array& array) { void JsonWriter::DumpValue(const Json& value) { switch (value.type()) { case Json::Type::OBJECT: - DumpObject(value.object_value()); + DumpObject(value.object()); break; case Json::Type::ARRAY: - DumpArray(value.array_value()); + DumpArray(value.array()); break; case Json::Type::STRING: - ValueString(value.string_value()); + ValueString(value.string()); break; case Json::Type::NUMBER: - ValueRaw(value.string_value()); + ValueRaw(value.string()); break; case Json::Type::JSON_TRUE: ValueRaw(std::string("true", 4)); diff --git a/src/core/lib/load_balancing/lb_policy_registry.cc b/src/core/lib/load_balancing/lb_policy_registry.cc index c60ece0f82e..a1dc0324be2 100644 --- a/src/core/lib/load_balancing/lb_policy_registry.cc +++ b/src/core/lib/load_balancing/lb_policy_registry.cc @@ -99,17 +99,17 @@ LoadBalancingPolicyRegistry::ParseLoadBalancingConfigHelper( } // Find the first LB policy that this client supports. std::vector policies_tried; - for (const Json& lb_config : lb_config_array.array_value()) { + for (const Json& lb_config : lb_config_array.array()) { if (lb_config.type() != Json::Type::OBJECT) { return absl::InvalidArgumentError("child entry should be of type object"); } - if (lb_config.object_value().empty()) { + if (lb_config.object().empty()) { return absl::InvalidArgumentError("no policy found in child entry"); } - if (lb_config.object_value().size() > 1) { + if (lb_config.object().size() > 1) { return absl::InvalidArgumentError("oneOf violation"); } - auto it = lb_config.object_value().begin(); + auto it = lb_config.object().begin(); if (it->second.type() != Json::Type::OBJECT) { return absl::InvalidArgumentError("child entry should be of type object"); } diff --git a/src/core/lib/security/authorization/rbac_translator.cc b/src/core/lib/security/authorization/rbac_translator.cc index b3138f040c4..0127c719a3f 100644 --- a/src/core/lib/security/authorization/rbac_translator.cc +++ b/src/core/lib/security/authorization/rbac_translator.cc @@ -91,13 +91,13 @@ bool IsUnsupportedHeader(absl::string_view header_name) { absl::StatusOr ParsePrincipalsArray(const Json& json) { std::vector> principal_names; - for (size_t i = 0; i < json.array_value().size(); ++i) { - const Json& child = json.array_value().at(i); + for (size_t i = 0; i < json.array().size(); ++i) { + const Json& child = json.array().at(i); if (child.type() != Json::Type::STRING) { return absl::InvalidArgumentError( absl::StrCat("\"principals\" ", i, ": is not a string.")); } - auto matcher_or = GetStringMatcher(child.string_value()); + auto matcher_or = GetStringMatcher(child.string()); if (!matcher_or.ok()) { return absl::Status(matcher_or.status().code(), absl::StrCat("\"principals\" ", i, ": ", @@ -112,7 +112,7 @@ absl::StatusOr ParsePrincipalsArray(const Json& json) { absl::StatusOr ParsePeer(const Json& json) { std::vector> peer; - for (const auto& object : json.object_value()) { + for (const auto& object : json.object()) { if (object.first == "principals") { if (object.second.type() != Json::Type::ARRAY) { return absl::InvalidArgumentError("\"principals\" is not an array."); @@ -136,17 +136,17 @@ absl::StatusOr ParsePeer(const Json& json) { absl::StatusOr ParseHeaderValues( const Json& json, absl::string_view header_name) { - if (json.array_value().empty()) { + if (json.array().empty()) { return absl::InvalidArgumentError("\"values\" list is empty."); } std::vector> values; - for (size_t i = 0; i < json.array_value().size(); ++i) { - const Json& child = json.array_value().at(i); + for (size_t i = 0; i < json.array().size(); ++i) { + const Json& child = json.array().at(i); if (child.type() != Json::Type::STRING) { return absl::InvalidArgumentError( absl::StrCat("\"values\" ", i, ": is not a string.")); } - auto matcher_or = GetHeaderMatcher(header_name, child.string_value()); + auto matcher_or = GetHeaderMatcher(header_name, child.string()); if (!matcher_or.ok()) { return absl::Status( matcher_or.status().code(), @@ -161,12 +161,12 @@ absl::StatusOr ParseHeaderValues( absl::StatusOr ParseHeaders(const Json& json) { absl::string_view key; const Json* values = nullptr; - for (const auto& object : json.object_value()) { + for (const auto& object : json.object()) { if (object.first == "key") { if (object.second.type() != Json::Type::STRING) { return absl::InvalidArgumentError("\"key\" is not a string."); } - key = object.second.string_value(); + key = object.second.string(); if (absl::StartsWith(key, ":") || absl::StartsWith(key, "grpc-") || IsUnsupportedHeader(key)) { return absl::InvalidArgumentError( @@ -193,8 +193,8 @@ absl::StatusOr ParseHeaders(const Json& json) { absl::StatusOr ParseHeadersArray(const Json& json) { std::vector> headers; - for (size_t i = 0; i < json.array_value().size(); ++i) { - const Json& child = json.array_value().at(i); + for (size_t i = 0; i < json.array().size(); ++i) { + const Json& child = json.array().at(i); if (child.type() != Json::Type::OBJECT) { return absl::InvalidArgumentError( absl::StrCat("\"headers\" ", i, ": is not an object.")); @@ -213,13 +213,13 @@ absl::StatusOr ParseHeadersArray(const Json& json) { absl::StatusOr ParsePathsArray(const Json& json) { std::vector> paths; - for (size_t i = 0; i < json.array_value().size(); ++i) { - const Json& child = json.array_value().at(i); + for (size_t i = 0; i < json.array().size(); ++i) { + const Json& child = json.array().at(i); if (child.type() != Json::Type::STRING) { return absl::InvalidArgumentError( absl::StrCat("\"paths\" ", i, ": is not a string.")); } - auto matcher_or = GetStringMatcher(child.string_value()); + auto matcher_or = GetStringMatcher(child.string()); if (!matcher_or.ok()) { return absl::Status( matcher_or.status().code(), @@ -233,7 +233,7 @@ absl::StatusOr ParsePathsArray(const Json& json) { absl::StatusOr ParseRequest(const Json& json) { std::vector> request; - for (const auto& object : json.object_value()) { + for (const auto& object : json.object()) { if (object.first == "paths") { if (object.second.type() != Json::Type::ARRAY) { return absl::InvalidArgumentError("\"paths\" is not an array."); @@ -270,13 +270,13 @@ absl::StatusOr ParseRule(const Json& json, std::string* policy_name) { absl::optional principals; absl::optional permissions; - for (const auto& object : json.object_value()) { + for (const auto& object : json.object()) { if (object.first == "name") { if (object.second.type() != Json::Type::STRING) { return absl::InvalidArgumentError( absl::StrCat("\"name\" is not a string.")); } - *policy_name = object.second.string_value(); + *policy_name = object.second.string(); } else if (object.first == "source") { if (object.second.type() != Json::Type::OBJECT) { return absl::InvalidArgumentError("\"source\" is not an object."); @@ -310,12 +310,12 @@ absl::StatusOr ParseRule(const Json& json, absl::StatusOr> ParseRulesArray( const Json& json, absl::string_view name) { - if (json.array_value().empty()) { + if (json.array().empty()) { return absl::InvalidArgumentError("rules is empty."); } std::map policies; - for (size_t i = 0; i < json.array_value().size(); ++i) { - const Json& child = json.array_value().at(i); + for (size_t i = 0; i < json.array().size(); ++i) { + const Json& child = json.array().at(i); if (child.type() != Json::Type::OBJECT) { return absl::InvalidArgumentError( absl::StrCat("rules ", i, ": is not an object.")); @@ -361,17 +361,17 @@ absl::StatusOr GenerateRbacPolicies( return absl::InvalidArgumentError( "SDK authorization policy is not an object."); } - auto it = json->object_value().find("name"); - if (it == json->object_value().end()) { + auto it = json->object().find("name"); + if (it == json->object().end()) { return absl::InvalidArgumentError("\"name\" field is not present."); } if (it->second.type() != Json::Type::STRING) { return absl::InvalidArgumentError("\"name\" is not a string."); } - absl::string_view name = it->second.string_value(); + absl::string_view name = it->second.string(); RbacPolicies rbacs; bool has_allow_rbac = false; - for (const auto& object : json->object_value()) { + for (const auto& object : json->object()) { if (object.first == "name") { continue; } else if (object.first == "deny_rules") { diff --git a/src/core/lib/security/credentials/external/aws_external_account_credentials.cc b/src/core/lib/security/credentials/external/aws_external_account_credentials.cc index c2ab4e3972f..39760bf2b02 100644 --- a/src/core/lib/security/credentials/external/aws_external_account_credentials.cc +++ b/src/core/lib/security/credentials/external/aws_external_account_credentials.cc @@ -93,8 +93,8 @@ AwsExternalAccountCredentials::AwsExternalAccountCredentials( Options options, std::vector scopes, grpc_error_handle* error) : ExternalAccountCredentials(options, std::move(scopes)) { audience_ = options.audience; - auto it = options.credential_source.object_value().find("environment_id"); - if (it == options.credential_source.object_value().end()) { + auto it = options.credential_source.object().find("environment_id"); + if (it == options.credential_source.object().end()) { *error = GRPC_ERROR_CREATE("environment_id field not present."); return; } @@ -102,12 +102,12 @@ AwsExternalAccountCredentials::AwsExternalAccountCredentials( *error = GRPC_ERROR_CREATE("environment_id field must be a string."); return; } - if (it->second.string_value() != kExpectedEnvironmentId) { + if (it->second.string() != kExpectedEnvironmentId) { *error = GRPC_ERROR_CREATE("environment_id does not match."); return; } - it = options.credential_source.object_value().find("region_url"); - if (it == options.credential_source.object_value().end()) { + it = options.credential_source.object().find("region_url"); + if (it == options.credential_source.object().end()) { *error = GRPC_ERROR_CREATE("region_url field not present."); return; } @@ -115,15 +115,15 @@ AwsExternalAccountCredentials::AwsExternalAccountCredentials( *error = GRPC_ERROR_CREATE("region_url field must be a string."); return; } - region_url_ = it->second.string_value(); - it = options.credential_source.object_value().find("url"); - if (it != options.credential_source.object_value().end() && + region_url_ = it->second.string(); + it = options.credential_source.object().find("url"); + if (it != options.credential_source.object().end() && it->second.type() == Json::Type::STRING) { - url_ = it->second.string_value(); + url_ = it->second.string(); } - it = options.credential_source.object_value().find( - "regional_cred_verification_url"); - if (it == options.credential_source.object_value().end()) { + it = + options.credential_source.object().find("regional_cred_verification_url"); + if (it == options.credential_source.object().end()) { *error = GRPC_ERROR_CREATE("regional_cred_verification_url field not present."); return; @@ -133,12 +133,11 @@ AwsExternalAccountCredentials::AwsExternalAccountCredentials( "regional_cred_verification_url field must be a string."); return; } - regional_cred_verification_url_ = it->second.string_value(); - it = - options.credential_source.object_value().find("imdsv2_session_token_url"); - if (it != options.credential_source.object_value().end() && + regional_cred_verification_url_ = it->second.string(); + it = options.credential_source.object().find("imdsv2_session_token_url"); + if (it != options.credential_source.object().end() && it->second.type() == Json::Type::STRING) { - imdsv2_session_token_url_ = it->second.string_value(); + imdsv2_session_token_url_ = it->second.string(); } } @@ -430,30 +429,27 @@ void AwsExternalAccountCredentials::OnRetrieveSigningKeysInternal( "JSON type is not object")); return; } - auto it = json->object_value().find("AccessKeyId"); - if (it != json->object_value().end() && - it->second.type() == Json::Type::STRING) { - access_key_id_ = it->second.string_value(); + auto it = json->object().find("AccessKeyId"); + if (it != json->object().end() && it->second.type() == Json::Type::STRING) { + access_key_id_ = it->second.string(); } else { FinishRetrieveSubjectToken( "", GRPC_ERROR_CREATE(absl::StrFormat( "Missing or invalid AccessKeyId in %s.", response_body))); return; } - it = json->object_value().find("SecretAccessKey"); - if (it != json->object_value().end() && - it->second.type() == Json::Type::STRING) { - secret_access_key_ = it->second.string_value(); + it = json->object().find("SecretAccessKey"); + if (it != json->object().end() && it->second.type() == Json::Type::STRING) { + secret_access_key_ = it->second.string(); } else { FinishRetrieveSubjectToken( "", GRPC_ERROR_CREATE(absl::StrFormat( "Missing or invalid SecretAccessKey in %s.", response_body))); return; } - it = json->object_value().find("Token"); - if (it != json->object_value().end() && - it->second.type() == Json::Type::STRING) { - token_ = it->second.string_value(); + it = json->object().find("Token"); + if (it != json->object().end() && it->second.type() == Json::Type::STRING) { + token_ = it->second.string(); } else { FinishRetrieveSubjectToken( "", GRPC_ERROR_CREATE(absl::StrFormat("Missing or invalid Token in %s.", diff --git a/src/core/lib/security/credentials/external/external_account_credentials.cc b/src/core/lib/security/credentials/external/external_account_credentials.cc index 2eff4b8e93b..79fec8d6710 100644 --- a/src/core/lib/security/credentials/external/external_account_credentials.cc +++ b/src/core/lib/security/credentials/external/external_account_credentials.cc @@ -114,8 +114,8 @@ RefCountedPtr ExternalAccountCredentials::Create( GRPC_ERROR_CREATE("Invalid json to construct credentials options."); return nullptr; } - auto it = json.object_value().find("type"); - if (it == json.object_value().end()) { + auto it = json.object().find("type"); + if (it == json.object().end()) { *error = GRPC_ERROR_CREATE("type field not present."); return nullptr; } @@ -123,13 +123,13 @@ RefCountedPtr ExternalAccountCredentials::Create( *error = GRPC_ERROR_CREATE("type field must be a string."); return nullptr; } - if (it->second.string_value() != GRPC_AUTH_JSON_TYPE_EXTERNAL_ACCOUNT) { + if (it->second.string() != GRPC_AUTH_JSON_TYPE_EXTERNAL_ACCOUNT) { *error = GRPC_ERROR_CREATE("Invalid credentials json type."); return nullptr; } options.type = GRPC_AUTH_JSON_TYPE_EXTERNAL_ACCOUNT; - it = json.object_value().find("audience"); - if (it == json.object_value().end()) { + it = json.object().find("audience"); + if (it == json.object().end()) { *error = GRPC_ERROR_CREATE("audience field not present."); return nullptr; } @@ -137,9 +137,9 @@ RefCountedPtr ExternalAccountCredentials::Create( *error = GRPC_ERROR_CREATE("audience field must be a string."); return nullptr; } - options.audience = it->second.string_value(); - it = json.object_value().find("subject_token_type"); - if (it == json.object_value().end()) { + options.audience = it->second.string(); + it = json.object().find("subject_token_type"); + if (it == json.object().end()) { *error = GRPC_ERROR_CREATE("subject_token_type field not present."); return nullptr; } @@ -147,13 +147,13 @@ RefCountedPtr ExternalAccountCredentials::Create( *error = GRPC_ERROR_CREATE("subject_token_type field must be a string."); return nullptr; } - options.subject_token_type = it->second.string_value(); - it = json.object_value().find("service_account_impersonation_url"); - if (it != json.object_value().end()) { - options.service_account_impersonation_url = it->second.string_value(); + options.subject_token_type = it->second.string(); + it = json.object().find("service_account_impersonation_url"); + if (it != json.object().end()) { + options.service_account_impersonation_url = it->second.string(); } - it = json.object_value().find("token_url"); - if (it == json.object_value().end()) { + it = json.object().find("token_url"); + if (it == json.object().end()) { *error = GRPC_ERROR_CREATE("token_url field not present."); return nullptr; } @@ -161,33 +161,33 @@ RefCountedPtr ExternalAccountCredentials::Create( *error = GRPC_ERROR_CREATE("token_url field must be a string."); return nullptr; } - options.token_url = it->second.string_value(); - it = json.object_value().find("token_info_url"); - if (it != json.object_value().end()) { - options.token_info_url = it->second.string_value(); + options.token_url = it->second.string(); + it = json.object().find("token_info_url"); + if (it != json.object().end()) { + options.token_info_url = it->second.string(); } - it = json.object_value().find("credential_source"); - if (it == json.object_value().end()) { + it = json.object().find("credential_source"); + if (it == json.object().end()) { *error = GRPC_ERROR_CREATE("credential_source field not present."); return nullptr; } options.credential_source = it->second; - it = json.object_value().find("quota_project_id"); - if (it != json.object_value().end()) { - options.quota_project_id = it->second.string_value(); + it = json.object().find("quota_project_id"); + if (it != json.object().end()) { + options.quota_project_id = it->second.string(); } - it = json.object_value().find("client_id"); - if (it != json.object_value().end()) { - options.client_id = it->second.string_value(); + it = json.object().find("client_id"); + if (it != json.object().end()) { + options.client_id = it->second.string(); } - it = json.object_value().find("client_secret"); - if (it != json.object_value().end()) { - options.client_secret = it->second.string_value(); + it = json.object().find("client_secret"); + if (it != json.object().end()) { + options.client_secret = it->second.string(); } - it = json.object_value().find("workforce_pool_user_project"); - if (it != json.object_value().end()) { + it = json.object().find("workforce_pool_user_project"); + if (it != json.object().end()) { if (MatchWorkforcePoolAudience(options.audience)) { - options.workforce_pool_user_project = it->second.string_value(); + options.workforce_pool_user_project = it->second.string(); } else { *error = GRPC_ERROR_CREATE( "workforce_pool_user_project should not be set for non-workforce " @@ -196,16 +196,16 @@ RefCountedPtr ExternalAccountCredentials::Create( } } RefCountedPtr creds; - if (options.credential_source.object_value().find("environment_id") != - options.credential_source.object_value().end()) { + if (options.credential_source.object().find("environment_id") != + options.credential_source.object().end()) { creds = MakeRefCounted( std::move(options), std::move(scopes), error); - } else if (options.credential_source.object_value().find("file") != - options.credential_source.object_value().end()) { + } else if (options.credential_source.object().find("file") != + options.credential_source.object().end()) { creds = MakeRefCounted( std::move(options), std::move(scopes), error); - } else if (options.credential_source.object_value().find("url") != - options.credential_source.object_value().end()) { + } else if (options.credential_source.object().find("url") != + options.credential_source.object().end()) { creds = MakeRefCounted( std::move(options), std::move(scopes), error); } else { @@ -401,14 +401,13 @@ void ExternalAccountCredentials::ImpersenateServiceAccount() { "Invalid token exchange response: JSON type is not object")); return; } - auto it = json->object_value().find("access_token"); - if (it == json->object_value().end() || - it->second.type() != Json::Type::STRING) { + auto it = json->object().find("access_token"); + if (it == json->object().end() || it->second.type() != Json::Type::STRING) { FinishTokenFetch(GRPC_ERROR_CREATE(absl::StrFormat( "Missing or invalid access_token in %s.", response_body))); return; } - std::string access_token = it->second.string_value(); + std::string access_token = it->second.string(); absl::StatusOr uri = URI::Parse(options_.service_account_impersonation_url); if (!uri.ok()) { @@ -481,22 +480,20 @@ void ExternalAccountCredentials::OnImpersenateServiceAccountInternal( "JSON type is not object")); return; } - auto it = json->object_value().find("accessToken"); - if (it == json->object_value().end() || - it->second.type() != Json::Type::STRING) { + auto it = json->object().find("accessToken"); + if (it == json->object().end() || it->second.type() != Json::Type::STRING) { FinishTokenFetch(GRPC_ERROR_CREATE(absl::StrFormat( "Missing or invalid accessToken in %s.", response_body))); return; } - std::string access_token = it->second.string_value(); - it = json->object_value().find("expireTime"); - if (it == json->object_value().end() || - it->second.type() != Json::Type::STRING) { + std::string access_token = it->second.string(); + it = json->object().find("expireTime"); + if (it == json->object().end() || it->second.type() != Json::Type::STRING) { FinishTokenFetch(GRPC_ERROR_CREATE(absl::StrFormat( "Missing or invalid expireTime in %s.", response_body))); return; } - std::string expire_time = it->second.string_value(); + std::string expire_time = it->second.string(); absl::Time t; if (!absl::ParseTime(absl::RFC3339_full, expire_time, &t, nullptr)) { FinishTokenFetch(GRPC_ERROR_CREATE( diff --git a/src/core/lib/security/credentials/external/file_external_account_credentials.cc b/src/core/lib/security/credentials/external/file_external_account_credentials.cc index e5a83b47732..c3c3116a11c 100644 --- a/src/core/lib/security/credentials/external/file_external_account_credentials.cc +++ b/src/core/lib/security/credentials/external/file_external_account_credentials.cc @@ -49,8 +49,8 @@ FileExternalAccountCredentials::Create(Options options, FileExternalAccountCredentials::FileExternalAccountCredentials( Options options, std::vector scopes, grpc_error_handle* error) : ExternalAccountCredentials(options, std::move(scopes)) { - auto it = options.credential_source.object_value().find("file"); - if (it == options.credential_source.object_value().end()) { + auto it = options.credential_source.object().find("file"); + if (it == options.credential_source.object().end()) { *error = GRPC_ERROR_CREATE("file field not present."); return; } @@ -58,17 +58,17 @@ FileExternalAccountCredentials::FileExternalAccountCredentials( *error = GRPC_ERROR_CREATE("file field must be a string."); return; } - file_ = it->second.string_value(); - it = options.credential_source.object_value().find("format"); - if (it != options.credential_source.object_value().end()) { + file_ = it->second.string(); + it = options.credential_source.object().find("format"); + if (it != options.credential_source.object().end()) { const Json& format_json = it->second; if (format_json.type() != Json::Type::OBJECT) { *error = GRPC_ERROR_CREATE( "The JSON value of credential source format is not an object."); return; } - auto format_it = format_json.object_value().find("type"); - if (format_it == format_json.object_value().end()) { + auto format_it = format_json.object().find("type"); + if (format_it == format_json.object().end()) { *error = GRPC_ERROR_CREATE("format.type field not present."); return; } @@ -76,10 +76,10 @@ FileExternalAccountCredentials::FileExternalAccountCredentials( *error = GRPC_ERROR_CREATE("format.type field must be a string."); return; } - format_type_ = format_it->second.string_value(); + format_type_ = format_it->second.string(); if (format_type_ == "json") { - format_it = format_json.object_value().find("subject_token_field_name"); - if (format_it == format_json.object_value().end()) { + format_it = format_json.object().find("subject_token_field_name"); + if (format_it == format_json.object().end()) { *error = GRPC_ERROR_CREATE( "format.subject_token_field_name field must be present if the " "format is in Json."); @@ -90,7 +90,7 @@ FileExternalAccountCredentials::FileExternalAccountCredentials( "format.subject_token_field_name field must be a string."); return; } - format_subject_token_field_name_ = format_it->second.string_value(); + format_subject_token_field_name_ = format_it->second.string(); } } } @@ -120,8 +120,8 @@ void FileExternalAccountCredentials::RetrieveSubjectToken( return; } auto content_it = - content_json->object_value().find(format_subject_token_field_name_); - if (content_it == content_json->object_value().end()) { + content_json->object().find(format_subject_token_field_name_); + if (content_it == content_json->object().end()) { cb("", GRPC_ERROR_CREATE("Subject token field not present.")); return; } @@ -129,7 +129,7 @@ void FileExternalAccountCredentials::RetrieveSubjectToken( cb("", GRPC_ERROR_CREATE("Subject token field must be a string.")); return; } - cb(content_it->second.string_value(), absl::OkStatus()); + cb(content_it->second.string(), absl::OkStatus()); return; } cb(std::string(content), absl::OkStatus()); diff --git a/src/core/lib/security/credentials/external/url_external_account_credentials.cc b/src/core/lib/security/credentials/external/url_external_account_credentials.cc index 80e44bfdd1e..371182f6b7c 100644 --- a/src/core/lib/security/credentials/external/url_external_account_credentials.cc +++ b/src/core/lib/security/credentials/external/url_external_account_credentials.cc @@ -61,8 +61,8 @@ UrlExternalAccountCredentials::Create(Options options, UrlExternalAccountCredentials::UrlExternalAccountCredentials( Options options, std::vector scopes, grpc_error_handle* error) : ExternalAccountCredentials(options, std::move(scopes)) { - auto it = options.credential_source.object_value().find("url"); - if (it == options.credential_source.object_value().end()) { + auto it = options.credential_source.object().find("url"); + if (it == options.credential_source.object().end()) { *error = GRPC_ERROR_CREATE("url field not present."); return; } @@ -70,7 +70,7 @@ UrlExternalAccountCredentials::UrlExternalAccountCredentials( *error = GRPC_ERROR_CREATE("url field must be a string."); return; } - absl::StatusOr tmp_url = URI::Parse(it->second.string_value()); + absl::StatusOr tmp_url = URI::Parse(it->second.string()); if (!tmp_url.ok()) { *error = GRPC_ERROR_CREATE( absl::StrFormat("Invalid credential source url. Error: %s", @@ -80,29 +80,29 @@ UrlExternalAccountCredentials::UrlExternalAccountCredentials( url_ = *tmp_url; // The url must follow the format of :/// std::vector v = - absl::StrSplit(it->second.string_value(), absl::MaxSplits('/', 3)); + absl::StrSplit(it->second.string(), absl::MaxSplits('/', 3)); url_full_path_ = absl::StrCat("/", v[3]); - it = options.credential_source.object_value().find("headers"); - if (it != options.credential_source.object_value().end()) { + it = options.credential_source.object().find("headers"); + if (it != options.credential_source.object().end()) { if (it->second.type() != Json::Type::OBJECT) { *error = GRPC_ERROR_CREATE( "The JSON value of credential source headers is not an object."); return; } - for (auto const& header : it->second.object_value()) { - headers_[header.first] = header.second.string_value(); + for (auto const& header : it->second.object()) { + headers_[header.first] = header.second.string(); } } - it = options.credential_source.object_value().find("format"); - if (it != options.credential_source.object_value().end()) { + it = options.credential_source.object().find("format"); + if (it != options.credential_source.object().end()) { const Json& format_json = it->second; if (format_json.type() != Json::Type::OBJECT) { *error = GRPC_ERROR_CREATE( "The JSON value of credential source format is not an object."); return; } - auto format_it = format_json.object_value().find("type"); - if (format_it == format_json.object_value().end()) { + auto format_it = format_json.object().find("type"); + if (format_it == format_json.object().end()) { *error = GRPC_ERROR_CREATE("format.type field not present."); return; } @@ -110,10 +110,10 @@ UrlExternalAccountCredentials::UrlExternalAccountCredentials( *error = GRPC_ERROR_CREATE("format.type field must be a string."); return; } - format_type_ = format_it->second.string_value(); + format_type_ = format_it->second.string(); if (format_type_ == "json") { - format_it = format_json.object_value().find("subject_token_field_name"); - if (format_it == format_json.object_value().end()) { + format_it = format_json.object().find("subject_token_field_name"); + if (format_it == format_json.object().end()) { *error = GRPC_ERROR_CREATE( "format.subject_token_field_name field must be present if the " "format is in Json."); @@ -124,7 +124,7 @@ UrlExternalAccountCredentials::UrlExternalAccountCredentials( "format.subject_token_field_name field must be a string."); return; } - format_subject_token_field_name_ = format_it->second.string_value(); + format_subject_token_field_name_ = format_it->second.string(); } } } @@ -208,8 +208,8 @@ void UrlExternalAccountCredentials::OnRetrieveSubjectTokenInternal( return; } auto response_it = - response_json->object_value().find(format_subject_token_field_name_); - if (response_it == response_json->object_value().end()) { + response_json->object().find(format_subject_token_field_name_); + if (response_it == response_json->object().end()) { FinishRetrieveSubjectToken( "", GRPC_ERROR_CREATE("Subject token field not present.")); return; @@ -219,7 +219,7 @@ void UrlExternalAccountCredentials::OnRetrieveSubjectTokenInternal( "", GRPC_ERROR_CREATE("Subject token field must be a string.")); return; } - FinishRetrieveSubjectToken(response_it->second.string_value(), error); + FinishRetrieveSubjectToken(response_it->second.string(), error); return; } FinishRetrieveSubjectToken(std::string(response_body), absl::OkStatus()); diff --git a/src/core/lib/security/credentials/jwt/jwt_verifier.cc b/src/core/lib/security/credentials/jwt/jwt_verifier.cc index eef5c027779..51f20a4004a 100644 --- a/src/core/lib/security/credentials/jwt/jwt_verifier.cc +++ b/src/core/lib/security/credentials/jwt/jwt_verifier.cc @@ -128,7 +128,7 @@ static const char* validate_string_field(const Json& json, const char* key) { gpr_log(GPR_ERROR, "Invalid %s field", key); return nullptr; } - return json.string_value().c_str(); + return json.string().c_str(); } static gpr_timespec validate_time_field(const Json& json, const char* key) { @@ -137,7 +137,7 @@ static gpr_timespec validate_time_field(const Json& json, const char* key) { gpr_log(GPR_ERROR, "Invalid %s field", key); return result; } - result.tv_sec = strtol(json.string_value().c_str(), nullptr, 10); + result.tv_sec = strtol(json.string().c_str(), nullptr, 10); return result; } @@ -164,8 +164,8 @@ static jose_header* jose_header_from_json(Json json) { goto error; } // Check alg field. - it = json.object_value().find("alg"); - if (it == json.object_value().end()) { + it = json.object().find("alg"); + if (it == json.object().end()) { gpr_log(GPR_ERROR, "Missing alg field."); goto error; } @@ -173,7 +173,7 @@ static jose_header* jose_header_from_json(Json json) { // Beware of this if we add HMAC support: // https://auth0.com/blog/2015/03/31/critical-vulnerabilities-in-json-web-token-libraries/ // - alg_value = it->second.string_value().c_str(); + alg_value = it->second.string().c_str(); if (it->second.type() != Json::Type::STRING || strncmp(alg_value, "RS", 2) != 0 || evp_md_from_alg(alg_value) == nullptr) { @@ -182,14 +182,14 @@ static jose_header* jose_header_from_json(Json json) { } h->alg = alg_value; // Check typ field. - it = json.object_value().find("typ"); - if (it != json.object_value().end()) { + it = json.object().find("typ"); + if (it != json.object().end()) { h->typ = validate_string_field(it->second, "typ"); if (h->typ == nullptr) goto error; } // Check kid field. - it = json.object_value().find("kid"); - if (it != json.object_value().end()) { + it = json.object().find("kid"); + if (it != json.object().end()) { h->kid = validate_string_field(it->second, "kid"); if (h->kid == nullptr) goto error; } @@ -269,7 +269,7 @@ grpc_jwt_claims* grpc_jwt_claims_from_json(Json json) { claims->exp = gpr_inf_future(GPR_CLOCK_REALTIME); // Per the spec, all fields are optional. - for (const auto& p : claims->json->object_value()) { + for (const auto& p : claims->json->object()) { if (p.first == "sub") { claims->sub = validate_string_field(p.second, "sub"); if (claims->sub == nullptr) goto error; @@ -445,8 +445,8 @@ static Json json_from_http(const grpc_http_response* response) { } static const Json* find_property_by_name(const Json& json, const char* name) { - auto it = json.object_value().find(name); - if (it == json.object_value().end()) { + auto it = json.object().find(name); + if (it == json.object().end()) { return nullptr; } return &it->second; @@ -538,15 +538,15 @@ static EVP_PKEY* pkey_from_jwk(const Json& json, const char* kty) { gpr_log(GPR_ERROR, "Could not create rsa key."); goto end; } - it = json.object_value().find("n"); - if (it == json.object_value().end()) { + it = json.object().find("n"); + if (it == json.object().end()) { gpr_log(GPR_ERROR, "Missing RSA public key field."); goto end; } tmp_n = bignum_from_base64(validate_string_field(it->second, "n")); if (tmp_n == nullptr) goto end; - it = json.object_value().find("e"); - if (it == json.object_value().end()) { + it = json.object().find("e"); + if (it == json.object().end()) { gpr_log(GPR_ERROR, "Missing RSA public key field."); goto end; } @@ -579,7 +579,7 @@ static EVP_PKEY* find_verification_key(const Json& json, const char* header_alg, // { : , : , ... } const Json* cur = find_property_by_name(json, header_kid); if (cur == nullptr) return nullptr; - return extract_pkey_from_x509(cur->string_value().c_str()); + return extract_pkey_from_x509(cur->string().c_str()); } if (jwt_keys->type() != Json::Type::ARRAY) { gpr_log(GPR_ERROR, @@ -588,21 +588,21 @@ static EVP_PKEY* find_verification_key(const Json& json, const char* header_alg, } // Key format is specified in: // https://tools.ietf.org/html/rfc7518#section-6. - for (const Json& jkey : jwt_keys->array_value()) { + for (const Json& jkey : jwt_keys->array()) { if (jkey.type() != Json::Type::OBJECT) continue; const char* alg = nullptr; - auto it = jkey.object_value().find("alg"); - if (it != jkey.object_value().end()) { + auto it = jkey.object().find("alg"); + if (it != jkey.object().end()) { alg = validate_string_field(it->second, "alg"); } const char* kid = nullptr; - it = jkey.object_value().find("kid"); - if (it != jkey.object_value().end()) { + it = jkey.object().find("kid"); + if (it != jkey.object().end()) { kid = validate_string_field(it->second, "kid"); } const char* kty = nullptr; - it = jkey.object_value().find("kty"); - if (it != jkey.object_value().end()) { + it = jkey.object().find("kty"); + if (it != jkey.object().end()) { kty = validate_string_field(it->second, "kty"); } if (alg != nullptr && kid != nullptr && kty != nullptr && diff --git a/src/core/lib/security/credentials/oauth2/oauth2_credentials.cc b/src/core/lib/security/credentials/oauth2/oauth2_credentials.cc index 4b67ef8fdad..1d27100b08c 100644 --- a/src/core/lib/security/credentials/oauth2/oauth2_credentials.cc +++ b/src/core/lib/security/credentials/oauth2/oauth2_credentials.cc @@ -194,30 +194,27 @@ grpc_oauth2_token_fetcher_credentials_parse_server_response( status = GRPC_CREDENTIALS_ERROR; goto end; } - it = json->object_value().find("access_token"); - if (it == json->object_value().end() || - it->second.type() != Json::Type::STRING) { + it = json->object().find("access_token"); + if (it == json->object().end() || it->second.type() != Json::Type::STRING) { gpr_log(GPR_ERROR, "Missing or invalid access_token in JSON."); status = GRPC_CREDENTIALS_ERROR; goto end; } - access_token = it->second.string_value().c_str(); - it = json->object_value().find("token_type"); - if (it == json->object_value().end() || - it->second.type() != Json::Type::STRING) { + access_token = it->second.string().c_str(); + it = json->object().find("token_type"); + if (it == json->object().end() || it->second.type() != Json::Type::STRING) { gpr_log(GPR_ERROR, "Missing or invalid token_type in JSON."); status = GRPC_CREDENTIALS_ERROR; goto end; } - token_type = it->second.string_value().c_str(); - it = json->object_value().find("expires_in"); - if (it == json->object_value().end() || - it->second.type() != Json::Type::NUMBER) { + token_type = it->second.string().c_str(); + it = json->object().find("expires_in"); + if (it == json->object().end() || it->second.type() != Json::Type::NUMBER) { gpr_log(GPR_ERROR, "Missing or invalid expires_in in JSON."); status = GRPC_CREDENTIALS_ERROR; goto end; } - expires_in = it->second.string_value().c_str(); + expires_in = it->second.string().c_str(); *token_lifetime = grpc_core::Duration::Seconds(strtol(expires_in, nullptr, 10)); *token_value = grpc_core::Slice::FromCopiedString( diff --git a/src/core/lib/security/util/json_util.cc b/src/core/lib/security/util/json_util.cc index 294cb43ec20..bf09ccebda5 100644 --- a/src/core/lib/security/util/json_util.cc +++ b/src/core/lib/security/util/json_util.cc @@ -39,8 +39,8 @@ const char* grpc_json_get_string_property(const grpc_core::Json& json, } return nullptr; } - auto it = json.object_value().find(prop_name); - if (it == json.object_value().end()) { + auto it = json.object().find(prop_name); + if (it == json.object().end()) { if (error != nullptr) { *error = GRPC_ERROR_CREATE( absl::StrCat("Property ", prop_name, " not found in JSON object.")); @@ -54,7 +54,7 @@ const char* grpc_json_get_string_property(const grpc_core::Json& json, } return nullptr; } - return it->second.string_value().c_str(); + return it->second.string().c_str(); } bool grpc_copy_json_string_property(const grpc_core::Json& json, diff --git a/src/core/lib/service_config/service_config_impl.cc b/src/core/lib/service_config/service_config_impl.cc index da3fa5d5a69..c8fb3271391 100644 --- a/src/core/lib/service_config/service_config_impl.cc +++ b/src/core/lib/service_config/service_config_impl.cc @@ -109,7 +109,7 @@ RefCountedPtr ServiceConfigImpl::Create( args, json, errors); // Parse per-method parameters. auto method_configs = LoadJsonObjectField>( - json.object_value(), JsonArgs(), "methodConfig", errors, + json.object(), JsonArgs(), "methodConfig", errors, /*required=*/false); if (method_configs.has_value()) { service_config->parsed_method_config_vectors_storage_.reserve( diff --git a/test/core/channel/channel_trace_test.cc b/test/core/channel/channel_trace_test.cc index d2f9c1651b3..d7466e03b10 100644 --- a/test/core/channel/channel_trace_test.cc +++ b/test/core/channel/channel_trace_test.cc @@ -57,7 +57,7 @@ void ValidateJsonArraySize(const Json& array, size_t expected) { ASSERT_EQ(array.type(), Json::Type::JSON_NULL); } else { ASSERT_EQ(array.type(), Json::Type::ARRAY); - EXPECT_EQ(array.array_value().size(), expected); + EXPECT_EQ(array.array().size(), expected); } } @@ -65,11 +65,11 @@ void ValidateChannelTraceData(const Json& json, size_t num_events_logged_expected, size_t actual_num_events_expected) { ASSERT_EQ(json.type(), Json::Type::OBJECT); - Json::Object object = json.object_value(); + Json::Object object = json.object(); Json& num_events_logged_json = object["numEventsLogged"]; ASSERT_EQ(num_events_logged_json.type(), Json::Type::STRING); size_t num_events_logged = static_cast( - strtol(num_events_logged_json.string_value().c_str(), nullptr, 0)); + strtol(num_events_logged_json.string().c_str(), nullptr, 0)); ASSERT_EQ(num_events_logged, num_events_logged_expected); Json& start_time_json = object["creationTimestamp"]; ASSERT_EQ(start_time_json.type(), Json::Type::STRING); diff --git a/test/core/channel/channelz_test.cc b/test/core/channel/channelz_test.cc index dc9e242b515..3b6d8314ecc 100644 --- a/test/core/channel/channelz_test.cc +++ b/test/core/channel/channelz_test.cc @@ -68,17 +68,17 @@ std::vector GetUuidListFromArray(const Json::Array& arr) { for (const Json& value : arr) { EXPECT_EQ(value.type(), Json::Type::OBJECT); if (value.type() != Json::Type::OBJECT) continue; - const Json::Object& object = value.object_value(); + const Json::Object& object = value.object(); auto it = object.find("ref"); EXPECT_NE(it, object.end()); if (it == object.end()) continue; EXPECT_EQ(it->second.type(), Json::Type::OBJECT); if (it->second.type() != Json::Type::OBJECT) continue; - const Json::Object& ref_object = it->second.object_value(); + const Json::Object& ref_object = it->second.object(); it = ref_object.find("channelId"); EXPECT_NE(it, ref_object.end()); if (it != ref_object.end()) { - uuids.push_back(atoi(it->second.string_value().c_str())); + uuids.push_back(atoi(it->second.string().c_str())); } } return uuids; @@ -89,17 +89,17 @@ void ValidateJsonArraySize(const Json& array, size_t expected) { ASSERT_EQ(array.type(), Json::Type::JSON_NULL); } else { ASSERT_EQ(array.type(), Json::Type::ARRAY); - EXPECT_EQ(array.array_value().size(), expected); + EXPECT_EQ(array.array().size(), expected); } } void ValidateJsonEnd(const Json& json, bool end) { - auto it = json.object_value().find("end"); + auto it = json.object().find("end"); if (end) { - ASSERT_NE(it, json.object_value().end()); + ASSERT_NE(it, json.object().end()); EXPECT_EQ(it->second.type(), Json::Type::JSON_TRUE); } else { - ASSERT_EQ(it, json.object_value().end()); + ASSERT_EQ(it, json.object().end()); } } @@ -201,8 +201,8 @@ void ValidateChildInteger(const Json::Object& object, const std::string& key, } ASSERT_NE(it, object.end()); ASSERT_EQ(it->second.type(), Json::Type::STRING); - int64_t gotten_number = static_cast( - strtol(it->second.string_value().c_str(), nullptr, 0)); + int64_t gotten_number = + static_cast(strtol(it->second.string().c_str(), nullptr, 0)); EXPECT_EQ(gotten_number, expected); } @@ -214,10 +214,9 @@ void ValidateCounters(const std::string& json_str, Json::Object* object = json->mutable_object(); Json& data = (*object)["data"]; ASSERT_EQ(data.type(), Json::Type::OBJECT); - ValidateChildInteger(data.object_value(), "callsStarted", args.calls_started); - ValidateChildInteger(data.object_value(), "callsFailed", args.calls_failed); - ValidateChildInteger(data.object_value(), "callsSucceeded", - args.calls_succeeded); + ValidateChildInteger(data.object(), "callsStarted", args.calls_started); + ValidateChildInteger(data.object(), "callsFailed", args.calls_failed); + ValidateChildInteger(data.object(), "callsSucceeded", args.calls_succeeded); } void ValidateChannel(ChannelNode* channel, @@ -388,7 +387,7 @@ TEST_F(ChannelzRegistryBasedTest, GetTopChannelsUuidCheck) { ASSERT_EQ(parsed_json->type(), Json::Type::OBJECT); Json& array = (*parsed_json->mutable_object())["channel"]; ValidateJsonArraySize(array, kNumChannels); - std::vector uuids = GetUuidListFromArray(array.array_value()); + std::vector uuids = GetUuidListFromArray(array.array()); for (int i = 0; i < kNumChannels; ++i) { EXPECT_EQ(i + 1, uuids[i]); } @@ -407,7 +406,7 @@ TEST_F(ChannelzRegistryBasedTest, GetTopChannelsMiddleUuidCheck) { ASSERT_EQ(parsed_json->type(), Json::Type::OBJECT); Json& array = (*parsed_json->mutable_object())["channel"]; ValidateJsonArraySize(array, kNumChannels - kMidQuery + 1); - std::vector uuids = GetUuidListFromArray(array.array_value()); + std::vector uuids = GetUuidListFromArray(array.array()); for (size_t i = 0; i < uuids.size(); ++i) { EXPECT_EQ(static_cast(kMidQuery + i), uuids[i]); } @@ -428,7 +427,7 @@ TEST_F(ChannelzRegistryBasedTest, GetTopChannelsNoHitUuid) { ASSERT_EQ(parsed_json->type(), Json::Type::OBJECT); Json& array = (*parsed_json->mutable_object())["channel"]; ValidateJsonArraySize(array, 10); - std::vector uuids = GetUuidListFromArray(array.array_value()); + std::vector uuids = GetUuidListFromArray(array.array()); for (size_t i = 0; i < uuids.size(); ++i) { EXPECT_EQ(static_cast(51 + i), uuids[i]); } @@ -448,7 +447,7 @@ TEST_F(ChannelzRegistryBasedTest, GetTopChannelsMoreGaps) { ASSERT_EQ(parsed_json->type(), Json::Type::OBJECT); Json array = (*parsed_json->mutable_object())["channel"]; ValidateJsonArraySize(array, 2); - std::vector uuids = GetUuidListFromArray(array.array_value()); + std::vector uuids = GetUuidListFromArray(array.array()); EXPECT_EQ(3, uuids[0]); EXPECT_EQ(5, uuids[1]); json_str = ChannelzRegistry::GetTopChannels(4); @@ -457,7 +456,7 @@ TEST_F(ChannelzRegistryBasedTest, GetTopChannelsMoreGaps) { ASSERT_EQ(parsed_json->type(), Json::Type::OBJECT); array = (*parsed_json->mutable_object())["channel"]; ValidateJsonArraySize(array, 1); - uuids = GetUuidListFromArray(array.array_value()); + uuids = GetUuidListFromArray(array.array()); EXPECT_EQ(5, uuids[0]); } @@ -479,7 +478,7 @@ TEST_F(ChannelzRegistryBasedTest, GetTopChannelsUuidAfterCompaction) { ASSERT_EQ(parsed_json->type(), Json::Type::OBJECT); Json& array = (*parsed_json->mutable_object())["channel"]; ValidateJsonArraySize(array, kLoopIterations); - std::vector uuids = GetUuidListFromArray(array.array_value()); + std::vector uuids = GetUuidListFromArray(array.array()); for (int i = 0; i < kLoopIterations; ++i) { // only the even uuids will still be present. EXPECT_EQ((i + 1) * 2, uuids[i]); diff --git a/test/core/json/json_object_loader_test.cc b/test/core/json/json_object_loader_test.cc index 848e6f3cff0..d13071d78e6 100644 --- a/test/core/json/json_object_loader_test.cc +++ b/test/core/json/json_object_loader_test.cc @@ -1118,8 +1118,8 @@ TEST(JsonObjectLoader, LoadJsonObjectField) { // Load a valid field. { ValidationErrors errors; - auto value = LoadJsonObjectField(json->object_value(), JsonArgs(), - "int", &errors); + auto value = LoadJsonObjectField(json->object(), JsonArgs(), "int", + &errors); ASSERT_TRUE(value.has_value()) << errors.status("unexpected errors"); EXPECT_EQ(*value, 1); EXPECT_TRUE(errors.ok()); @@ -1127,7 +1127,7 @@ TEST(JsonObjectLoader, LoadJsonObjectField) { // An optional field that is not present. { ValidationErrors errors; - auto value = LoadJsonObjectField(json->object_value(), JsonArgs(), + auto value = LoadJsonObjectField(json->object(), JsonArgs(), "not_present", &errors, /*required=*/false); EXPECT_FALSE(value.has_value()); @@ -1136,7 +1136,7 @@ TEST(JsonObjectLoader, LoadJsonObjectField) { // A required field that is not present. { ValidationErrors errors; - auto value = LoadJsonObjectField(json->object_value(), JsonArgs(), + auto value = LoadJsonObjectField(json->object(), JsonArgs(), "not_present", &errors); EXPECT_FALSE(value.has_value()); auto status = errors.status("errors validating JSON"); @@ -1149,8 +1149,8 @@ TEST(JsonObjectLoader, LoadJsonObjectField) { // Value has the wrong type. { ValidationErrors errors; - auto value = LoadJsonObjectField(json->object_value(), - JsonArgs(), "int", &errors); + auto value = LoadJsonObjectField(json->object(), JsonArgs(), + "int", &errors); EXPECT_FALSE(value.has_value()); auto status = errors.status("errors validating JSON"); EXPECT_THAT(status.code(), absl::StatusCode::kInvalidArgument); diff --git a/test/core/json/json_test.cc b/test/core/json/json_test.cc index 57028e92920..82a4ae0666b 100644 --- a/test/core/json/json_test.cc +++ b/test/core/json/json_test.cc @@ -58,13 +58,13 @@ void ValidateValue(const Json& actual, const Json& expected) { break; case Json::Type::STRING: case Json::Type::NUMBER: - EXPECT_EQ(actual.string_value(), expected.string_value()); + EXPECT_EQ(actual.string(), expected.string()); break; case Json::Type::OBJECT: - ValidateObject(actual.object_value(), expected.object_value()); + ValidateObject(actual.object(), expected.object()); break; case Json::Type::ARRAY: - ValidateArray(actual.array_value(), expected.array_value()); + ValidateArray(actual.array(), expected.array()); break; } } diff --git a/test/core/security/json_token_test.cc b/test/core/security/json_token_test.cc index 4541b43b92d..a04be2681dc 100644 --- a/test/core/security/json_token_test.cc +++ b/test/core/security/json_token_test.cc @@ -230,54 +230,54 @@ static Json parse_json_part_from_jwt(const char* str, size_t len) { } static void check_jwt_header(const Json& header) { - Json::Object object = header.object_value(); + Json::Object object = header.object(); Json value = object["alg"]; ASSERT_EQ(value.type(), Json::Type::STRING); - ASSERT_STREQ(value.string_value().c_str(), "RS256"); + ASSERT_STREQ(value.string().c_str(), "RS256"); value = object["typ"]; ASSERT_EQ(value.type(), Json::Type::STRING); - ASSERT_STREQ(value.string_value().c_str(), "JWT"); + ASSERT_STREQ(value.string().c_str(), "JWT"); value = object["kid"]; ASSERT_EQ(value.type(), Json::Type::STRING); - ASSERT_STREQ(value.string_value().c_str(), + ASSERT_STREQ(value.string().c_str(), "e6b5137873db8d2ef81e06a47289e6434ec8a165"); } static void check_jwt_claim(const Json& claim, const char* expected_audience, const char* expected_scope) { - Json::Object object = claim.object_value(); + Json::Object object = claim.object(); Json value = object["iss"]; ASSERT_EQ(value.type(), Json::Type::STRING); - ASSERT_EQ(value.string_value(), + ASSERT_EQ(value.string(), "777-abaslkan11hlb6nmim3bpspl31ud@developer.gserviceaccount.com"); if (expected_scope != nullptr) { ASSERT_EQ(object.find("sub"), object.end()); value = object["scope"]; ASSERT_EQ(value.type(), Json::Type::STRING); - ASSERT_EQ(value.string_value(), expected_scope); + ASSERT_EQ(value.string(), expected_scope); } else { // Claims without scope must have a sub. ASSERT_EQ(object.find("scope"), object.end()); value = object["sub"]; ASSERT_EQ(value.type(), Json::Type::STRING); - ASSERT_EQ(value.string_value(), object["iss"].string_value()); + ASSERT_EQ(value.string(), object["iss"].string()); } value = object["aud"]; ASSERT_EQ(value.type(), Json::Type::STRING); - ASSERT_EQ(value.string_value(), expected_audience); + ASSERT_EQ(value.string(), expected_audience); gpr_timespec expiration = gpr_time_0(GPR_CLOCK_REALTIME); value = object["exp"]; ASSERT_EQ(value.type(), Json::Type::NUMBER); - expiration.tv_sec = strtol(value.string_value().c_str(), nullptr, 10); + expiration.tv_sec = strtol(value.string().c_str(), nullptr, 10); gpr_timespec issue_time = gpr_time_0(GPR_CLOCK_REALTIME); value = object["iat"]; ASSERT_EQ(value.type(), Json::Type::NUMBER); - issue_time.tv_sec = strtol(value.string_value().c_str(), nullptr, 10); + issue_time.tv_sec = strtol(value.string().c_str(), nullptr, 10); gpr_timespec parsed_lifetime = gpr_time_sub(expiration, issue_time); ASSERT_EQ(parsed_lifetime.tv_sec, grpc_max_auth_token_lifetime().tv_sec); diff --git a/test/core/util/test_lb_policies.cc b/test/core/util/test_lb_policies.cc index c3b30fc9785..0d8d4854e0f 100644 --- a/test/core/util/test_lb_policies.cc +++ b/test/core/util/test_lb_policies.cc @@ -542,7 +542,7 @@ class FixedAddressFactory : public LoadBalancingPolicyFactory { ParseLoadBalancingConfig(const Json& json) const override { std::vector error_list; std::string address; - ParseJsonObjectField(json.object_value(), "address", &address, &error_list); + ParseJsonObjectField(json.object(), "address", &address, &error_list); if (!error_list.empty()) { grpc_error_handle error = GRPC_ERROR_CREATE_FROM_VECTOR( "errors parsing fixed_address_lb config", &error_list); diff --git a/test/core/xds/xds_bootstrap_test.cc b/test/core/xds/xds_bootstrap_test.cc index d900167a3bf..72c454793e6 100644 --- a/test/core/xds/xds_bootstrap_test.cc +++ b/test/core/xds/xds_bootstrap_test.cc @@ -183,12 +183,12 @@ TEST(XdsBootstrapTest, Basic) { ::testing::Eq("bar"), ::testing::AllOf( ::testing::Property(&Json::type, Json::Type::NUMBER), - ::testing::Property(&Json::string_value, "2"))), + ::testing::Property(&Json::string, "2"))), ::testing::Pair( ::testing::Eq("foo"), ::testing::AllOf( ::testing::Property(&Json::type, Json::Type::NUMBER), - ::testing::Property(&Json::string_value, "1"))))); + ::testing::Property(&Json::string, "1"))))); EXPECT_EQ(bootstrap->server_listener_resource_name_template(), "example/resource"); } @@ -588,14 +588,14 @@ class FakeCertificateProviderFactory : public CertificateProviderFactory { grpc_error_handle* error) override { std::vector error_list; EXPECT_EQ(config_json.type(), Json::Type::OBJECT); - auto it = config_json.object_value().find("value"); - if (it == config_json.object_value().end()) { + auto it = config_json.object().find("value"); + if (it == config_json.object().end()) { return MakeRefCounted(0); } else if (it->second.type() != Json::Type::NUMBER) { *error = GRPC_ERROR_CREATE("field:config field:value not of type number"); } else { int value = 0; - EXPECT_TRUE(absl::SimpleAtoi(it->second.string_value(), &value)); + EXPECT_TRUE(absl::SimpleAtoi(it->second.string(), &value)); return MakeRefCounted(value); } return nullptr; diff --git a/test/core/xds/xds_client_test.cc b/test/core/xds/xds_client_test.cc index 22b7c151e4f..f53a3d41b0e 100644 --- a/test/core/xds/xds_client_test.cc +++ b/test/core/xds/xds_client_test.cc @@ -355,9 +355,9 @@ class XdsClientTest : public ::testing::Test { absl::StatusOr foo = LoadFromJson(*json); if (!foo.ok()) { - auto it = json->object_value().find("name"); - if (it != json->object_value().end()) { - result.name = it->second.string_value(); + auto it = json->object().find("name"); + if (it != json->object().end()) { + result.name = it->second.string(); } result.resource = foo.status(); } else {