Fix --define=grpc_no_xds=true build

pull/24503/head
Yash Tibrewal 4 years ago
parent 004480e706
commit b62f33cd39
  1. 21
      BUILD
  2. 1
      BUILD.gn
  3. 1
      CMakeLists.txt
  4. 2
      Makefile
  5. 1
      build_autogenerated.yaml
  6. 1
      gRPC-C++.podspec
  7. 1
      grpc.gyp
  8. 39
      src/cpp/client/secure_credentials.cc
  9. 7
      src/cpp/client/secure_credentials.h
  10. 40
      src/cpp/client/xds_credentials.cc
  11. 1
      tools/doxygen/Doxyfile.c++.internal

21
BUILD

@ -42,6 +42,7 @@ config_setting(
values = {"define": "grpc_no_ares=true"},
)
# TODO(yashykt): Add a build target with this flag.
config_setting(
name = "grpc_no_xds",
values = {"define": "grpc_no_xds=true"},
@ -367,6 +368,12 @@ grpc_cc_library(
],
language = "c++",
public_hdrs = GRPCXX_PUBLIC_HDRS,
select_deps = {
"grpc_no_xds": [],
"//conditions:default": [
"grpc++_xds_credentials",
],
},
standalone = True,
deps = [
"gpr",
@ -379,6 +386,20 @@ grpc_cc_library(
],
)
grpc_cc_library(
name = "grpc++_xds_credentials",
srcs = [
"src/cpp/client/xds_credentials.cc",
],
hdrs = [
"src/cpp/client/secure_credentials.h",
],
language = "c++",
deps = [
"grpc++_base",
],
)
grpc_cc_library(
name = "grpc++_unsecure",
srcs = [

@ -1415,6 +1415,7 @@ config("grpc_config") {
"src/cpp/client/insecure_credentials.cc",
"src/cpp/client/secure_credentials.cc",
"src/cpp/client/secure_credentials.h",
"src/cpp/client/xds_credentials.cc",
"src/cpp/codegen/codegen_init.cc",
"src/cpp/common/alarm.cc",
"src/cpp/common/auth_property_iterator.cc",

@ -2656,6 +2656,7 @@ add_library(grpc++
src/cpp/client/credentials_cc.cc
src/cpp/client/insecure_credentials.cc
src/cpp/client/secure_credentials.cc
src/cpp/client/xds_credentials.cc
src/cpp/codegen/codegen_init.cc
src/cpp/common/alarm.cc
src/cpp/common/auth_property_iterator.cc

@ -2831,6 +2831,7 @@ LIBGRPC++_SRC = \
src/cpp/client/credentials_cc.cc \
src/cpp/client/insecure_credentials.cc \
src/cpp/client/secure_credentials.cc \
src/cpp/client/xds_credentials.cc \
src/cpp/codegen/codegen_init.cc \
src/cpp/common/alarm.cc \
src/cpp/common/auth_property_iterator.cc \
@ -4851,6 +4852,7 @@ src/core/tsi/ssl_transport_security.cc: $(OPENSSL_DEP)
src/core/tsi/transport_security.cc: $(OPENSSL_DEP)
src/core/tsi/transport_security_grpc.cc: $(OPENSSL_DEP)
src/cpp/client/secure_credentials.cc: $(OPENSSL_DEP)
src/cpp/client/xds_credentials.cc: $(OPENSSL_DEP)
src/cpp/common/alts_context.cc: $(OPENSSL_DEP)
src/cpp/common/alts_util.cc: $(OPENSSL_DEP)
src/cpp/common/auth_property_iterator.cc: $(OPENSSL_DEP)

@ -2295,6 +2295,7 @@ libs:
- src/cpp/client/credentials_cc.cc
- src/cpp/client/insecure_credentials.cc
- src/cpp/client/secure_credentials.cc
- src/cpp/client/xds_credentials.cc
- src/cpp/codegen/codegen_init.cc
- src/cpp/common/alarm.cc
- src/cpp/common/auth_property_iterator.cc

@ -708,6 +708,7 @@ Pod::Spec.new do |s|
'src/cpp/client/insecure_credentials.cc',
'src/cpp/client/secure_credentials.cc',
'src/cpp/client/secure_credentials.h',
'src/cpp/client/xds_credentials.cc',
'src/cpp/codegen/codegen_init.cc',
'src/cpp/common/alarm.cc',
'src/cpp/common/auth_property_iterator.cc',

@ -1388,6 +1388,7 @@
'src/cpp/client/credentials_cc.cc',
'src/cpp/client/insecure_credentials.cc',
'src/cpp/client/secure_credentials.cc',
'src/cpp/client/xds_credentials.cc',
'src/cpp/codegen/codegen_init.cc',
'src/cpp/common/alarm.cc',
'src/cpp/common/auth_property_iterator.cc',

@ -80,7 +80,8 @@ bool SecureCallCredentials::ApplyToCall(grpc_call* call) {
return grpc_call_set_credentials(call, c_creds_) == GRPC_CALL_OK;
}
namespace {
namespace internal {
std::shared_ptr<ChannelCredentials> WrapChannelCredentials(
grpc_channel_credentials* creds) {
return creds == nullptr ? nullptr
@ -88,6 +89,10 @@ std::shared_ptr<ChannelCredentials> WrapChannelCredentials(
new SecureChannelCredentials(creds));
}
} // namespace internal
namespace {
std::shared_ptr<CallCredentials> WrapCallCredentials(
grpc_call_credentials* creds) {
return creds == nullptr ? nullptr
@ -98,7 +103,7 @@ std::shared_ptr<CallCredentials> WrapCallCredentials(
std::shared_ptr<ChannelCredentials> GoogleDefaultCredentials() {
grpc::GrpcLibraryCodegen init; // To call grpc_init().
return WrapChannelCredentials(
return internal::WrapChannelCredentials(
grpc_google_default_credentials_create(nullptr));
}
@ -113,7 +118,7 @@ std::shared_ptr<ChannelCredentials> SslCredentials(
options.pem_root_certs.empty() ? nullptr : options.pem_root_certs.c_str(),
options.pem_private_key.empty() ? nullptr : &pem_key_cert_pair, nullptr,
nullptr);
return WrapChannelCredentials(c_creds);
return internal::WrapChannelCredentials(c_creds);
}
namespace experimental {
@ -278,39 +283,23 @@ std::shared_ptr<ChannelCredentials> AltsCredentials(
}
grpc_channel_credentials* c_creds = grpc_alts_credentials_create(c_options);
grpc_alts_credentials_options_destroy(c_options);
return WrapChannelCredentials(c_creds);
return internal::WrapChannelCredentials(c_creds);
}
// Builds Local Credentials
std::shared_ptr<ChannelCredentials> LocalCredentials(
grpc_local_connect_type type) {
grpc::GrpcLibraryCodegen init; // To call grpc_init().
return WrapChannelCredentials(grpc_local_credentials_create(type));
return internal::WrapChannelCredentials(grpc_local_credentials_create(type));
}
// Builds TLS Credentials given TLS options.
std::shared_ptr<ChannelCredentials> TlsCredentials(
const TlsCredentialsOptions& options) {
return WrapChannelCredentials(
return internal::WrapChannelCredentials(
grpc_tls_credentials_create(options.c_credentials_options()));
}
// Builds XDS Credentials
std::shared_ptr<ChannelCredentials> XdsCredentials(
const std::shared_ptr<ChannelCredentials>& fallback_creds) {
if (fallback_creds->IsInsecure()) {
grpc_channel_credentials* insecure_creds =
grpc_insecure_credentials_create();
auto xds_creds =
WrapChannelCredentials(grpc_xds_credentials_create(insecure_creds));
grpc_channel_credentials_release(insecure_creds);
return xds_creds;
} else {
return WrapChannelCredentials(grpc_xds_credentials_create(
fallback_creds->AsSecureCredentials()->GetRawCreds()));
}
}
} // namespace experimental
// Builds credentials for use when running in GCE
@ -373,8 +362,10 @@ std::shared_ptr<ChannelCredentials> CompositeChannelCredentials(
channel_creds->AsSecureCredentials();
SecureCallCredentials* s_call_creds = call_creds->AsSecureCredentials();
if (s_channel_creds && s_call_creds) {
return WrapChannelCredentials(grpc_composite_channel_credentials_create(
s_channel_creds->GetRawCreds(), s_call_creds->GetRawCreds(), nullptr));
return internal::WrapChannelCredentials(
grpc_composite_channel_credentials_create(
s_channel_creds->GetRawCreds(), s_call_creds->GetRawCreds(),
nullptr));
}
return nullptr;
}

@ -75,6 +75,13 @@ class SecureCallCredentials final : public CallCredentials {
grpc_call_credentials* const c_creds_;
};
namespace internal {
std::shared_ptr<ChannelCredentials> WrapChannelCredentials(
grpc_channel_credentials* creds);
} // namespace internal
namespace experimental {
// Transforms C++ STS Credentials options to core options. The pointers of the

@ -0,0 +1,40 @@
//
//
// Copyright 2020 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 "src/cpp/client/secure_credentials.h"
namespace grpc {
namespace experimental {
std::shared_ptr<ChannelCredentials> XdsCredentials(
const std::shared_ptr<ChannelCredentials>& fallback_creds) {
if (fallback_creds->IsInsecure()) {
grpc_channel_credentials* insecure_creds =
grpc_insecure_credentials_create();
auto xds_creds = internal::WrapChannelCredentials(
grpc_xds_credentials_create(insecure_creds));
grpc_channel_credentials_release(insecure_creds);
return xds_creds;
} else {
return internal::WrapChannelCredentials(grpc_xds_credentials_create(
fallback_creds->AsSecureCredentials()->GetRawCreds()));
}
}
} // namespace experimental
} // namespace grpc

@ -2111,6 +2111,7 @@ src/cpp/client/credentials_cc.cc \
src/cpp/client/insecure_credentials.cc \
src/cpp/client/secure_credentials.cc \
src/cpp/client/secure_credentials.h \
src/cpp/client/xds_credentials.cc \
src/cpp/codegen/codegen_init.cc \
src/cpp/common/alarm.cc \
src/cpp/common/auth_property_iterator.cc \

Loading…
Cancel
Save