Skip to content

Commit

Permalink
Merge pull request grpc#8247 from y-zeng/proto_db_check_service
Browse files Browse the repository at this point in the history
Handle partially exposed reflection service in gRPC CLI
  • Loading branch information
y-zeng authored Oct 3, 2016
2 parents 37cf028 + 7cd90c6 commit 9070ab6
Showing 1 changed file with 11 additions and 4 deletions.
15 changes: 11 additions & 4 deletions test/cpp/util/proto_file_parser.cc
Original file line number Diff line number Diff line change
Expand Up @@ -36,6 +36,7 @@
#include <algorithm>
#include <iostream>
#include <sstream>
#include <unordered_set>

#include <grpc++/support/config.h>

Expand Down Expand Up @@ -87,6 +88,7 @@ ProtoFileParser::ProtoFileParser(std::shared_ptr<grpc::Channel> channel,
reflection_db_->GetServices(&service_list);
}

std::unordered_set<grpc::string> known_services;
if (!protofiles.empty()) {
source_tree_.MapPath("", proto_path);
error_printer_.reset(new ErrorPrinter(this));
Expand All @@ -100,6 +102,7 @@ ProtoFileParser::ProtoFileParser(std::shared_ptr<grpc::Channel> channel,
if (file_desc) {
for (int i = 0; i < file_desc->service_count(); i++) {
service_desc_list_.push_back(file_desc->service(i));
known_services.insert(file_desc->service(i)->full_name());
}
} else {
std::cerr << file_name << " not found" << std::endl;
Expand Down Expand Up @@ -127,9 +130,12 @@ ProtoFileParser::ProtoFileParser(std::shared_ptr<grpc::Channel> channel,
dynamic_factory_.reset(new protobuf::DynamicMessageFactory(desc_pool_.get()));

for (auto it = service_list.begin(); it != service_list.end(); it++) {
if (const protobuf::ServiceDescriptor* service_desc =
desc_pool_->FindServiceByName(*it)) {
service_desc_list_.push_back(service_desc);
if (known_services.find(*it) == known_services.end()) {
if (const protobuf::ServiceDescriptor* service_desc =
desc_pool_->FindServiceByName(*it)) {
service_desc_list_.push_back(service_desc);
known_services.insert(*it);
}
}
}
}
Expand All @@ -146,7 +152,8 @@ grpc::string ProtoFileParser::GetFullMethodName(const grpc::string& method) {
const auto* method_desc = service_desc->method(j);
if (MethodNameMatch(method_desc->full_name(), method)) {
if (method_descriptor) {
std::ostringstream error_stream("Ambiguous method names: ");
std::ostringstream error_stream;
error_stream << "Ambiguous method names: ";
error_stream << method_descriptor->full_name() << " ";
error_stream << method_desc->full_name();
LogError(error_stream.str());
Expand Down

0 comments on commit 9070ab6

Please sign in to comment.