Merge pull request #19021 from yashykt/validatesvccfg

Add method to validate service config json
reviewable/pr19038/r2
Yash Tibrewal 6 years ago committed by GitHub
commit d43604a8b1
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23
  1. 2
      BUILD
  2. 2
      BUILD.gn
  3. 6
      CMakeLists.txt
  4. 6
      Makefile
  5. 2
      build.yaml
  6. 2
      gRPC-C++.podspec
  7. 2
      grpc.gyp
  8. 36
      include/grpcpp/support/validate_service_config.h
  9. 40
      src/cpp/common/validate_service_config.cc
  10. 8
      test/cpp/end2end/service_config_end2end_test.cc
  11. 3
      tools/doxygen/Doxyfile.c++
  12. 2
      tools/doxygen/Doxyfile.c++.internal
  13. 3
      tools/run_tests/generated/sources_and_headers.json

@ -137,6 +137,7 @@ GRPCXX_SRCS = [
"src/cpp/common/resource_quota_cc.cc",
"src/cpp/common/rpc_method.cc",
"src/cpp/common/version_cc.cc",
"src/cpp/common/validate_service_config.cc",
"src/cpp/server/async_generic_service.cc",
"src/cpp/server/channel_argument_option.cc",
"src/cpp/server/create_default_thread_pool.cc",
@ -286,6 +287,7 @@ GRPCXX_PUBLIC_HDRS = [
"include/grpcpp/support/stub_options.h",
"include/grpcpp/support/sync_stream.h",
"include/grpcpp/support/time.h",
"include/grpcpp/support/validate_service_config.h",
]
grpc_cc_library(

@ -1139,6 +1139,7 @@ config("grpc_config") {
"include/grpcpp/support/stub_options.h",
"include/grpcpp/support/sync_stream.h",
"include/grpcpp/support/time.h",
"include/grpcpp/support/validate_service_config.h",
"src/core/ext/transport/inproc/inproc_transport.h",
"src/core/lib/avl/avl.h",
"src/core/lib/backoff/backoff.h",
@ -1338,6 +1339,7 @@ config("grpc_config") {
"src/cpp/common/secure_auth_context.h",
"src/cpp/common/secure_channel_arguments.cc",
"src/cpp/common/secure_create_auth_context.cc",
"src/cpp/common/validate_service_config.cc",
"src/cpp/common/version_cc.cc",
"src/cpp/server/async_generic_service.cc",
"src/cpp/server/channel_argument_option.cc",

@ -3043,6 +3043,7 @@ add_library(grpc++
src/cpp/common/core_codegen.cc
src/cpp/common/resource_quota_cc.cc
src/cpp/common/rpc_method.cc
src/cpp/common/validate_service_config.cc
src/cpp/common/version_cc.cc
src/cpp/server/async_generic_service.cc
src/cpp/server/channel_argument_option.cc
@ -3218,6 +3219,7 @@ foreach(_hdr
include/grpcpp/support/stub_options.h
include/grpcpp/support/sync_stream.h
include/grpcpp/support/time.h
include/grpcpp/support/validate_service_config.h
include/grpc/support/alloc.h
include/grpc/support/atm.h
include/grpc/support/atm_gcc_atomic.h
@ -3440,6 +3442,7 @@ add_library(grpc++_cronet
src/cpp/common/core_codegen.cc
src/cpp/common/resource_quota_cc.cc
src/cpp/common/rpc_method.cc
src/cpp/common/validate_service_config.cc
src/cpp/common/version_cc.cc
src/cpp/server/async_generic_service.cc
src/cpp/server/channel_argument_option.cc
@ -3835,6 +3838,7 @@ foreach(_hdr
include/grpcpp/support/stub_options.h
include/grpcpp/support/sync_stream.h
include/grpcpp/support/time.h
include/grpcpp/support/validate_service_config.h
include/grpc/support/alloc.h
include/grpc/support/atm.h
include/grpc/support/atm_gcc_atomic.h
@ -4652,6 +4656,7 @@ add_library(grpc++_unsecure
src/cpp/common/core_codegen.cc
src/cpp/common/resource_quota_cc.cc
src/cpp/common/rpc_method.cc
src/cpp/common/validate_service_config.cc
src/cpp/common/version_cc.cc
src/cpp/server/async_generic_service.cc
src/cpp/server/channel_argument_option.cc
@ -4826,6 +4831,7 @@ foreach(_hdr
include/grpcpp/support/stub_options.h
include/grpcpp/support/sync_stream.h
include/grpcpp/support/time.h
include/grpcpp/support/validate_service_config.h
include/grpc/support/alloc.h
include/grpc/support/atm.h
include/grpc/support/atm_gcc_atomic.h

@ -5435,6 +5435,7 @@ LIBGRPC++_SRC = \
src/cpp/common/core_codegen.cc \
src/cpp/common/resource_quota_cc.cc \
src/cpp/common/rpc_method.cc \
src/cpp/common/validate_service_config.cc \
src/cpp/common/version_cc.cc \
src/cpp/server/async_generic_service.cc \
src/cpp/server/channel_argument_option.cc \
@ -5575,6 +5576,7 @@ PUBLIC_HEADERS_CXX += \
include/grpcpp/support/stub_options.h \
include/grpcpp/support/sync_stream.h \
include/grpcpp/support/time.h \
include/grpcpp/support/validate_service_config.h \
include/grpc/support/alloc.h \
include/grpc/support/atm.h \
include/grpc/support/atm_gcc_atomic.h \
@ -5841,6 +5843,7 @@ LIBGRPC++_CRONET_SRC = \
src/cpp/common/core_codegen.cc \
src/cpp/common/resource_quota_cc.cc \
src/cpp/common/rpc_method.cc \
src/cpp/common/validate_service_config.cc \
src/cpp/common/version_cc.cc \
src/cpp/server/async_generic_service.cc \
src/cpp/server/channel_argument_option.cc \
@ -6200,6 +6203,7 @@ PUBLIC_HEADERS_CXX += \
include/grpcpp/support/stub_options.h \
include/grpcpp/support/sync_stream.h \
include/grpcpp/support/time.h \
include/grpcpp/support/validate_service_config.h \
include/grpc/support/alloc.h \
include/grpc/support/atm.h \
include/grpc/support/atm_gcc_atomic.h \
@ -7000,6 +7004,7 @@ LIBGRPC++_UNSECURE_SRC = \
src/cpp/common/core_codegen.cc \
src/cpp/common/resource_quota_cc.cc \
src/cpp/common/rpc_method.cc \
src/cpp/common/validate_service_config.cc \
src/cpp/common/version_cc.cc \
src/cpp/server/async_generic_service.cc \
src/cpp/server/channel_argument_option.cc \
@ -7140,6 +7145,7 @@ PUBLIC_HEADERS_CXX += \
include/grpcpp/support/stub_options.h \
include/grpcpp/support/sync_stream.h \
include/grpcpp/support/time.h \
include/grpcpp/support/validate_service_config.h \
include/grpc/support/alloc.h \
include/grpc/support/atm.h \
include/grpc/support/atm_gcc_atomic.h \

@ -1426,6 +1426,7 @@ filegroups:
- include/grpcpp/support/stub_options.h
- include/grpcpp/support/sync_stream.h
- include/grpcpp/support/time.h
- include/grpcpp/support/validate_service_config.h
headers:
- src/cpp/client/create_channel_internal.h
- src/cpp/common/channel_filter.h
@ -1450,6 +1451,7 @@ filegroups:
- src/cpp/common/core_codegen.cc
- src/cpp/common/resource_quota_cc.cc
- src/cpp/common/rpc_method.cc
- src/cpp/common/validate_service_config.cc
- src/cpp/common/version_cc.cc
- src/cpp/server/async_generic_service.cc
- src/cpp/server/channel_argument_option.cc

@ -148,6 +148,7 @@ Pod::Spec.new do |s|
'include/grpcpp/support/stub_options.h',
'include/grpcpp/support/sync_stream.h',
'include/grpcpp/support/time.h',
'include/grpcpp/support/validate_service_config.h',
'include/grpcpp/impl/codegen/async_generic_service.h',
'include/grpcpp/impl/codegen/async_stream.h',
'include/grpcpp/impl/codegen/async_unary_call.h',
@ -234,6 +235,7 @@ Pod::Spec.new do |s|
'src/cpp/common/core_codegen.cc',
'src/cpp/common/resource_quota_cc.cc',
'src/cpp/common/rpc_method.cc',
'src/cpp/common/validate_service_config.cc',
'src/cpp/common/version_cc.cc',
'src/cpp/server/async_generic_service.cc',
'src/cpp/server/channel_argument_option.cc',

@ -1463,6 +1463,7 @@
'src/cpp/common/core_codegen.cc',
'src/cpp/common/resource_quota_cc.cc',
'src/cpp/common/rpc_method.cc',
'src/cpp/common/validate_service_config.cc',
'src/cpp/common/version_cc.cc',
'src/cpp/server/async_generic_service.cc',
'src/cpp/server/channel_argument_option.cc',
@ -1619,6 +1620,7 @@
'src/cpp/common/core_codegen.cc',
'src/cpp/common/resource_quota_cc.cc',
'src/cpp/common/rpc_method.cc',
'src/cpp/common/validate_service_config.cc',
'src/cpp/common/version_cc.cc',
'src/cpp/server/async_generic_service.cc',
'src/cpp/server/channel_argument_option.cc',

@ -0,0 +1,36 @@
/*
*
* Copyright 2019 gRPC authors.
*
* Licensed under the Apache License, Version 2.0 (the "License");
* you may not use this file except in compliance with the License.
* You may obtain a copy of the License at
*
* http://www.apache.org/licenses/LICENSE-2.0
*
* Unless required by applicable law or agreed to in writing, software
* distributed under the License is distributed on an "AS IS" BASIS,
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
* See the License for the specific language governing permissions and
* limitations under the License.
*
*/
#ifndef GRPCPP_SUPPORT_VALIDATE_SERVICE_CONFIG_H
#define GRPCPP_SUPPORT_VALIDATE_SERVICE_CONFIG_H
#include <grpcpp/support/config.h>
namespace grpc {
namespace experimental {
/// Validates \a service_config_json. If valid, returns an empty string.
/// Otherwise, returns the validation error.
/// TODO(yashykt): Promote it to out of experimental once it is proved useful
/// and gRFC is accepted.
grpc::string ValidateServiceConfigJSON(const grpc::string& service_config_json);
} // namespace experimental
} // namespace grpc
#endif // GRPCPP_SUPPORT_VALIDATE_SERVICE_CONFIG_H

@ -0,0 +1,40 @@
/*
*
* Copyright 2019 gRPC authors.
*
* Licensed under the Apache License, Version 2.0 (the "License");
* you may not use this file except in compliance with the License.
* You may obtain a copy of the License at
*
* http://www.apache.org/licenses/LICENSE-2.0
*
* Unless required by applicable law or agreed to in writing, software
* distributed under the License is distributed on an "AS IS" BASIS,
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
* See the License for the specific language governing permissions and
* limitations under the License.
*
*/
#include <grpc/grpc.h>
#include <grpcpp/support/validate_service_config.h>
#include "src/core/ext/filters/client_channel/service_config.h"
namespace grpc {
namespace experimental {
grpc::string ValidateServiceConfigJSON(
const grpc::string& service_config_json) {
grpc_init();
grpc_error* error = GRPC_ERROR_NONE;
grpc_core::ServiceConfig::Create(service_config_json.c_str(), &error);
grpc::string return_value;
if (error != GRPC_ERROR_NONE) {
return_value = grpc_error_string(error);
GRPC_ERROR_UNREF(error);
}
grpc_shutdown();
return return_value;
}
} // namespace experimental
} // namespace grpc

@ -36,6 +36,7 @@
#include <grpcpp/impl/codegen/sync.h>
#include <grpcpp/server.h>
#include <grpcpp/server_builder.h>
#include <grpcpp/support/validate_service_config.h>
#include "src/core/ext/filters/client_channel/backup_poller.h"
#include "src/core/ext/filters/client_channel/global_subchannel_pool.h"
@ -231,6 +232,9 @@ class ServiceConfigEnd2endTest : public ::testing::Test {
std::shared_ptr<Channel> BuildChannelWithDefaultServiceConfig() {
ChannelArguments args;
EXPECT_THAT(grpc::experimental::ValidateServiceConfigJSON(
ValidDefaultServiceConfig()),
::testing::StrEq(""));
args.SetServiceConfigJSON(ValidDefaultServiceConfig());
args.SetPointer(GRPC_ARG_FAKE_RESOLVER_RESPONSE_GENERATOR,
response_generator_.get());
@ -239,6 +243,10 @@ class ServiceConfigEnd2endTest : public ::testing::Test {
std::shared_ptr<Channel> BuildChannelWithInvalidDefaultServiceConfig() {
ChannelArguments args;
EXPECT_THAT(
grpc::experimental::ValidateServiceConfigJSON(
InvalidDefaultServiceConfig()),
::testing::HasSubstr("failed to parse JSON for service config"));
args.SetServiceConfigJSON(InvalidDefaultServiceConfig());
args.SetPointer(GRPC_ARG_FAKE_RESOLVER_RESPONSE_GENERATOR,
response_generator_.get());

@ -1040,7 +1040,8 @@ include/grpcpp/support/status_code_enum.h \
include/grpcpp/support/string_ref.h \
include/grpcpp/support/stub_options.h \
include/grpcpp/support/sync_stream.h \
include/grpcpp/support/time.h
include/grpcpp/support/time.h \
include/grpcpp/support/validate_service_config.h
# This tag can be used to specify the character encoding of the source files
# that doxygen parses. Internally doxygen uses the UTF-8 encoding. Doxygen uses

@ -1043,6 +1043,7 @@ include/grpcpp/support/string_ref.h \
include/grpcpp/support/stub_options.h \
include/grpcpp/support/sync_stream.h \
include/grpcpp/support/time.h \
include/grpcpp/support/validate_service_config.h \
src/core/ext/filters/client_channel/health/health.pb.c \
src/core/ext/filters/client_channel/health/health.pb.h \
src/core/ext/transport/inproc/inproc_transport.h \
@ -1245,6 +1246,7 @@ src/cpp/common/secure_auth_context.cc \
src/cpp/common/secure_auth_context.h \
src/cpp/common/secure_channel_arguments.cc \
src/cpp/common/secure_create_auth_context.cc \
src/cpp/common/validate_service_config.cc \
src/cpp/common/version_cc.cc \
src/cpp/server/async_generic_service.cc \
src/cpp/server/channel_argument_option.cc \

@ -10404,6 +10404,7 @@
"include/grpcpp/support/stub_options.h",
"include/grpcpp/support/sync_stream.h",
"include/grpcpp/support/time.h",
"include/grpcpp/support/validate_service_config.h",
"src/cpp/client/create_channel_internal.h",
"src/cpp/common/channel_filter.h",
"src/cpp/server/dynamic_thread_pool.h",
@ -10530,6 +10531,7 @@
"include/grpcpp/support/stub_options.h",
"include/grpcpp/support/sync_stream.h",
"include/grpcpp/support/time.h",
"include/grpcpp/support/validate_service_config.h",
"src/cpp/client/channel_cc.cc",
"src/cpp/client/client_context.cc",
"src/cpp/client/client_interceptor.cc",
@ -10547,6 +10549,7 @@
"src/cpp/common/core_codegen.cc",
"src/cpp/common/resource_quota_cc.cc",
"src/cpp/common/rpc_method.cc",
"src/cpp/common/validate_service_config.cc",
"src/cpp/common/version_cc.cc",
"src/cpp/server/async_generic_service.cc",
"src/cpp/server/channel_argument_option.cc",

Loading…
Cancel
Save