| 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 <memory> |
| 19 |
#include <string> |
| 20 |
#include <utility> |
| 21 |
#include <vector> |
| 22 |
|
| 23 |
#include <grpc/grpc.h> |
| 24 |
#include <grpc/grpc_security.h> |
| 25 |
#include <grpc/impl/codegen/grpc_types.h> |
| 26 |
#include <grpcpp/channel.h> |
| 27 |
#include <grpcpp/security/credentials.h> |
| 28 |
#include <grpcpp/support/channel_arguments.h> |
| 29 |
#include <grpcpp/support/client_interceptor.h> |
| 30 |
|
| 31 |
#include "src/cpp/client/create_channel_internal.h" |
| 32 |
|
| 33 |
namespace grpc { |
| 34 |
|
| 35 |
namespace { |
| 36 |
class InsecureChannelCredentialsImpl final : public ChannelCredentials { |
| 37 |
public: |
| 38 |
std::shared_ptr<Channel> CreateChannelImpl( |
| 39 |
const std::string& target, const ChannelArguments& args) override { |
| 40 |
return CreateChannelWithInterceptors( |
| 41 |
target, args, |
| 42 |
std::vector<std::unique_ptr< |
| 43 |
grpc::experimental::ClientInterceptorFactoryInterface>>()); |
| 44 |
} |
| 45 |
|
| 46 |
std::shared_ptr<Channel> CreateChannelWithInterceptors( |
| 47 |
const std::string& target, const ChannelArguments& args, |
| 48 |
std::vector<std::unique_ptr< |
| 49 |
grpc::experimental::ClientInterceptorFactoryInterface>> |
| 50 |
interceptor_creators) override { |
| 51 |
grpc_channel_args channel_args; |
| 52 |
args.SetChannelArgs(&channel_args); |
| 53 |
grpc_channel_credentials* creds = grpc_insecure_credentials_create(); |
| 54 |
std::shared_ptr<Channel> channel = grpc::CreateChannelInternal( |
| 55 |
"", grpc_channel_create(target.c_str(), creds, &channel_args), |
| 56 |
std::move(interceptor_creators)); |
| 57 |
grpc_channel_credentials_release(creds); |
| 58 |
return channel; |
| 59 |
} |
| 60 |
|
| 61 |
SecureChannelCredentials* AsSecureCredentials() override { return nullptr; } |
| 62 |
|
| 63 |
private: |
| 64 |
bool IsInsecure() const override { return true; } |
| 65 |
}; |
| 66 |
} // namespace |
| 67 |
|
| 68 |
std::shared_ptr<ChannelCredentials> InsecureChannelCredentials() { |
| 69 |
return std::shared_ptr<ChannelCredentials>( |
| 70 |
new InsecureChannelCredentialsImpl()); |
| 71 |
} |
| 72 |
|
| 73 |
} // namespace grpc |