1
#pragma once
2

            
3
#include "envoy/api/api.h"
4
#include "envoy/common/platform.h"
5
#include "envoy/config/core/v3/grpc_service.pb.h"
6
#include "envoy/registry/registry.h"
7

            
8
#include "grpcpp/grpcpp.h"
9

            
10
namespace Envoy {
11
namespace Grpc {
12

            
13
grpc::SslCredentialsOptions buildSslOptionsFromConfig(
14
    const envoy::config::core::v3::GrpcService::GoogleGrpc::SslCredentials& ssl_config);
15

            
16
std::shared_ptr<grpc::ChannelCredentials>
17
getGoogleGrpcChannelCredentials(const envoy::config::core::v3::GrpcService& grpc_service,
18
                                Api::Api& api);
19

            
20
class CredsUtility {
21
public:
22
  /**
23
   * Translation from envoy::config::core::v3::GrpcService::GoogleGrpc to grpc::ChannelCredentials
24
   * for channel credentials.
25
   * @param google_grpc Google gRPC config.
26
   * @param api reference to the Api object
27
   * @return std::shared_ptr<grpc::ChannelCredentials> channel credentials. A nullptr
28
   *         will be returned in the absence of any configured credentials.
29
   */
30
  static std::shared_ptr<grpc::ChannelCredentials>
31
  getChannelCredentials(const envoy::config::core::v3::GrpcService::GoogleGrpc& google_grpc,
32
                        Api::Api& api);
33

            
34
  /**
35
   * Static translation from envoy::config::core::v3::GrpcService::GoogleGrpc to a vector of
36
   * grpc::CallCredentials. Any plugin based call credentials will be elided.
37
   * @param grpc_service Google gRPC config.
38
   * @return std::vector<std::shared_ptr<grpc::CallCredentials>> call credentials.
39
   */
40
  static std::vector<std::shared_ptr<grpc::CallCredentials>>
41
  callCredentials(const envoy::config::core::v3::GrpcService::GoogleGrpc& google_grpc);
42

            
43
  /**
44
   * Default translation from envoy::config::core::v3::GrpcService::GoogleGrpc to
45
   * grpc::ChannelCredentials for SSL channel credentials.
46
   * @param grpc_service_config gRPC service config.
47
   * @param api reference to the Api object
48
   * @return std::shared_ptr<grpc::ChannelCredentials> SSL channel credentials. Empty SSL
49
   *         credentials will be set in the absence of any configured SSL in grpc_service_config,
50
   *         forcing the channel to SSL.
51
   */
52
  static std::shared_ptr<grpc::ChannelCredentials>
53
  defaultSslChannelCredentials(const envoy::config::core::v3::GrpcService& grpc_service_config,
54
                               Api::Api& api);
55

            
56
  /**
57
   * Default static translation from envoy::config::core::v3::GrpcService::GoogleGrpc to
58
   * grpc::ChannelCredentials for all non-plugin based channel and call credentials.
59
   * @param grpc_service_config gRPC service config.
60
   * @param api reference to the Api object
61
   * @return std::shared_ptr<grpc::ChannelCredentials> composite channel and call credentials.
62
   *         will be set in the absence of any configured SSL in grpc_service_config, forcing the
63
   *         channel to SSL.
64
   */
65
  static std::shared_ptr<grpc::ChannelCredentials>
66
  defaultChannelCredentials(const envoy::config::core::v3::GrpcService& grpc_service_config,
67
                            Api::Api& api);
68
};
69
DECLARE_FACTORY(DefaultGoogleGrpcCredentialsFactory);
70

            
71
} // namespace Grpc
72
} // namespace Envoy