[JSON] use updated style for enum values (#32741)

More preparation for making this a public API.
pull/32742/head
Mark D. Roth 2 years ago committed by GitHub
parent 066e398bcc
commit 656e5f283b
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23
  1. 2
      src/core/ext/filters/client_channel/client_channel_channelz.cc
  2. 2
      src/core/ext/filters/client_channel/lb_policy/outlier_detection/outlier_detection.cc
  3. 2
      src/core/ext/filters/client_channel/lb_policy/priority/priority.cc
  4. 6
      src/core/ext/filters/client_channel/lb_policy/rls/rls.cc
  5. 2
      src/core/ext/filters/client_channel/lb_policy/weighted_round_robin/weighted_round_robin.cc
  6. 2
      src/core/ext/filters/client_channel/lb_policy/weighted_target/weighted_target.cc
  7. 2
      src/core/ext/filters/client_channel/lb_policy/xds/cds.cc
  8. 2
      src/core/ext/filters/client_channel/lb_policy/xds/xds_cluster_impl.cc
  9. 2
      src/core/ext/filters/client_channel/lb_policy/xds/xds_cluster_manager.cc
  10. 2
      src/core/ext/filters/client_channel/lb_policy/xds/xds_cluster_resolver.cc
  11. 2
      src/core/ext/filters/client_channel/lb_policy/xds/xds_override_host.cc
  12. 2
      src/core/ext/filters/client_channel/lb_policy/xds/xds_wrr_locality.cc
  13. 14
      src/core/ext/filters/client_channel/resolver/dns/c_ares/dns_resolver_ares.cc
  14. 4
      src/core/ext/filters/client_channel/retry_service_config.cc
  15. 2
      src/core/ext/xds/certificate_provider_store.cc
  16. 2
      src/core/ext/xds/file_watcher_certificate_provider_factory.cc
  17. 2
      src/core/ext/xds/google_mesh_ca_certificate_provider_factory.cc
  18. 14
      src/core/ext/xds/xds_api.cc
  19. 4
      src/core/ext/xds/xds_bootstrap_grpc.cc
  20. 4
      src/core/lib/channel/channelz.cc
  21. 4
      src/core/lib/gprpp/validation_errors.h
  22. 73
      src/core/lib/json/json.h
  23. 24
      src/core/lib/json/json_object_loader.cc
  24. 2
      src/core/lib/json/json_object_loader.h
  25. 25
      src/core/lib/json/json_reader.cc
  26. 8
      src/core/lib/json/json_util.cc
  27. 5
      src/core/lib/json/json_util.h
  28. 26
      src/core/lib/json/json_writer.cc
  29. 6
      src/core/lib/load_balancing/lb_policy_registry.cc
  30. 34
      src/core/lib/security/authorization/rbac_translator.cc
  31. 18
      src/core/lib/security/credentials/external/aws_external_account_credentials.cc
  32. 21
      src/core/lib/security/credentials/external/external_account_credentials.cc
  33. 12
      src/core/lib/security/credentials/external/file_external_account_credentials.cc
  34. 14
      src/core/lib/security/credentials/external/url_external_account_credentials.cc
  35. 2
      src/core/lib/security/credentials/google_default/google_default_credentials.cc
  36. 2
      src/core/lib/security/credentials/jwt/json_token.cc
  37. 2
      src/core/lib/security/credentials/jwt/jwt_credentials.cc
  38. 22
      src/core/lib/security/credentials/jwt/jwt_verifier.cc
  39. 13
      src/core/lib/security/credentials/oauth2/oauth2_credentials.cc
  40. 4
      src/core/lib/security/util/json_util.cc
  41. 2
      src/core/lib/service_config/service_config_impl.cc
  42. 2
      src/cpp/client/secure_credentials.cc
  43. 12
      test/core/channel/channel_trace_test.cc
  44. 40
      test/core/channel/channelz_test.cc
  45. 14
      test/core/json/json_test.cc
  46. 22
      test/core/security/json_token_test.cc
  47. 10
      test/core/security/jwt_verifier_test.cc
  48. 8
      test/core/xds/xds_bootstrap_test.cc
  49. 2
      test/cpp/util/channel_trace_proto_helper.cc

@ -58,7 +58,7 @@ Json SubchannelNode::RenderJson() {
// Fill in the channel trace if applicable
Json trace_json = trace_.RenderJson();
if (trace_json.type() != Json::Type::JSON_NULL) {
if (trace_json.type() != Json::Type::kNull) {
data["trace"] = std::move(trace_json);
}
// Ask CallCountingHelper to populate call count data.

@ -992,7 +992,7 @@ class OutlierDetectionLbFactory : public LoadBalancingPolicyFactory {
absl::StatusOr<RefCountedPtr<LoadBalancingPolicy::Config>>
ParseLoadBalancingConfig(const Json& json) const override {
if (json.type() == Json::Type::JSON_NULL) {
if (json.type() == Json::Type::kNull) {
// This policy was configured in the deprecated loadBalancingPolicy
// field or in the client API.
return absl::InvalidArgumentError(

@ -903,7 +903,7 @@ class PriorityLbFactory : public LoadBalancingPolicyFactory {
absl::StatusOr<RefCountedPtr<LoadBalancingPolicy::Config>>
ParseLoadBalancingConfig(const Json& json) const override {
if (json.type() == Json::Type::JSON_NULL) {
if (json.type() == Json::Type::kNull) {
// priority was mentioned as a policy in the deprecated
// loadBalancingPolicy field or in the client API.
return absl::InvalidArgumentError(

@ -754,7 +754,7 @@ void RlsLb::ChildPolicyWrapper::Orphan() {
bool InsertOrUpdateChildPolicyField(const std::string& field,
const std::string& value, Json* config,
ValidationErrors* errors) {
if (config->type() != Json::Type::ARRAY) {
if (config->type() != Json::Type::kArray) {
errors->AddError("is not an array");
return false;
}
@ -762,7 +762,7 @@ bool InsertOrUpdateChildPolicyField(const std::string& field,
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) {
if (child_json.type() != Json::Type::kObject) {
errors->AddError("is not an object");
success = false;
} else {
@ -774,7 +774,7 @@ bool InsertOrUpdateChildPolicyField(const std::string& field,
ValidationErrors::ScopedField json_field(
errors, absl::StrCat("[\"", child.begin()->first, "\"]"));
Json& child_config_json = child.begin()->second;
if (child_config_json.type() != Json::Type::OBJECT) {
if (child_config_json.type() != Json::Type::kObject) {
errors->AddError("child policy config is not an object");
success = false;
} else {

@ -988,7 +988,7 @@ class WeightedRoundRobinFactory : public LoadBalancingPolicyFactory {
absl::StatusOr<RefCountedPtr<LoadBalancingPolicy::Config>>
ParseLoadBalancingConfig(const Json& json) const override {
if (json.type() == Json::Type::JSON_NULL) {
if (json.type() == Json::Type::kNull) {
return absl::InvalidArgumentError(
"field:loadBalancingPolicy error:weighted_round_robin policy "
"requires configuration. Please use loadBalancingConfig field of "

@ -764,7 +764,7 @@ class WeightedTargetLbFactory : public LoadBalancingPolicyFactory {
absl::StatusOr<RefCountedPtr<LoadBalancingPolicy::Config>>
ParseLoadBalancingConfig(const Json& json) const override {
if (json.type() == Json::Type::JSON_NULL) {
if (json.type() == Json::Type::kNull) {
// weighted_target was mentioned as a policy in the deprecated
// loadBalancingPolicy field or in the client API.
return absl::InvalidArgumentError(

@ -743,7 +743,7 @@ class CdsLbFactory : public LoadBalancingPolicyFactory {
absl::StatusOr<RefCountedPtr<LoadBalancingPolicy::Config>>
ParseLoadBalancingConfig(const Json& json) const override {
if (json.type() == Json::Type::JSON_NULL) {
if (json.type() == Json::Type::kNull) {
// xds was mentioned as a policy in the deprecated loadBalancingPolicy
// field or in the client API.
return absl::InvalidArgumentError(

@ -777,7 +777,7 @@ class XdsClusterImplLbFactory : public LoadBalancingPolicyFactory {
absl::StatusOr<RefCountedPtr<LoadBalancingPolicy::Config>>
ParseLoadBalancingConfig(const Json& json) const override {
if (json.type() == Json::Type::JSON_NULL) {
if (json.type() == Json::Type::kNull) {
// This policy was configured in the deprecated loadBalancingPolicy
// field or in the client API.
return absl::InvalidArgumentError(

@ -672,7 +672,7 @@ class XdsClusterManagerLbFactory : public LoadBalancingPolicyFactory {
absl::StatusOr<RefCountedPtr<LoadBalancingPolicy::Config>>
ParseLoadBalancingConfig(const Json& json) const override {
if (json.type() == Json::Type::JSON_NULL) {
if (json.type() == Json::Type::kNull) {
// xds_cluster_manager was mentioned as a policy in the deprecated
// loadBalancingPolicy field or in the client API.
return absl::InvalidArgumentError(

@ -1145,7 +1145,7 @@ class XdsClusterResolverLbFactory : public LoadBalancingPolicyFactory {
absl::StatusOr<RefCountedPtr<LoadBalancingPolicy::Config>>
ParseLoadBalancingConfig(const Json& json) const override {
if (json.type() == Json::Type::JSON_NULL) {
if (json.type() == Json::Type::kNull) {
// xds_cluster_resolver was mentioned as a policy in the deprecated
// loadBalancingPolicy field or in the client API.
return absl::InvalidArgumentError(

@ -740,7 +740,7 @@ class XdsOverrideHostLbFactory : public LoadBalancingPolicyFactory {
absl::StatusOr<RefCountedPtr<LoadBalancingPolicy::Config>>
ParseLoadBalancingConfig(const Json& json) const override {
if (json.type() == Json::Type::JSON_NULL) {
if (json.type() == Json::Type::kNull) {
// This policy was configured in the deprecated loadBalancingPolicy
// field or in the client API.
return absl::InvalidArgumentError(

@ -345,7 +345,7 @@ class XdsWrrLocalityLbFactory : public LoadBalancingPolicyFactory {
absl::StatusOr<RefCountedPtr<LoadBalancingPolicy::Config>>
ParseLoadBalancingConfig(const Json& json) const override {
if (json.type() == Json::Type::JSON_NULL) {
if (json.type() == Json::Type::kNull) {
// xds_wrr_locality was mentioned as a policy in the deprecated
// loadBalancingPolicy field or in the client API.
return absl::InvalidArgumentError(

@ -237,7 +237,7 @@ OrphanablePtr<Orphanable> 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) {
if (entry.type() == Json::Type::kString && entry.string() == value) {
return true;
}
}
@ -251,7 +251,7 @@ std::string ChooseServiceConfig(char* service_config_choice_json,
*error = absl_status_to_grpc_error(json.status());
return "";
}
if (json->type() != Json::Type::ARRAY) {
if (json->type() != Json::Type::kArray) {
*error = GRPC_ERROR_CREATE(
"Service Config Choices, error: should be of type array");
return "";
@ -259,7 +259,7 @@ std::string ChooseServiceConfig(char* service_config_choice_json,
const Json* service_config = nullptr;
std::vector<grpc_error_handle> error_list;
for (const Json& choice : json->array()) {
if (choice.type() != Json::Type::OBJECT) {
if (choice.type() != Json::Type::kObject) {
error_list.push_back(GRPC_ERROR_CREATE(
"Service Config Choice, error: should be of type object"));
continue;
@ -267,7 +267,7 @@ std::string ChooseServiceConfig(char* service_config_choice_json,
// Check client language, if specified.
auto it = choice.object().find("clientLanguage");
if (it != choice.object().end()) {
if (it->second.type() != Json::Type::ARRAY) {
if (it->second.type() != Json::Type::kArray) {
error_list.push_back(GRPC_ERROR_CREATE(
"field:clientLanguage error:should be of type array"));
} else if (!ValueInJsonArray(it->second.array(), "c++")) {
@ -277,7 +277,7 @@ std::string ChooseServiceConfig(char* service_config_choice_json,
// Check client hostname, if specified.
it = choice.object().find("clientHostname");
if (it != choice.object().end()) {
if (it->second.type() != Json::Type::ARRAY) {
if (it->second.type() != Json::Type::kArray) {
error_list.push_back(GRPC_ERROR_CREATE(
"field:clientHostname error:should be of type array"));
} else {
@ -291,7 +291,7 @@ std::string ChooseServiceConfig(char* service_config_choice_json,
// Check percentage, if specified.
it = choice.object().find("percentage");
if (it != choice.object().end()) {
if (it->second.type() != Json::Type::NUMBER) {
if (it->second.type() != Json::Type::kNumber) {
error_list.push_back(GRPC_ERROR_CREATE(
"field:percentage error:should be of type number"));
} else {
@ -310,7 +310,7 @@ std::string ChooseServiceConfig(char* service_config_choice_json,
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) {
} else if (it->second.type() != Json::Type::kObject) {
error_list.push_back(GRPC_ERROR_CREATE(
"field:serviceConfig error:should be of type object"));
} else if (service_config == nullptr) {

@ -74,8 +74,8 @@ void RetryGlobalConfig::JsonPostLoad(const Json& json, const JsonArgs& args,
errors->AddError("field not present");
return;
}
if (it->second.type() != Json::Type::NUMBER &&
it->second.type() != Json::Type::STRING) {
if (it->second.type() != Json::Type::kNumber &&
it->second.type() != Json::Type::kString) {
errors->AddError("is not a number");
return;
}

@ -66,7 +66,7 @@ void CertificateProviderStore::PluginDefinition::JsonPostLoad(
// object.
Json::Object config_json;
if (it != json.object().end()) {
if (it->second.type() != Json::Type::OBJECT) {
if (it->second.type() != Json::Type::kObject) {
errors->AddError("is not an object");
return; // No point parsing config.
} else {

@ -75,7 +75,7 @@ RefCountedPtr<FileWatcherCertificateProviderFactory::Config>
FileWatcherCertificateProviderFactory::Config::Parse(const Json& config_json,
grpc_error_handle* error) {
auto config = MakeRefCounted<FileWatcherCertificateProviderFactory::Config>();
if (config_json.type() != Json::Type::OBJECT) {
if (config_json.type() != Json::Type::kObject) {
*error = GRPC_ERROR_CREATE("error:config type should be OBJECT.");
return nullptr;
}

@ -191,7 +191,7 @@ GoogleMeshCaCertificateProviderFactory::Config::Parse(
const Json& config_json, grpc_error_handle* error) {
auto config =
MakeRefCounted<GoogleMeshCaCertificateProviderFactory::Config>();
if (config_json.type() != Json::Type::OBJECT) {
if (config_json.type() != Json::Type::kObject) {
*error = GRPC_ERROR_CREATE("error:config type should be OBJECT.");
return nullptr;
}

@ -103,30 +103,30 @@ void PopulateMetadata(const XdsApiContext& context,
void PopulateMetadataValue(const XdsApiContext& context,
google_protobuf_Value* value_pb, const Json& value) {
switch (value.type()) {
case Json::Type::JSON_NULL:
case Json::Type::kNull:
google_protobuf_Value_set_null_value(value_pb, 0);
break;
case Json::Type::NUMBER:
case Json::Type::kNumber:
google_protobuf_Value_set_number_value(
value_pb, strtod(value.string().c_str(), nullptr));
break;
case Json::Type::STRING:
case Json::Type::kString:
google_protobuf_Value_set_string_value(
value_pb, StdStringToUpbString(value.string()));
break;
case Json::Type::JSON_TRUE:
case Json::Type::kTrue:
google_protobuf_Value_set_bool_value(value_pb, true);
break;
case Json::Type::JSON_FALSE:
case Json::Type::kFalse:
google_protobuf_Value_set_bool_value(value_pb, false);
break;
case Json::Type::OBJECT: {
case Json::Type::kObject: {
google_protobuf_Struct* struct_value =
google_protobuf_Value_mutable_struct_value(value_pb, context.arena);
PopulateMetadata(context, struct_value, value.object());
break;
}
case Json::Type::ARRAY: {
case Json::Type::kArray: {
google_protobuf_ListValue* list_value =
google_protobuf_Value_mutable_list_value(value_pb, context.arena);
PopulateListValue(context, list_value, value.array());

@ -155,12 +155,12 @@ void GrpcXdsBootstrap::GrpcXdsServer::JsonPostLoad(const Json& json,
ValidationErrors::ScopedField field(errors, ".server_features");
auto it = json.object().find("server_features");
if (it != json.object().end()) {
if (it->second.type() != Json::Type::ARRAY) {
if (it->second.type() != Json::Type::kArray) {
errors->AddError("is not an array");
} else {
const Json::Array& array = it->second.array();
for (const Json& feature_json : array) {
if (feature_json.type() == Json::Type::STRING &&
if (feature_json.type() == Json::Type::kString &&
(feature_json.string() == kServerFeatureIgnoreResourceDeletion)) {
server_features_.insert(feature_json.string());
}

@ -174,7 +174,7 @@ Json ChannelNode::RenderJson() {
}
// Fill in the channel trace if applicable.
Json trace_json = trace_.RenderJson();
if (trace_json.type() != Json::Type::JSON_NULL) {
if (trace_json.type() != Json::Type::kNull) {
data["trace"] = std::move(trace_json);
}
// Ask CallCountingHelper to populate call count data.
@ -301,7 +301,7 @@ Json ServerNode::RenderJson() {
Json::Object data;
// Fill in the channel trace if applicable.
Json trace_json = trace_.RenderJson();
if (trace_json.type() != Json::Type::JSON_NULL) {
if (trace_json.type() != Json::Type::kNull) {
data["trace"] = std::move(trace_json);
}
// Ask CallCountingHelper to populate call count data.

@ -43,7 +43,7 @@ namespace grpc_core {
// auto it = json.object().find("foo");
// if (it == json.object().end()) {
// errors.AddError("field not present");
// } else if (it->second.type() != Json::Type::OBJECT) {
// } else if (it->second.type() != Json::Type::kObject) {
// errors.AddError("must be a JSON object");
// } else {
// const Json& foo = it->second;
@ -51,7 +51,7 @@ namespace grpc_core {
// auto it = foo.object().find("bar");
// if (it == json.object().end()) {
// errors.AddError("field not present");
// } else if (it->second.type() != Json::Type::STRING) {
// } else if (it->second.type() != Json::Type::kString) {
// errors.AddError("must be a JSON string");
// } else {
// return it->second.string();

@ -38,15 +38,7 @@ class Json {
// consider whether there's a better alternative (e.g., maybe storing
// each numeric type as the native C++ type and automatically converting
// to string as needed).
enum class Type {
JSON_NULL,
JSON_TRUE,
JSON_FALSE,
NUMBER,
STRING,
OBJECT,
ARRAY
};
enum class Type { kNull, kTrue, kFalse, kNumber, kString, kObject, kArray };
using Object = std::map<std::string, Json>;
using Array = std::vector<Json>;
@ -71,12 +63,13 @@ class Json {
}
// Construct from copying a string.
// If is_number is true, the type will be NUMBER instead of STRING.
// If is_number is true, the type will be kNumber instead of kString.
// NOLINTNEXTLINE(google-explicit-constructor)
Json(const std::string& string, bool is_number = false)
: type_(is_number ? Type::NUMBER : Type::STRING), string_value_(string) {}
: type_(is_number ? Type::kNumber : Type::kString),
string_value_(string) {}
Json& operator=(const std::string& string) {
type_ = Type::STRING;
type_ = Type::kString;
string_value_ = string;
return *this;
}
@ -100,18 +93,18 @@ class Json {
// Construct by moving a string.
// NOLINTNEXTLINE(google-explicit-constructor)
Json(std::string&& string)
: type_(Type::STRING), string_value_(std::move(string)) {}
: type_(Type::kString), string_value_(std::move(string)) {}
Json& operator=(std::string&& string) {
type_ = Type::STRING;
type_ = Type::kString;
string_value_ = std::move(string);
return *this;
}
// Construct from bool.
// NOLINTNEXTLINE(google-explicit-constructor)
Json(bool b) : type_(b ? Type::JSON_TRUE : Type::JSON_FALSE) {}
Json(bool b) : type_(b ? Type::kTrue : Type::kFalse) {}
Json& operator=(bool b) {
type_ = b ? Type::JSON_TRUE : Type::JSON_FALSE;
type_ = b ? Type::kTrue : Type::kFalse;
return *this;
}
@ -119,19 +112,19 @@ class Json {
template <typename NumericType>
// NOLINTNEXTLINE(google-explicit-constructor)
Json(NumericType number)
: type_(Type::NUMBER), string_value_(std::to_string(number)) {}
: type_(Type::kNumber), string_value_(std::to_string(number)) {}
template <typename NumericType>
Json& operator=(NumericType number) {
type_ = Type::NUMBER;
type_ = Type::kNumber;
string_value_ = std::to_string(number);
return *this;
}
// Construct by copying object.
// NOLINTNEXTLINE(google-explicit-constructor)
Json(const Object& object) : type_(Type::OBJECT), object_value_(object) {}
Json(const Object& object) : type_(Type::kObject), object_value_(object) {}
Json& operator=(const Object& object) {
type_ = Type::OBJECT;
type_ = Type::kObject;
object_value_ = object;
return *this;
}
@ -139,27 +132,27 @@ class Json {
// Construct by moving object.
// NOLINTNEXTLINE(google-explicit-constructor)
Json(Object&& object)
: type_(Type::OBJECT), object_value_(std::move(object)) {}
: type_(Type::kObject), object_value_(std::move(object)) {}
Json& operator=(Object&& object) {
type_ = Type::OBJECT;
type_ = Type::kObject;
object_value_ = std::move(object);
return *this;
}
// Construct by copying array.
// NOLINTNEXTLINE(google-explicit-constructor)
Json(const Array& array) : type_(Type::ARRAY), array_value_(array) {}
Json(const Array& array) : type_(Type::kArray), array_value_(array) {}
Json& operator=(const Array& array) {
type_ = Type::ARRAY;
type_ = Type::kArray;
array_value_ = array;
return *this;
}
// Construct by moving array.
// NOLINTNEXTLINE(google-explicit-constructor)
Json(Array&& array) : type_(Type::ARRAY), array_value_(std::move(array)) {}
Json(Array&& array) : type_(Type::kArray), array_value_(std::move(array)) {}
Json& operator=(Array&& array) {
type_ = Type::ARRAY;
type_ = Type::kArray;
array_value_ = std::move(array);
return *this;
}
@ -179,14 +172,14 @@ class Json {
bool operator==(const Json& other) const {
if (type_ != other.type_) return false;
switch (type_) {
case Type::NUMBER:
case Type::STRING:
case Type::kNumber:
case Type::kString:
if (string_value_ != other.string_value_) return false;
break;
case Type::OBJECT:
case Type::kObject:
if (object_value_ != other.object_value_) return false;
break;
case Type::ARRAY:
case Type::kArray:
if (array_value_ != other.array_value_) return false;
break;
default:
@ -201,14 +194,14 @@ class Json {
void CopyFrom(const Json& other) {
type_ = other.type_;
switch (type_) {
case Type::NUMBER:
case Type::STRING:
case Type::kNumber:
case Type::kString:
string_value_ = other.string_value_;
break;
case Type::OBJECT:
case Type::kObject:
object_value_ = other.object_value_;
break;
case Type::ARRAY:
case Type::kArray:
array_value_ = other.array_value_;
break;
default:
@ -218,16 +211,16 @@ class Json {
void MoveFrom(Json&& other) {
type_ = other.type_;
other.type_ = Type::JSON_NULL;
other.type_ = Type::kNull;
switch (type_) {
case Type::NUMBER:
case Type::STRING:
case Type::kNumber:
case Type::kString:
string_value_ = std::move(other.string_value_);
break;
case Type::OBJECT:
case Type::kObject:
object_value_ = std::move(other.object_value_);
break;
case Type::ARRAY:
case Type::kArray:
array_value_ = std::move(other.array_value_);
break;
default:
@ -235,7 +228,7 @@ class Json {
}
}
Type type_ = Type::JSON_NULL;
Type type_ = Type::kNull;
std::string string_value_;
Object object_value_;
Array array_value_;

@ -27,10 +27,10 @@ namespace json_detail {
void LoadScalar::LoadInto(const Json& json, const JsonArgs& /*args*/, void* dst,
ValidationErrors* errors) const {
// We accept either STRING or NUMBER for numeric values, as per
// We accept either kString or kNumber for numeric values, as per
// https://developers.google.com/protocol-buffers/docs/proto3#json.
if (json.type() != Json::Type::STRING &&
(!IsNumber() || json.type() != Json::Type::NUMBER)) {
if (json.type() != Json::Type::kString &&
(!IsNumber() || json.type() != Json::Type::kNumber)) {
errors->AddError(
absl::StrCat("is not a ", IsNumber() ? "number" : "string"));
return;
@ -91,9 +91,9 @@ bool LoadNumber::IsNumber() const { return true; }
void LoadBool::LoadInto(const Json& json, const JsonArgs&, void* dst,
ValidationErrors* errors) const {
if (json.type() == Json::Type::JSON_TRUE) {
if (json.type() == Json::Type::kTrue) {
*static_cast<bool*>(dst) = true;
} else if (json.type() == Json::Type::JSON_FALSE) {
} else if (json.type() == Json::Type::kFalse) {
*static_cast<bool*>(dst) = false;
} else {
errors->AddError("is not a boolean");
@ -103,7 +103,7 @@ void LoadBool::LoadInto(const Json& json, const JsonArgs&, void* dst,
void LoadUnprocessedJsonObject::LoadInto(const Json& json, const JsonArgs&,
void* dst,
ValidationErrors* errors) const {
if (json.type() != Json::Type::OBJECT) {
if (json.type() != Json::Type::kObject) {
errors->AddError("is not an object");
return;
}
@ -113,7 +113,7 @@ void LoadUnprocessedJsonObject::LoadInto(const Json& json, const JsonArgs&,
void LoadUnprocessedJsonArray::LoadInto(const Json& json, const JsonArgs&,
void* dst,
ValidationErrors* errors) const {
if (json.type() != Json::Type::ARRAY) {
if (json.type() != Json::Type::kArray) {
errors->AddError("is not an array");
return;
}
@ -122,7 +122,7 @@ void LoadUnprocessedJsonArray::LoadInto(const Json& json, const JsonArgs&,
void LoadVector::LoadInto(const Json& json, const JsonArgs& args, void* dst,
ValidationErrors* errors) const {
if (json.type() != Json::Type::ARRAY) {
if (json.type() != Json::Type::kArray) {
errors->AddError("is not an array");
return;
}
@ -138,7 +138,7 @@ void LoadVector::LoadInto(const Json& json, const JsonArgs& args, void* dst,
void AutoLoader<std::vector<bool>>::LoadInto(const Json& json,
const JsonArgs& args, void* dst,
ValidationErrors* errors) const {
if (json.type() != Json::Type::ARRAY) {
if (json.type() != Json::Type::kArray) {
errors->AddError("is not an array");
return;
}
@ -155,7 +155,7 @@ void AutoLoader<std::vector<bool>>::LoadInto(const Json& json,
void LoadMap::LoadInto(const Json& json, const JsonArgs& args, void* dst,
ValidationErrors* errors) const {
if (json.type() != Json::Type::OBJECT) {
if (json.type() != Json::Type::kObject) {
errors->AddError("is not an object");
return;
}
@ -170,7 +170,7 @@ void LoadMap::LoadInto(const Json& json, const JsonArgs& args, void* dst,
void LoadOptional::LoadInto(const Json& json, const JsonArgs& args, void* dst,
ValidationErrors* errors) const {
if (json.type() == Json::Type::JSON_NULL) return;
if (json.type() == Json::Type::kNull) return;
void* element = Emplace(dst);
size_t starting_error_size = errors->size();
ElementLoader()->LoadInto(json, args, element, errors);
@ -179,7 +179,7 @@ void LoadOptional::LoadInto(const Json& json, const JsonArgs& args, void* dst,
bool LoadObject(const Json& json, const JsonArgs& args, const Element* elements,
size_t num_elements, void* dst, ValidationErrors* errors) {
if (json.type() != Json::Type::OBJECT) {
if (json.type() != Json::Type::kObject) {
errors->AddError("is not an object");
return false;
}

@ -485,7 +485,7 @@ class Vec<T, 0> {
// Given a list of elements, and a destination object, load the elements into
// the object from some parsed JSON.
// Returns false if the JSON object was not of type Json::Type::OBJECT.
// Returns false if the JSON object was not of type Json::Type::kObject.
bool LoadObject(const Json& json, const JsonArgs& args, const Element* elements,
size_t num_elements, void* dst, ValidationErrors* errors);

@ -234,7 +234,7 @@ Json* JsonReader::CreateAndLinkValue() {
value = &root_value_;
} else {
Json* parent = stack_.back();
if (parent->type() == Json::Type::OBJECT) {
if (parent->type() == Json::Type::kObject) {
if (parent->object().find(key_) != parent->object().end()) {
if (errors_.size() == GRPC_JSON_MAX_ERRORS) {
truncated_errors_ = true;
@ -245,7 +245,7 @@ Json* JsonReader::CreateAndLinkValue() {
}
value = &(*parent->mutable_object())[std::move(key_)];
} else {
GPR_ASSERT(parent->type() == Json::Type::ARRAY);
GPR_ASSERT(parent->type() == Json::Type::kArray);
parent->mutable_array()->emplace_back();
value = &parent->mutable_array()->back();
}
@ -265,10 +265,10 @@ bool JsonReader::StartContainer(Json::Type type) {
return false;
}
Json* value = CreateAndLinkValue();
if (type == Json::Type::OBJECT) {
if (type == Json::Type::kObject) {
*value = Json::Object();
} else {
GPR_ASSERT(type == Json::Type::ARRAY);
GPR_ASSERT(type == Json::Type::kArray);
*value = Json::Array();
}
stack_.push_back(value);
@ -405,9 +405,10 @@ JsonReader::Status JsonReader::Run() {
if (stack_.empty()) {
return Status::GRPC_JSON_PARSE_ERROR;
} else if (c == '}' &&
stack_.back()->type() != Json::Type::OBJECT) {
stack_.back()->type() != Json::Type::kObject) {
return Status::GRPC_JSON_PARSE_ERROR;
} else if (c == ']' && stack_.back()->type() != Json::Type::ARRAY) {
} else if (c == ']' &&
stack_.back()->type() != Json::Type::kArray) {
return Status::GRPC_JSON_PARSE_ERROR;
}
if (!SetNumber()) return Status::GRPC_JSON_PARSE_ERROR;
@ -422,10 +423,10 @@ JsonReader::Status JsonReader::Run() {
return Status::GRPC_JSON_PARSE_ERROR;
}
if (!stack_.empty() &&
stack_.back()->type() == Json::Type::OBJECT) {
stack_.back()->type() == Json::Type::kObject) {
state_ = State::GRPC_JSON_STATE_OBJECT_KEY_BEGIN;
} else if (!stack_.empty() &&
stack_.back()->type() == Json::Type::ARRAY) {
stack_.back()->type() == Json::Type::kArray) {
state_ = State::GRPC_JSON_STATE_VALUE_BEGIN;
} else {
return Status::GRPC_JSON_PARSE_ERROR;
@ -434,7 +435,7 @@ JsonReader::Status JsonReader::Run() {
if (stack_.empty()) {
return Status::GRPC_JSON_PARSE_ERROR;
}
if (c == '}' && stack_.back()->type() != Json::Type::OBJECT) {
if (c == '}' && stack_.back()->type() != Json::Type::kObject) {
return Status::GRPC_JSON_PARSE_ERROR;
}
if (c == '}' &&
@ -442,7 +443,7 @@ JsonReader::Status JsonReader::Run() {
!container_just_begun_) {
return Status::GRPC_JSON_PARSE_ERROR;
}
if (c == ']' && stack_.back()->type() != Json::Type::ARRAY) {
if (c == ']' && stack_.back()->type() != Json::Type::kArray) {
return Status::GRPC_JSON_PARSE_ERROR;
}
if (c == ']' && state_ == State::GRPC_JSON_STATE_VALUE_BEGIN &&
@ -581,7 +582,7 @@ JsonReader::Status JsonReader::Run() {
case '{':
container_just_begun_ = true;
if (!StartContainer(Json::Type::OBJECT)) {
if (!StartContainer(Json::Type::kObject)) {
return Status::GRPC_JSON_PARSE_ERROR;
}
state_ = State::GRPC_JSON_STATE_OBJECT_KEY_BEGIN;
@ -589,7 +590,7 @@ JsonReader::Status JsonReader::Run() {
case '[':
container_just_begun_ = true;
if (!StartContainer(Json::Type::ARRAY)) {
if (!StartContainer(Json::Type::kArray)) {
return Status::GRPC_JSON_PARSE_ERROR;
}
break;

@ -38,10 +38,10 @@ bool ParseDurationFromJson(const Json& field, Duration* duration) {
bool ExtractJsonBool(const Json& json, absl::string_view field_name,
bool* output, std::vector<grpc_error_handle>* error_list) {
switch (json.type()) {
case Json::Type::JSON_TRUE:
case Json::Type::kTrue:
*output = true;
return true;
case Json::Type::JSON_FALSE:
case Json::Type::kFalse:
*output = false;
return true;
default:
@ -54,7 +54,7 @@ bool ExtractJsonBool(const Json& json, absl::string_view field_name,
bool ExtractJsonArray(const Json& json, absl::string_view field_name,
const Json::Array** output,
std::vector<grpc_error_handle>* error_list) {
if (json.type() != Json::Type::ARRAY) {
if (json.type() != Json::Type::kArray) {
*output = nullptr;
error_list->push_back(GRPC_ERROR_CREATE(
absl::StrCat("field:", field_name, " error:type should be ARRAY")));
@ -67,7 +67,7 @@ bool ExtractJsonArray(const Json& json, absl::string_view field_name,
bool ExtractJsonObject(const Json& json, absl::string_view field_name,
const Json::Object** output,
std::vector<grpc_error_handle>* error_list) {
if (json.type() != Json::Type::OBJECT) {
if (json.type() != Json::Type::kObject) {
*output = nullptr;
error_list->push_back(GRPC_ERROR_CREATE(
absl::StrCat("field:", field_name, " error:type should be OBJECT")));

@ -54,7 +54,8 @@ bool ExtractJsonNumber(const Json& json, absl::string_view field_name,
NumericType* output,
std::vector<grpc_error_handle>* error_list) {
static_assert(std::is_integral<NumericType>::value, "Integral required");
if (json.type() != Json::Type::NUMBER && json.type() != Json::Type::STRING) {
if (json.type() != Json::Type::kNumber &&
json.type() != Json::Type::kString) {
error_list->push_back(GRPC_ERROR_CREATE(absl::StrCat(
"field:", field_name, " error:type should be NUMBER or STRING")));
return false;
@ -75,7 +76,7 @@ template <typename OutputType>
bool ExtractJsonString(const Json& json, absl::string_view field_name,
OutputType* output,
std::vector<grpc_error_handle>* error_list) {
if (json.type() != Json::Type::STRING) {
if (json.type() != Json::Type::kString) {
*output = "";
error_list->push_back(GRPC_ERROR_CREATE(
absl::StrCat("field:", field_name, " error:type should be STRING")));

@ -243,7 +243,7 @@ void JsonWriter::EscapeString(const std::string& string) {
void JsonWriter::ContainerBegins(Json::Type type) {
if (!got_key_) ValueEnd();
OutputIndent();
OutputChar(type == Json::Type::OBJECT ? '{' : '[');
OutputChar(type == Json::Type::kObject ? '{' : '[');
container_empty_ = true;
got_key_ = false;
depth_++;
@ -253,7 +253,7 @@ void JsonWriter::ContainerEnds(Json::Type type) {
if (indent_ && !container_empty_) OutputChar('\n');
depth_--;
if (!container_empty_) OutputIndent();
OutputChar(type == Json::Type::OBJECT ? '}' : ']');
OutputChar(type == Json::Type::kObject ? '}' : ']');
container_empty_ = false;
got_key_ = false;
}
@ -281,43 +281,43 @@ void JsonWriter::ValueString(const std::string& string) {
}
void JsonWriter::DumpObject(const Json::Object& object) {
ContainerBegins(Json::Type::OBJECT);
ContainerBegins(Json::Type::kObject);
for (const auto& p : object) {
ObjectKey(p.first);
DumpValue(p.second);
}
ContainerEnds(Json::Type::OBJECT);
ContainerEnds(Json::Type::kObject);
}
void JsonWriter::DumpArray(const Json::Array& array) {
ContainerBegins(Json::Type::ARRAY);
ContainerBegins(Json::Type::kArray);
for (const auto& v : array) {
DumpValue(v);
}
ContainerEnds(Json::Type::ARRAY);
ContainerEnds(Json::Type::kArray);
}
void JsonWriter::DumpValue(const Json& value) {
switch (value.type()) {
case Json::Type::OBJECT:
case Json::Type::kObject:
DumpObject(value.object());
break;
case Json::Type::ARRAY:
case Json::Type::kArray:
DumpArray(value.array());
break;
case Json::Type::STRING:
case Json::Type::kString:
ValueString(value.string());
break;
case Json::Type::NUMBER:
case Json::Type::kNumber:
ValueRaw(value.string());
break;
case Json::Type::JSON_TRUE:
case Json::Type::kTrue:
ValueRaw(std::string("true", 4));
break;
case Json::Type::JSON_FALSE:
case Json::Type::kFalse:
ValueRaw(std::string("false", 5));
break;
case Json::Type::JSON_NULL:
case Json::Type::kNull:
ValueRaw(std::string("null", 4));
break;
default:

@ -94,13 +94,13 @@ bool LoadBalancingPolicyRegistry::LoadBalancingPolicyExists(
absl::StatusOr<Json::Object::const_iterator>
LoadBalancingPolicyRegistry::ParseLoadBalancingConfigHelper(
const Json& lb_config_array) const {
if (lb_config_array.type() != Json::Type::ARRAY) {
if (lb_config_array.type() != Json::Type::kArray) {
return absl::InvalidArgumentError("type should be array");
}
// Find the first LB policy that this client supports.
std::vector<absl::string_view> policies_tried;
for (const Json& lb_config : lb_config_array.array()) {
if (lb_config.type() != Json::Type::OBJECT) {
if (lb_config.type() != Json::Type::kObject) {
return absl::InvalidArgumentError("child entry should be of type object");
}
if (lb_config.object().empty()) {
@ -110,7 +110,7 @@ LoadBalancingPolicyRegistry::ParseLoadBalancingConfigHelper(
return absl::InvalidArgumentError("oneOf violation");
}
auto it = lb_config.object().begin();
if (it->second.type() != Json::Type::OBJECT) {
if (it->second.type() != Json::Type::kObject) {
return absl::InvalidArgumentError("child entry should be of type object");
}
// If we support this policy, then select it.

@ -93,7 +93,7 @@ absl::StatusOr<Rbac::Principal> ParsePrincipalsArray(const Json& json) {
std::vector<std::unique_ptr<Rbac::Principal>> principal_names;
for (size_t i = 0; i < json.array().size(); ++i) {
const Json& child = json.array().at(i);
if (child.type() != Json::Type::STRING) {
if (child.type() != Json::Type::kString) {
return absl::InvalidArgumentError(
absl::StrCat("\"principals\" ", i, ": is not a string."));
}
@ -114,7 +114,7 @@ absl::StatusOr<Rbac::Principal> ParsePeer(const Json& json) {
std::vector<std::unique_ptr<Rbac::Principal>> peer;
for (const auto& object : json.object()) {
if (object.first == "principals") {
if (object.second.type() != Json::Type::ARRAY) {
if (object.second.type() != Json::Type::kArray) {
return absl::InvalidArgumentError("\"principals\" is not an array.");
}
auto principal_names_or = ParsePrincipalsArray(object.second);
@ -142,7 +142,7 @@ absl::StatusOr<Rbac::Permission> ParseHeaderValues(
std::vector<std::unique_ptr<Rbac::Permission>> values;
for (size_t i = 0; i < json.array().size(); ++i) {
const Json& child = json.array().at(i);
if (child.type() != Json::Type::STRING) {
if (child.type() != Json::Type::kString) {
return absl::InvalidArgumentError(
absl::StrCat("\"values\" ", i, ": is not a string."));
}
@ -163,7 +163,7 @@ absl::StatusOr<Rbac::Permission> ParseHeaders(const Json& json) {
const Json* values = nullptr;
for (const auto& object : json.object()) {
if (object.first == "key") {
if (object.second.type() != Json::Type::STRING) {
if (object.second.type() != Json::Type::kString) {
return absl::InvalidArgumentError("\"key\" is not a string.");
}
key = object.second.string();
@ -173,7 +173,7 @@ absl::StatusOr<Rbac::Permission> ParseHeaders(const Json& json) {
absl::StrFormat("Unsupported \"key\" %s.", key));
}
} else if (object.first == "values") {
if (object.second.type() != Json::Type::ARRAY) {
if (object.second.type() != Json::Type::kArray) {
return absl::InvalidArgumentError("\"values\" is not an array.");
}
values = &object.second;
@ -195,7 +195,7 @@ absl::StatusOr<Rbac::Permission> ParseHeadersArray(const Json& json) {
std::vector<std::unique_ptr<Rbac::Permission>> headers;
for (size_t i = 0; i < json.array().size(); ++i) {
const Json& child = json.array().at(i);
if (child.type() != Json::Type::OBJECT) {
if (child.type() != Json::Type::kObject) {
return absl::InvalidArgumentError(
absl::StrCat("\"headers\" ", i, ": is not an object."));
}
@ -215,7 +215,7 @@ absl::StatusOr<Rbac::Permission> ParsePathsArray(const Json& json) {
std::vector<std::unique_ptr<Rbac::Permission>> paths;
for (size_t i = 0; i < json.array().size(); ++i) {
const Json& child = json.array().at(i);
if (child.type() != Json::Type::STRING) {
if (child.type() != Json::Type::kString) {
return absl::InvalidArgumentError(
absl::StrCat("\"paths\" ", i, ": is not a string."));
}
@ -235,7 +235,7 @@ absl::StatusOr<Rbac::Permission> ParseRequest(const Json& json) {
std::vector<std::unique_ptr<Rbac::Permission>> request;
for (const auto& object : json.object()) {
if (object.first == "paths") {
if (object.second.type() != Json::Type::ARRAY) {
if (object.second.type() != Json::Type::kArray) {
return absl::InvalidArgumentError("\"paths\" is not an array.");
}
auto paths_or = ParsePathsArray(object.second);
@ -245,7 +245,7 @@ absl::StatusOr<Rbac::Permission> ParseRequest(const Json& json) {
std::make_unique<Rbac::Permission>(std::move(paths_or.value())));
}
} else if (object.first == "headers") {
if (object.second.type() != Json::Type::ARRAY) {
if (object.second.type() != Json::Type::kArray) {
return absl::InvalidArgumentError("\"headers\" is not an array.");
}
auto headers_or = ParseHeadersArray(object.second);
@ -272,20 +272,20 @@ absl::StatusOr<Rbac::Policy> ParseRule(const Json& json,
absl::optional<Rbac::Permission> permissions;
for (const auto& object : json.object()) {
if (object.first == "name") {
if (object.second.type() != Json::Type::STRING) {
if (object.second.type() != Json::Type::kString) {
return absl::InvalidArgumentError(
absl::StrCat("\"name\" is not a string."));
}
*policy_name = object.second.string();
} else if (object.first == "source") {
if (object.second.type() != Json::Type::OBJECT) {
if (object.second.type() != Json::Type::kObject) {
return absl::InvalidArgumentError("\"source\" is not an object.");
}
auto peer_or = ParsePeer(object.second);
if (!peer_or.ok()) return peer_or.status();
principals = std::move(*peer_or);
} else if (object.first == "request") {
if (object.second.type() != Json::Type::OBJECT) {
if (object.second.type() != Json::Type::kObject) {
return absl::InvalidArgumentError("\"request\" is not an object.");
}
auto request_or = ParseRequest(object.second);
@ -316,7 +316,7 @@ absl::StatusOr<std::map<std::string, Rbac::Policy>> ParseRulesArray(
std::map<std::string, Rbac::Policy> policies;
for (size_t i = 0; i < json.array().size(); ++i) {
const Json& child = json.array().at(i);
if (child.type() != Json::Type::OBJECT) {
if (child.type() != Json::Type::kObject) {
return absl::InvalidArgumentError(
absl::StrCat("rules ", i, ": is not an object."));
}
@ -357,7 +357,7 @@ absl::StatusOr<RbacPolicies> GenerateRbacPolicies(
absl::StrCat("Failed to parse gRPC authorization policy. Error: ",
json.status().ToString()));
}
if (json->type() != Json::Type::OBJECT) {
if (json->type() != Json::Type::kObject) {
return absl::InvalidArgumentError(
"SDK authorization policy is not an object.");
}
@ -365,7 +365,7 @@ absl::StatusOr<RbacPolicies> GenerateRbacPolicies(
if (it == json->object().end()) {
return absl::InvalidArgumentError("\"name\" field is not present.");
}
if (it->second.type() != Json::Type::STRING) {
if (it->second.type() != Json::Type::kString) {
return absl::InvalidArgumentError("\"name\" is not a string.");
}
absl::string_view name = it->second.string();
@ -375,7 +375,7 @@ absl::StatusOr<RbacPolicies> GenerateRbacPolicies(
if (object.first == "name") {
continue;
} else if (object.first == "deny_rules") {
if (object.second.type() != Json::Type::ARRAY) {
if (object.second.type() != Json::Type::kArray) {
return absl::InvalidArgumentError("\"deny_rules\" is not an array.");
}
auto deny_policy_or = ParseDenyRulesArray(object.second, name);
@ -386,7 +386,7 @@ absl::StatusOr<RbacPolicies> GenerateRbacPolicies(
}
rbacs.deny_policy = std::move(*deny_policy_or);
} else if (object.first == "allow_rules") {
if (object.second.type() != Json::Type::ARRAY) {
if (object.second.type() != Json::Type::kArray) {
return absl::InvalidArgumentError("\"allow_rules\" is not an array.");
}
auto allow_policy_or = ParseAllowRulesArray(object.second, name);

@ -98,7 +98,7 @@ AwsExternalAccountCredentials::AwsExternalAccountCredentials(
*error = GRPC_ERROR_CREATE("environment_id field not present.");
return;
}
if (it->second.type() != Json::Type::STRING) {
if (it->second.type() != Json::Type::kString) {
*error = GRPC_ERROR_CREATE("environment_id field must be a string.");
return;
}
@ -111,14 +111,14 @@ AwsExternalAccountCredentials::AwsExternalAccountCredentials(
*error = GRPC_ERROR_CREATE("region_url field not present.");
return;
}
if (it->second.type() != Json::Type::STRING) {
if (it->second.type() != Json::Type::kString) {
*error = GRPC_ERROR_CREATE("region_url field must be a string.");
return;
}
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) {
it->second.type() == Json::Type::kString) {
url_ = it->second.string();
}
it =
@ -128,7 +128,7 @@ AwsExternalAccountCredentials::AwsExternalAccountCredentials(
GRPC_ERROR_CREATE("regional_cred_verification_url field not present.");
return;
}
if (it->second.type() != Json::Type::STRING) {
if (it->second.type() != Json::Type::kString) {
*error = GRPC_ERROR_CREATE(
"regional_cred_verification_url field must be a string.");
return;
@ -136,7 +136,7 @@ AwsExternalAccountCredentials::AwsExternalAccountCredentials(
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) {
it->second.type() == Json::Type::kString) {
imdsv2_session_token_url_ = it->second.string();
}
}
@ -423,14 +423,14 @@ void AwsExternalAccountCredentials::OnRetrieveSigningKeysInternal(
json.status().ToString())));
return;
}
if (json->type() != Json::Type::OBJECT) {
if (json->type() != Json::Type::kObject) {
FinishRetrieveSubjectToken(
"", GRPC_ERROR_CREATE("Invalid retrieve signing keys response: "
"JSON type is not object"));
return;
}
auto it = json->object().find("AccessKeyId");
if (it != json->object().end() && it->second.type() == Json::Type::STRING) {
if (it != json->object().end() && it->second.type() == Json::Type::kString) {
access_key_id_ = it->second.string();
} else {
FinishRetrieveSubjectToken(
@ -439,7 +439,7 @@ void AwsExternalAccountCredentials::OnRetrieveSigningKeysInternal(
return;
}
it = json->object().find("SecretAccessKey");
if (it != json->object().end() && it->second.type() == Json::Type::STRING) {
if (it != json->object().end() && it->second.type() == Json::Type::kString) {
secret_access_key_ = it->second.string();
} else {
FinishRetrieveSubjectToken(
@ -448,7 +448,7 @@ void AwsExternalAccountCredentials::OnRetrieveSigningKeysInternal(
return;
}
it = json->object().find("Token");
if (it != json->object().end() && it->second.type() == Json::Type::STRING) {
if (it != json->object().end() && it->second.type() == Json::Type::kString) {
token_ = it->second.string();
} else {
FinishRetrieveSubjectToken(

@ -1,4 +1,3 @@
//
// Copyright 2020 gRPC authors.
//
// Licensed under the Apache License, Version 2.0 (the "License");
@ -109,7 +108,7 @@ RefCountedPtr<ExternalAccountCredentials> ExternalAccountCredentials::Create(
GPR_ASSERT(error->ok());
Options options;
options.type = GRPC_AUTH_JSON_TYPE_INVALID;
if (json.type() != Json::Type::OBJECT) {
if (json.type() != Json::Type::kObject) {
*error =
GRPC_ERROR_CREATE("Invalid json to construct credentials options.");
return nullptr;
@ -119,7 +118,7 @@ RefCountedPtr<ExternalAccountCredentials> ExternalAccountCredentials::Create(
*error = GRPC_ERROR_CREATE("type field not present.");
return nullptr;
}
if (it->second.type() != Json::Type::STRING) {
if (it->second.type() != Json::Type::kString) {
*error = GRPC_ERROR_CREATE("type field must be a string.");
return nullptr;
}
@ -133,7 +132,7 @@ RefCountedPtr<ExternalAccountCredentials> ExternalAccountCredentials::Create(
*error = GRPC_ERROR_CREATE("audience field not present.");
return nullptr;
}
if (it->second.type() != Json::Type::STRING) {
if (it->second.type() != Json::Type::kString) {
*error = GRPC_ERROR_CREATE("audience field must be a string.");
return nullptr;
}
@ -143,7 +142,7 @@ RefCountedPtr<ExternalAccountCredentials> ExternalAccountCredentials::Create(
*error = GRPC_ERROR_CREATE("subject_token_type field not present.");
return nullptr;
}
if (it->second.type() != Json::Type::STRING) {
if (it->second.type() != Json::Type::kString) {
*error = GRPC_ERROR_CREATE("subject_token_type field must be a string.");
return nullptr;
}
@ -157,7 +156,7 @@ RefCountedPtr<ExternalAccountCredentials> ExternalAccountCredentials::Create(
*error = GRPC_ERROR_CREATE("token_url field not present.");
return nullptr;
}
if (it->second.type() != Json::Type::STRING) {
if (it->second.type() != Json::Type::kString) {
*error = GRPC_ERROR_CREATE("token_url field must be a string.");
return nullptr;
}
@ -396,13 +395,13 @@ void ExternalAccountCredentials::ImpersenateServiceAccount() {
"Invalid token exchange response: ", json.status().ToString())));
return;
}
if (json->type() != Json::Type::OBJECT) {
if (json->type() != Json::Type::kObject) {
FinishTokenFetch(GRPC_ERROR_CREATE(
"Invalid token exchange response: JSON type is not object"));
return;
}
auto it = json->object().find("access_token");
if (it == json->object().end() || it->second.type() != Json::Type::STRING) {
if (it == json->object().end() || it->second.type() != Json::Type::kString) {
FinishTokenFetch(GRPC_ERROR_CREATE(absl::StrFormat(
"Missing or invalid access_token in %s.", response_body)));
return;
@ -474,21 +473,21 @@ void ExternalAccountCredentials::OnImpersenateServiceAccountInternal(
json.status().ToString())));
return;
}
if (json->type() != Json::Type::OBJECT) {
if (json->type() != Json::Type::kObject) {
FinishTokenFetch(
GRPC_ERROR_CREATE("Invalid service account impersonation response: "
"JSON type is not object"));
return;
}
auto it = json->object().find("accessToken");
if (it == json->object().end() || it->second.type() != Json::Type::STRING) {
if (it == json->object().end() || it->second.type() != Json::Type::kString) {
FinishTokenFetch(GRPC_ERROR_CREATE(absl::StrFormat(
"Missing or invalid accessToken in %s.", response_body)));
return;
}
std::string access_token = it->second.string();
it = json->object().find("expireTime");
if (it == json->object().end() || it->second.type() != Json::Type::STRING) {
if (it == json->object().end() || it->second.type() != Json::Type::kString) {
FinishTokenFetch(GRPC_ERROR_CREATE(absl::StrFormat(
"Missing or invalid expireTime in %s.", response_body)));
return;

@ -54,7 +54,7 @@ FileExternalAccountCredentials::FileExternalAccountCredentials(
*error = GRPC_ERROR_CREATE("file field not present.");
return;
}
if (it->second.type() != Json::Type::STRING) {
if (it->second.type() != Json::Type::kString) {
*error = GRPC_ERROR_CREATE("file field must be a string.");
return;
}
@ -62,7 +62,7 @@ FileExternalAccountCredentials::FileExternalAccountCredentials(
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) {
if (format_json.type() != Json::Type::kObject) {
*error = GRPC_ERROR_CREATE(
"The JSON value of credential source format is not an object.");
return;
@ -72,7 +72,7 @@ FileExternalAccountCredentials::FileExternalAccountCredentials(
*error = GRPC_ERROR_CREATE("format.type field not present.");
return;
}
if (format_it->second.type() != Json::Type::STRING) {
if (format_it->second.type() != Json::Type::kString) {
*error = GRPC_ERROR_CREATE("format.type field must be a string.");
return;
}
@ -85,7 +85,7 @@ FileExternalAccountCredentials::FileExternalAccountCredentials(
"format is in Json.");
return;
}
if (format_it->second.type() != Json::Type::STRING) {
if (format_it->second.type() != Json::Type::kString) {
*error = GRPC_ERROR_CREATE(
"format.subject_token_field_name field must be a string.");
return;
@ -114,7 +114,7 @@ void FileExternalAccountCredentials::RetrieveSubjectToken(
absl::string_view content = StringViewFromSlice(content_slice.slice);
if (format_type_ == "json") {
auto content_json = Json::Parse(content);
if (!content_json.ok() || content_json->type() != Json::Type::OBJECT) {
if (!content_json.ok() || content_json->type() != Json::Type::kObject) {
cb("", GRPC_ERROR_CREATE(
"The content of the file is not a valid json object."));
return;
@ -125,7 +125,7 @@ void FileExternalAccountCredentials::RetrieveSubjectToken(
cb("", GRPC_ERROR_CREATE("Subject token field not present."));
return;
}
if (content_it->second.type() != Json::Type::STRING) {
if (content_it->second.type() != Json::Type::kString) {
cb("", GRPC_ERROR_CREATE("Subject token field must be a string."));
return;
}

@ -66,7 +66,7 @@ UrlExternalAccountCredentials::UrlExternalAccountCredentials(
*error = GRPC_ERROR_CREATE("url field not present.");
return;
}
if (it->second.type() != Json::Type::STRING) {
if (it->second.type() != Json::Type::kString) {
*error = GRPC_ERROR_CREATE("url field must be a string.");
return;
}
@ -84,7 +84,7 @@ UrlExternalAccountCredentials::UrlExternalAccountCredentials(
url_full_path_ = absl::StrCat("/", v[3]);
it = options.credential_source.object().find("headers");
if (it != options.credential_source.object().end()) {
if (it->second.type() != Json::Type::OBJECT) {
if (it->second.type() != Json::Type::kObject) {
*error = GRPC_ERROR_CREATE(
"The JSON value of credential source headers is not an object.");
return;
@ -96,7 +96,7 @@ UrlExternalAccountCredentials::UrlExternalAccountCredentials(
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) {
if (format_json.type() != Json::Type::kObject) {
*error = GRPC_ERROR_CREATE(
"The JSON value of credential source format is not an object.");
return;
@ -106,7 +106,7 @@ UrlExternalAccountCredentials::UrlExternalAccountCredentials(
*error = GRPC_ERROR_CREATE("format.type field not present.");
return;
}
if (format_it->second.type() != Json::Type::STRING) {
if (format_it->second.type() != Json::Type::kString) {
*error = GRPC_ERROR_CREATE("format.type field must be a string.");
return;
}
@ -119,7 +119,7 @@ UrlExternalAccountCredentials::UrlExternalAccountCredentials(
"format is in Json.");
return;
}
if (format_it->second.type() != Json::Type::STRING) {
if (format_it->second.type() != Json::Type::kString) {
*error = GRPC_ERROR_CREATE(
"format.subject_token_field_name field must be a string.");
return;
@ -201,7 +201,7 @@ void UrlExternalAccountCredentials::OnRetrieveSubjectTokenInternal(
ctx_->response.body_length);
if (format_type_ == "json") {
auto response_json = Json::Parse(response_body);
if (!response_json.ok() || response_json->type() != Json::Type::OBJECT) {
if (!response_json.ok() || response_json->type() != Json::Type::kObject) {
FinishRetrieveSubjectToken(
"", GRPC_ERROR_CREATE(
"The format of response is not a valid json object."));
@ -214,7 +214,7 @@ void UrlExternalAccountCredentials::OnRetrieveSubjectTokenInternal(
"", GRPC_ERROR_CREATE("Subject token field not present."));
return;
}
if (response_it->second.type() != Json::Type::STRING) {
if (response_it->second.type() != Json::Type::kString) {
FinishRetrieveSubjectToken(
"", GRPC_ERROR_CREATE("Subject token field must be a string."));
return;

@ -275,7 +275,7 @@ static grpc_error_handle create_default_creds_from_path(
}
json = std::move(*json_or);
}
if (json.type() != Json::Type::OBJECT) {
if (json.type() != Json::Type::kObject) {
error = grpc_error_set_str(GRPC_ERROR_CREATE("Failed to parse JSON"),
grpc_core::StatusStrProperty::kRawBytes,
grpc_core::StringViewFromSlice(creds_data));

@ -80,7 +80,7 @@ grpc_auth_json_key grpc_auth_json_key_create_from_json(const Json& json) {
memset(&result, 0, sizeof(grpc_auth_json_key));
result.type = GRPC_AUTH_JSON_TYPE_INVALID;
if (json.type() == Json::Type::JSON_NULL) {
if (json.type() == Json::Type::kNull) {
gpr_log(GPR_ERROR, "Invalid json.");
goto end;
}

@ -140,7 +140,7 @@ grpc_service_account_jwt_access_credentials_create_from_auth_json_key(
static char* redact_private_key(const char* json_key) {
auto json = Json::Parse(json_key);
if (!json.ok() || json->type() != Json::Type::OBJECT) {
if (!json.ok() || json->type() != Json::Type::kObject) {
return gpr_strdup("<Json failed to parse.>");
}
(*json->mutable_object())["private_key"] = "<redacted>";

@ -124,7 +124,7 @@ static Json parse_json_part_from_jwt(const char* str, size_t len) {
}
static const char* validate_string_field(const Json& json, const char* key) {
if (json.type() != Json::Type::STRING) {
if (json.type() != Json::Type::kString) {
gpr_log(GPR_ERROR, "Invalid %s field", key);
return nullptr;
}
@ -133,7 +133,7 @@ static const char* validate_string_field(const Json& json, const char* key) {
static gpr_timespec validate_time_field(const Json& json, const char* key) {
gpr_timespec result = gpr_time_0(GPR_CLOCK_REALTIME);
if (json.type() != Json::Type::NUMBER) {
if (json.type() != Json::Type::kNumber) {
gpr_log(GPR_ERROR, "Invalid %s field", key);
return result;
}
@ -159,7 +159,7 @@ static jose_header* jose_header_from_json(Json json) {
const char* alg_value;
Json::Object::const_iterator it;
jose_header* h = grpc_core::Zalloc<jose_header>();
if (json.type() != Json::Type::OBJECT) {
if (json.type() != Json::Type::kObject) {
gpr_log(GPR_ERROR, "JSON value is not an object");
goto error;
}
@ -174,7 +174,7 @@ static jose_header* jose_header_from_json(Json json) {
// https://auth0.com/blog/2015/03/31/critical-vulnerabilities-in-json-web-token-libraries/
//
alg_value = it->second.string().c_str();
if (it->second.type() != Json::Type::STRING ||
if (it->second.type() != Json::Type::kString ||
strncmp(alg_value, "RS", 2) != 0 ||
evp_md_from_alg(alg_value) == nullptr) {
gpr_log(GPR_ERROR, "Invalid alg field");
@ -527,7 +527,7 @@ static EVP_PKEY* pkey_from_jwk(const Json& json, const char* kty) {
BIGNUM* tmp_e = nullptr;
Json::Object::const_iterator it;
GPR_ASSERT(json.type() == Json::Type::OBJECT);
GPR_ASSERT(json.type() == Json::Type::kObject);
GPR_ASSERT(kty != nullptr);
if (strcmp(kty, "RSA") != 0) {
gpr_log(GPR_ERROR, "Unsupported key type %s.", kty);
@ -581,7 +581,7 @@ static EVP_PKEY* find_verification_key(const Json& json, const char* header_alg,
if (cur == nullptr) return nullptr;
return extract_pkey_from_x509(cur->string().c_str());
}
if (jwt_keys->type() != Json::Type::ARRAY) {
if (jwt_keys->type() != Json::Type::kArray) {
gpr_log(GPR_ERROR,
"Unexpected value type of keys property in jwks key set.");
return nullptr;
@ -589,7 +589,7 @@ 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()) {
if (jkey.type() != Json::Type::OBJECT) continue;
if (jkey.type() != Json::Type::kObject) continue;
const char* alg = nullptr;
auto it = jkey.object().find("alg");
if (it != jkey.object().end()) {
@ -656,7 +656,7 @@ static void on_keys_retrieved(void* user_data, grpc_error_handle /*error*/) {
grpc_jwt_verifier_status status = GRPC_JWT_VERIFIER_GENERIC_ERROR;
grpc_jwt_claims* claims = nullptr;
if (json.type() == Json::Type::JSON_NULL) {
if (json.type() == Json::Type::kNull) {
status = GRPC_JWT_VERIFIER_KEY_RETRIEVAL_ERROR;
goto end;
}
@ -702,7 +702,7 @@ static void on_openid_config_retrieved(void* user_data,
char* path;
// TODO(jboeuf): Cache the jwks_uri in order to avoid this hop next time.
if (json.type() == Json::Type::JSON_NULL) goto error;
if (json.type() == Json::Type::kNull) goto error;
cur = find_property_by_name(json, "jwks_uri");
if (cur == nullptr) {
gpr_log(GPR_ERROR, "Could not find jwks_uri in openid config.");
@ -894,7 +894,7 @@ void grpc_jwt_verifier_verify(grpc_jwt_verifier* verifier,
dot = strchr(cur, '.');
if (dot == nullptr) goto error;
json = parse_json_part_from_jwt(cur, static_cast<size_t>(dot - cur));
if (json.type() == Json::Type::JSON_NULL) goto error;
if (json.type() == Json::Type::kNull) goto error;
header = jose_header_from_json(std::move(json));
if (header == nullptr) goto error;
@ -902,7 +902,7 @@ void grpc_jwt_verifier_verify(grpc_jwt_verifier* verifier,
dot = strchr(cur, '.');
if (dot == nullptr) goto error;
json = parse_json_part_from_jwt(cur, static_cast<size_t>(dot - cur));
if (json.type() == Json::Type::JSON_NULL) goto error;
if (json.type() == Json::Type::kNull) goto error;
claims = grpc_jwt_claims_from_json(std::move(json));
if (claims == nullptr) goto error;

@ -82,7 +82,7 @@ grpc_auth_refresh_token grpc_auth_refresh_token_create_from_json(
memset(&result, 0, sizeof(grpc_auth_refresh_token));
result.type = GRPC_AUTH_JSON_TYPE_INVALID;
if (json.type() != Json::Type::OBJECT) {
if (json.type() != Json::Type::kObject) {
gpr_log(GPR_ERROR, "Invalid json.");
goto end;
}
@ -189,27 +189,30 @@ grpc_oauth2_token_fetcher_credentials_parse_server_response(
status = GRPC_CREDENTIALS_ERROR;
goto end;
}
if (json->type() != Json::Type::OBJECT) {
if (json->type() != Json::Type::kObject) {
gpr_log(GPR_ERROR, "Response should be a JSON object");
status = GRPC_CREDENTIALS_ERROR;
goto end;
}
it = json->object().find("access_token");
if (it == json->object().end() || it->second.type() != Json::Type::STRING) {
if (it == json->object().end() ||
it->second.type() != Json::Type::kString) {
gpr_log(GPR_ERROR, "Missing or invalid access_token in JSON.");
status = GRPC_CREDENTIALS_ERROR;
goto end;
}
access_token = it->second.string().c_str();
it = json->object().find("token_type");
if (it == json->object().end() || it->second.type() != Json::Type::STRING) {
if (it == json->object().end() ||
it->second.type() != Json::Type::kString) {
gpr_log(GPR_ERROR, "Missing or invalid token_type in JSON.");
status = GRPC_CREDENTIALS_ERROR;
goto end;
}
token_type = it->second.string().c_str();
it = json->object().find("expires_in");
if (it == json->object().end() || it->second.type() != Json::Type::NUMBER) {
if (it == json->object().end() ||
it->second.type() != Json::Type::kNumber) {
gpr_log(GPR_ERROR, "Missing or invalid expires_in in JSON.");
status = GRPC_CREDENTIALS_ERROR;
goto end;

@ -33,7 +33,7 @@
const char* grpc_json_get_string_property(const grpc_core::Json& json,
const char* prop_name,
grpc_error_handle* error) {
if (json.type() != grpc_core::Json::Type::OBJECT) {
if (json.type() != grpc_core::Json::Type::kObject) {
if (error != nullptr) {
*error = GRPC_ERROR_CREATE("JSON value is not an object");
}
@ -47,7 +47,7 @@ const char* grpc_json_get_string_property(const grpc_core::Json& json,
}
return nullptr;
}
if (it->second.type() != grpc_core::Json::Type::STRING) {
if (it->second.type() != grpc_core::Json::Type::kString) {
if (error != nullptr) {
*error = GRPC_ERROR_CREATE(absl::StrCat(
"Property ", prop_name, " n JSON object is not a string."));

@ -97,7 +97,7 @@ RefCountedPtr<ServiceConfig> ServiceConfigImpl::Create(
RefCountedPtr<ServiceConfig> ServiceConfigImpl::Create(
const ChannelArgs& args, const Json& json, absl::string_view json_string,
ValidationErrors* errors) {
if (json.type() != Json::Type::OBJECT) {
if (json.type() != Json::Type::kObject) {
errors->AddError("is not an object");
return nullptr;
}

@ -164,7 +164,7 @@ grpc::Status StsCredentialsOptionsFromJson(const std::string& json_string,
}
ClearStsCredentialsOptions(options);
auto json = grpc_core::Json::Parse(json_string.c_str());
if (!json.ok() || json->type() != grpc_core::Json::Type::OBJECT) {
if (!json.ok() || json->type() != grpc_core::Json::Type::kObject) {
return grpc::Status(
grpc::StatusCode::INVALID_ARGUMENT,
absl::StrCat("Invalid json: ", json.status().ToString()));

@ -54,9 +54,9 @@ namespace {
void ValidateJsonArraySize(const Json& array, size_t expected) {
if (expected == 0) {
ASSERT_EQ(array.type(), Json::Type::JSON_NULL);
ASSERT_EQ(array.type(), Json::Type::kNull);
} else {
ASSERT_EQ(array.type(), Json::Type::ARRAY);
ASSERT_EQ(array.type(), Json::Type::kArray);
EXPECT_EQ(array.array().size(), expected);
}
}
@ -64,15 +64,15 @@ void ValidateJsonArraySize(const Json& array, size_t expected) {
void ValidateChannelTraceData(const Json& json,
size_t num_events_logged_expected,
size_t actual_num_events_expected) {
ASSERT_EQ(json.type(), Json::Type::OBJECT);
ASSERT_EQ(json.type(), Json::Type::kObject);
Json::Object object = json.object();
Json& num_events_logged_json = object["numEventsLogged"];
ASSERT_EQ(num_events_logged_json.type(), Json::Type::STRING);
ASSERT_EQ(num_events_logged_json.type(), Json::Type::kString);
size_t num_events_logged = static_cast<size_t>(
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);
ASSERT_EQ(start_time_json.type(), Json::Type::kString);
ValidateJsonArraySize(object["events"], actual_num_events_expected);
}
@ -85,7 +85,7 @@ void AddSimpleTrace(ChannelTrace* tracer) {
void ValidateChannelTraceCustom(ChannelTrace* tracer, size_t num_events_logged,
size_t num_events_expected) {
Json json = tracer->RenderJson();
ASSERT_EQ(json.type(), Json::Type::OBJECT);
ASSERT_EQ(json.type(), Json::Type::kObject);
std::string json_str = json.Dump();
grpc::testing::ValidateChannelTraceProtoJsonTranslation(json_str.c_str());
ValidateChannelTraceData(json, num_events_logged, num_events_expected);

@ -66,14 +66,14 @@ namespace {
std::vector<intptr_t> GetUuidListFromArray(const Json::Array& arr) {
std::vector<intptr_t> uuids;
for (const Json& value : arr) {
EXPECT_EQ(value.type(), Json::Type::OBJECT);
if (value.type() != Json::Type::OBJECT) continue;
EXPECT_EQ(value.type(), Json::Type::kObject);
if (value.type() != Json::Type::kObject) continue;
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;
EXPECT_EQ(it->second.type(), Json::Type::kObject);
if (it->second.type() != Json::Type::kObject) continue;
const Json::Object& ref_object = it->second.object();
it = ref_object.find("channelId");
EXPECT_NE(it, ref_object.end());
@ -86,9 +86,9 @@ std::vector<intptr_t> GetUuidListFromArray(const Json::Array& arr) {
void ValidateJsonArraySize(const Json& array, size_t expected) {
if (expected == 0) {
ASSERT_EQ(array.type(), Json::Type::JSON_NULL);
ASSERT_EQ(array.type(), Json::Type::kNull);
} else {
ASSERT_EQ(array.type(), Json::Type::ARRAY);
ASSERT_EQ(array.type(), Json::Type::kArray);
EXPECT_EQ(array.array().size(), expected);
}
}
@ -97,7 +97,7 @@ void ValidateJsonEnd(const Json& json, bool end) {
auto it = json.object().find("end");
if (end) {
ASSERT_NE(it, json.object().end());
EXPECT_EQ(it->second.type(), Json::Type::JSON_TRUE);
EXPECT_EQ(it->second.type(), Json::Type::kTrue);
} else {
ASSERT_EQ(it, json.object().end());
}
@ -109,7 +109,7 @@ void ValidateGetTopChannels(size_t expected_channels) {
json_str.c_str());
auto parsed_json = Json::Parse(json_str);
ASSERT_TRUE(parsed_json.ok()) << parsed_json.status();
ASSERT_EQ(parsed_json->type(), Json::Type::OBJECT);
ASSERT_EQ(parsed_json->type(), Json::Type::kObject);
// This check will naturally have to change when we support pagination.
// tracked: https://github.com/grpc/grpc/issues/16019.
ValidateJsonArraySize((*parsed_json->mutable_object())["channel"],
@ -128,7 +128,7 @@ void ValidateGetServers(size_t expected_servers) {
json_str.c_str());
auto parsed_json = Json::Parse(json_str);
ASSERT_TRUE(parsed_json.ok()) << parsed_json.status();
ASSERT_EQ(parsed_json->type(), Json::Type::OBJECT);
ASSERT_EQ(parsed_json->type(), Json::Type::kObject);
// This check will naturally have to change when we support pagination.
// tracked: https://github.com/grpc/grpc/issues/16019.
ValidateJsonArraySize((*parsed_json->mutable_object())["server"],
@ -200,7 +200,7 @@ void ValidateChildInteger(const Json::Object& object, const std::string& key,
return;
}
ASSERT_NE(it, object.end());
ASSERT_EQ(it->second.type(), Json::Type::STRING);
ASSERT_EQ(it->second.type(), Json::Type::kString);
int64_t gotten_number =
static_cast<int64_t>(strtol(it->second.string().c_str(), nullptr, 0));
EXPECT_EQ(gotten_number, expected);
@ -210,10 +210,10 @@ void ValidateCounters(const std::string& json_str,
const ValidateChannelDataArgs& args) {
auto json = Json::Parse(json_str);
ASSERT_TRUE(json.ok()) << json.status();
ASSERT_EQ(json->type(), Json::Type::OBJECT);
ASSERT_EQ(json->type(), Json::Type::kObject);
Json::Object* object = json->mutable_object();
Json& data = (*object)["data"];
ASSERT_EQ(data.type(), Json::Type::OBJECT);
ASSERT_EQ(data.type(), Json::Type::kObject);
ValidateChildInteger(data.object(), "callsStarted", args.calls_started);
ValidateChildInteger(data.object(), "callsFailed", args.calls_failed);
ValidateChildInteger(data.object(), "callsSucceeded", args.calls_succeeded);
@ -361,7 +361,7 @@ TEST_F(ChannelzRegistryBasedTest, GetTopChannelsPagination) {
json_str.c_str());
auto parsed_json = Json::Parse(json_str);
ASSERT_TRUE(parsed_json.ok()) << parsed_json.status();
ASSERT_EQ(parsed_json->type(), Json::Type::OBJECT);
ASSERT_EQ(parsed_json->type(), Json::Type::kObject);
// 100 is the pagination limit.
ValidateJsonArraySize((*parsed_json->mutable_object())["channel"], 100);
ValidateJsonEnd(*parsed_json, false);
@ -371,7 +371,7 @@ TEST_F(ChannelzRegistryBasedTest, GetTopChannelsPagination) {
json_str.c_str());
parsed_json = Json::Parse(json_str);
ASSERT_TRUE(parsed_json.ok()) << parsed_json.status();
ASSERT_EQ(parsed_json->type(), Json::Type::OBJECT);
ASSERT_EQ(parsed_json->type(), Json::Type::kObject);
ValidateJsonArraySize((*parsed_json->mutable_object())["channel"], 50);
ValidateJsonEnd(*parsed_json, true);
}
@ -384,7 +384,7 @@ TEST_F(ChannelzRegistryBasedTest, GetTopChannelsUuidCheck) {
std::string json_str = ChannelzRegistry::GetTopChannels(0);
auto parsed_json = Json::Parse(json_str);
ASSERT_TRUE(parsed_json.ok()) << parsed_json.status();
ASSERT_EQ(parsed_json->type(), Json::Type::OBJECT);
ASSERT_EQ(parsed_json->type(), Json::Type::kObject);
Json& array = (*parsed_json->mutable_object())["channel"];
ValidateJsonArraySize(array, kNumChannels);
std::vector<intptr_t> uuids = GetUuidListFromArray(array.array());
@ -403,7 +403,7 @@ TEST_F(ChannelzRegistryBasedTest, GetTopChannelsMiddleUuidCheck) {
std::string json_str = ChannelzRegistry::GetTopChannels(kMidQuery);
auto parsed_json = Json::Parse(json_str);
ASSERT_TRUE(parsed_json.ok()) << parsed_json.status();
ASSERT_EQ(parsed_json->type(), Json::Type::OBJECT);
ASSERT_EQ(parsed_json->type(), Json::Type::kObject);
Json& array = (*parsed_json->mutable_object())["channel"];
ValidateJsonArraySize(array, kNumChannels - kMidQuery + 1);
std::vector<intptr_t> uuids = GetUuidListFromArray(array.array());
@ -424,7 +424,7 @@ TEST_F(ChannelzRegistryBasedTest, GetTopChannelsNoHitUuid) {
std::string json_str = ChannelzRegistry::GetTopChannels(45);
auto parsed_json = Json::Parse(json_str);
ASSERT_TRUE(parsed_json.ok()) << parsed_json.status();
ASSERT_EQ(parsed_json->type(), Json::Type::OBJECT);
ASSERT_EQ(parsed_json->type(), Json::Type::kObject);
Json& array = (*parsed_json->mutable_object())["channel"];
ValidateJsonArraySize(array, 10);
std::vector<intptr_t> uuids = GetUuidListFromArray(array.array());
@ -444,7 +444,7 @@ TEST_F(ChannelzRegistryBasedTest, GetTopChannelsMoreGaps) {
std::string json_str = ChannelzRegistry::GetTopChannels(2);
auto parsed_json = Json::Parse(json_str);
ASSERT_TRUE(parsed_json.ok()) << parsed_json.status();
ASSERT_EQ(parsed_json->type(), Json::Type::OBJECT);
ASSERT_EQ(parsed_json->type(), Json::Type::kObject);
Json array = (*parsed_json->mutable_object())["channel"];
ValidateJsonArraySize(array, 2);
std::vector<intptr_t> uuids = GetUuidListFromArray(array.array());
@ -453,7 +453,7 @@ TEST_F(ChannelzRegistryBasedTest, GetTopChannelsMoreGaps) {
json_str = ChannelzRegistry::GetTopChannels(4);
parsed_json = Json::Parse(json_str);
ASSERT_TRUE(parsed_json.ok()) << parsed_json.status();
ASSERT_EQ(parsed_json->type(), Json::Type::OBJECT);
ASSERT_EQ(parsed_json->type(), Json::Type::kObject);
array = (*parsed_json->mutable_object())["channel"];
ValidateJsonArraySize(array, 1);
uuids = GetUuidListFromArray(array.array());
@ -475,7 +475,7 @@ TEST_F(ChannelzRegistryBasedTest, GetTopChannelsUuidAfterCompaction) {
std::string json_str = ChannelzRegistry::GetTopChannels(0);
auto parsed_json = Json::Parse(json_str);
ASSERT_TRUE(parsed_json.ok()) << parsed_json.status();
ASSERT_EQ(parsed_json->type(), Json::Type::OBJECT);
ASSERT_EQ(parsed_json->type(), Json::Type::kObject);
Json& array = (*parsed_json->mutable_object())["channel"];
ValidateJsonArraySize(array, kLoopIterations);
std::vector<intptr_t> uuids = GetUuidListFromArray(array.array());

@ -52,18 +52,18 @@ void ValidateArray(const Json::Array& actual, const Json::Array& expected) {
void ValidateValue(const Json& actual, const Json& expected) {
ASSERT_EQ(actual.type(), expected.type());
switch (expected.type()) {
case Json::Type::JSON_NULL:
case Json::Type::JSON_TRUE:
case Json::Type::JSON_FALSE:
case Json::Type::kNull:
case Json::Type::kTrue:
case Json::Type::kFalse:
break;
case Json::Type::STRING:
case Json::Type::NUMBER:
case Json::Type::kString:
case Json::Type::kNumber:
EXPECT_EQ(actual.string(), expected.string());
break;
case Json::Type::OBJECT:
case Json::Type::kObject:
ValidateObject(actual.object(), expected.object());
break;
case Json::Type::ARRAY:
case Json::Type::kArray:
ValidateArray(actual.array(), expected.array());
break;
}

@ -232,13 +232,13 @@ 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();
Json value = object["alg"];
ASSERT_EQ(value.type(), Json::Type::STRING);
ASSERT_EQ(value.type(), Json::Type::kString);
ASSERT_STREQ(value.string().c_str(), "RS256");
value = object["typ"];
ASSERT_EQ(value.type(), Json::Type::STRING);
ASSERT_EQ(value.type(), Json::Type::kString);
ASSERT_STREQ(value.string().c_str(), "JWT");
value = object["kid"];
ASSERT_EQ(value.type(), Json::Type::STRING);
ASSERT_EQ(value.type(), Json::Type::kString);
ASSERT_STREQ(value.string().c_str(),
"e6b5137873db8d2ef81e06a47289e6434ec8a165");
}
@ -248,35 +248,35 @@ static void check_jwt_claim(const Json& claim, const char* expected_audience,
Json::Object object = claim.object();
Json value = object["iss"];
ASSERT_EQ(value.type(), Json::Type::STRING);
ASSERT_EQ(value.type(), Json::Type::kString);
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.type(), Json::Type::kString);
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.type(), Json::Type::kString);
ASSERT_EQ(value.string(), object["iss"].string());
}
value = object["aud"];
ASSERT_EQ(value.type(), Json::Type::STRING);
ASSERT_EQ(value.type(), Json::Type::kString);
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);
ASSERT_EQ(value.type(), Json::Type::kNumber);
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);
ASSERT_EQ(value.type(), Json::Type::kNumber);
issue_time.tv_sec = strtol(value.string().c_str(), nullptr, 10);
gpr_timespec parsed_lifetime = gpr_time_sub(expiration, issue_time);
@ -343,7 +343,7 @@ static void test_jwt_encode_and_sign(
ASSERT_NE(dot, nullptr);
Json parsed_header =
parse_json_part_from_jwt(jwt, static_cast<size_t>(dot - jwt));
ASSERT_EQ(parsed_header.type(), Json::Type::OBJECT);
ASSERT_EQ(parsed_header.type(), Json::Type::kObject);
check_jwt_header(parsed_header);
offset = static_cast<size_t>(dot - jwt) + 1;
@ -351,7 +351,7 @@ static void test_jwt_encode_and_sign(
ASSERT_NE(dot, nullptr);
Json parsed_claim = parse_json_part_from_jwt(
jwt + offset, static_cast<size_t>(dot - (jwt + offset)));
ASSERT_EQ(parsed_claim.type(), Json::Type::OBJECT);
ASSERT_EQ(parsed_claim.type(), Json::Type::kObject);
check_jwt_claim_func(parsed_claim);
offset = static_cast<size_t>(dot - jwt) + 1;

@ -211,7 +211,7 @@ TEST(JwtVerifierTest, ClaimsSuccess) {
grpc_jwt_claims* claims;
auto json = Json::Parse(claims_without_time_constraint);
ASSERT_TRUE(json.ok()) << json.status();
ASSERT_EQ(json->type(), Json::Type::OBJECT);
ASSERT_EQ(json->type(), Json::Type::kObject);
grpc_core::ExecCtx exec_ctx;
claims = grpc_jwt_claims_from_json(*json);
ASSERT_NE(claims, nullptr);
@ -229,7 +229,7 @@ TEST(JwtVerifierTest, ExpiredClaimsFailure) {
grpc_jwt_claims* claims;
auto json = Json::Parse(expired_claims);
ASSERT_TRUE(json.ok()) << json.status();
ASSERT_EQ(json->type(), Json::Type::OBJECT);
ASSERT_EQ(json->type(), Json::Type::kObject);
gpr_timespec exp_iat = {100, 0, GPR_CLOCK_REALTIME};
gpr_timespec exp_exp = {120, 0, GPR_CLOCK_REALTIME};
gpr_timespec exp_nbf = {60, 0, GPR_CLOCK_REALTIME};
@ -252,7 +252,7 @@ TEST(JwtVerifierTest, ExpiredClaimsFailure) {
TEST(JwtVerifierTest, InvalidClaimsFailure) {
auto json = Json::Parse(invalid_claims);
ASSERT_TRUE(json.ok()) << json.status();
ASSERT_EQ(json->type(), Json::Type::OBJECT);
ASSERT_EQ(json->type(), Json::Type::kObject);
grpc_core::ExecCtx exec_ctx;
ASSERT_EQ(grpc_jwt_claims_from_json(*json), nullptr);
}
@ -261,7 +261,7 @@ TEST(JwtVerifierTest, BadAudienceClaimsFailure) {
grpc_jwt_claims* claims;
auto json = Json::Parse(claims_without_time_constraint);
ASSERT_TRUE(json.ok()) << json.status();
ASSERT_EQ(json->type(), Json::Type::OBJECT);
ASSERT_EQ(json->type(), Json::Type::kObject);
grpc_core::ExecCtx exec_ctx;
claims = grpc_jwt_claims_from_json(*json);
ASSERT_NE(claims, nullptr);
@ -274,7 +274,7 @@ TEST(JwtVerifierTest, BadSubjectClaimsFailure) {
grpc_jwt_claims* claims;
auto json = Json::Parse(claims_with_bad_subject);
ASSERT_TRUE(json.ok()) << json.status();
ASSERT_EQ(json->type(), Json::Type::OBJECT);
ASSERT_EQ(json->type(), Json::Type::kObject);
grpc_core::ExecCtx exec_ctx;
claims = grpc_jwt_claims_from_json(*json);
ASSERT_NE(claims, nullptr);

@ -182,12 +182,12 @@ TEST(XdsBootstrapTest, Basic) {
::testing::Pair(
::testing::Eq("bar"),
::testing::AllOf(
::testing::Property(&Json::type, Json::Type::NUMBER),
::testing::Property(&Json::type, Json::Type::kNumber),
::testing::Property(&Json::string, "2"))),
::testing::Pair(
::testing::Eq("foo"),
::testing::AllOf(
::testing::Property(&Json::type, Json::Type::NUMBER),
::testing::Property(&Json::type, Json::Type::kNumber),
::testing::Property(&Json::string, "1")))));
EXPECT_EQ(bootstrap->server_listener_resource_name_template(),
"example/resource");
@ -587,11 +587,11 @@ class FakeCertificateProviderFactory : public CertificateProviderFactory {
CreateCertificateProviderConfig(const Json& config_json,
grpc_error_handle* error) override {
std::vector<grpc_error_handle> error_list;
EXPECT_EQ(config_json.type(), Json::Type::OBJECT);
EXPECT_EQ(config_json.type(), Json::Type::kObject);
auto it = config_json.object().find("value");
if (it == config_json.object().end()) {
return MakeRefCounted<FakeCertificateProviderFactory::Config>(0);
} else if (it->second.type() != Json::Type::NUMBER) {
} else if (it->second.type() != Json::Type::kNumber) {
*error = GRPC_ERROR_CREATE("field:config field:value not of type number");
} else {
int value = 0;

@ -63,7 +63,7 @@ void VaidateProtoJsonTranslation(const std::string& json_str) {
// same as what would be generated by our JSON library.
auto parsed_json = grpc_core::Json::Parse(proto_json_str.c_str());
ASSERT_TRUE(parsed_json.ok()) << parsed_json.status();
ASSERT_EQ(parsed_json->type(), grpc_core::Json::Type::OBJECT);
ASSERT_EQ(parsed_json->type(), grpc_core::Json::Type::kObject);
proto_json_str = parsed_json->Dump();
EXPECT_EQ(json_str, proto_json_str);
}

Loading…
Cancel
Save