• Home
  • Line#
  • Scopes#
  • Navigate#
  • Raw
  • Download
1 // Copyright 2024 The gRPC Authors
2 //
3 // Licensed under the Apache License, Version 2.0 (the "License");
4 // you may not use this file except in compliance with the License.
5 // You may obtain a copy of the License at
6 //
7 //     http://www.apache.org/licenses/LICENSE-2.0
8 //
9 // Unless required by applicable law or agreed to in writing, software
10 // distributed under the License is distributed on an "AS IS" BASIS,
11 // WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
12 // See the License for the specific language governing permissions and
13 // limitations under the License.
14 #include <grpc/grpc.h>
15 #include <grpc/grpc_security.h>
16 #include <grpc/support/port_platform.h>
17 #include <grpcpp/security/credentials.h>
18 #include <grpcpp/support/channel_arguments.h>
19 
20 #include <memory>
21 #include <string>
22 #include <vector>
23 
24 namespace grpc {
25 
ChannelCredentials(grpc_channel_credentials * c_creds)26 ChannelCredentials::ChannelCredentials(grpc_channel_credentials* c_creds)
27     : c_creds_(c_creds) {}
28 
~ChannelCredentials()29 ChannelCredentials::~ChannelCredentials() {
30   grpc_channel_credentials_release(c_creds_);
31 }
32 
CreateChannelWithInterceptors(const std::string & target,const ChannelArguments & args,std::vector<std::unique_ptr<grpc::experimental::ClientInterceptorFactoryInterface>> interceptor_creators)33 std::shared_ptr<Channel> ChannelCredentials::CreateChannelWithInterceptors(
34     const std::string& target, const ChannelArguments& args,
35     std::vector<
36         std::unique_ptr<grpc::experimental::ClientInterceptorFactoryInterface>>
37         interceptor_creators) {
38   grpc_channel_args channel_args;
39   args.SetChannelArgs(&channel_args);
40   return grpc::CreateChannelInternal(
41       args.GetSslTargetNameOverride(),
42       grpc_channel_create(target.c_str(), c_creds_, &channel_args),
43       std::move(interceptor_creators));
44 }
45 
46 }  // namespace grpc
47