• Home
  • Line#
  • Scopes#
  • Navigate#
  • Raw
  • Download
1 /*
2  *
3  * Copyright 2015 gRPC authors.
4  *
5  * Licensed under the Apache License, Version 2.0 (the "License");
6  * you may not use this file except in compliance with the License.
7  * You may obtain a copy of the License at
8  *
9  *     http://www.apache.org/licenses/LICENSE-2.0
10  *
11  * Unless required by applicable law or agreed to in writing, software
12  * distributed under the License is distributed on an "AS IS" BASIS,
13  * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
14  * See the License for the specific language governing permissions and
15  * limitations under the License.
16  *
17  */
18 #include <grpcpp/security/credentials.h>
19 
20 #include <grpc/grpc.h>
21 #include <grpc/support/log.h>
22 #include <grpcpp/channel.h>
23 #include <grpcpp/support/channel_arguments.h>
24 #include <grpcpp/support/config.h>
25 #include "src/cpp/client/create_channel_internal.h"
26 
27 namespace grpc {
28 
29 namespace {
30 class InsecureChannelCredentialsImpl final : public ChannelCredentials {
31  public:
CreateChannelImpl(const std::string & target,const ChannelArguments & args)32   std::shared_ptr<Channel> CreateChannelImpl(
33       const std::string& target, const ChannelArguments& args) override {
34     return CreateChannelWithInterceptors(
35         target, args,
36         std::vector<std::unique_ptr<
37             grpc::experimental::ClientInterceptorFactoryInterface>>());
38   }
39 
CreateChannelWithInterceptors(const std::string & target,const ChannelArguments & args,std::vector<std::unique_ptr<grpc::experimental::ClientInterceptorFactoryInterface>> interceptor_creators)40   std::shared_ptr<Channel> CreateChannelWithInterceptors(
41       const std::string& target, const ChannelArguments& args,
42       std::vector<std::unique_ptr<
43           grpc::experimental::ClientInterceptorFactoryInterface>>
44           interceptor_creators) override {
45     grpc_channel_args channel_args;
46     args.SetChannelArgs(&channel_args);
47     return ::grpc::CreateChannelInternal(
48         "",
49         grpc_insecure_channel_create(target.c_str(), &channel_args, nullptr),
50         std::move(interceptor_creators));
51   }
52 
AsSecureCredentials()53   SecureChannelCredentials* AsSecureCredentials() override { return nullptr; }
54 
55  private:
IsInsecure() const56   bool IsInsecure() const override { return true; }
57 };
58 }  // namespace
59 
InsecureChannelCredentials()60 std::shared_ptr<ChannelCredentials> InsecureChannelCredentials() {
61   return std::shared_ptr<ChannelCredentials>(
62       new InsecureChannelCredentialsImpl());
63 }
64 
65 }  // namespace grpc
66