OmniSciDB  04ee39c94c
ThriftClientConnection Class Reference

#include <ThriftClient.h>

+ Collaboration diagram for ThriftClientConnection:

Public Member Functions

 ThriftClientConnection (const std::string &server_host, const int port, const ThriftConnectionType conn_type, bool skip_host_verify, const std::string &ca_cert_name, const std::string &trust_cert_file)
 
 ThriftClientConnection (const std::string &ca_cert_name)
 
 ThriftClientConnection ()
 
mapd::shared_ptr< TTransport > open_buffered_client_transport (const std::string &server_host, const int port, const std::string &ca_cert_name, const bool with_timeout=false, const unsigned connect_timeout=0, const unsigned recv_timeount=0, const unsigned send_timeout=0)
 
mapd::shared_ptr< TTransport > open_http_client_transport (const std::string &server_host, const int port, const std::string &trust_cert_file_, bool use_https, bool skip_verify)
 
mapd::shared_ptr< TProtocol > get_protocol ()
 

Private Attributes

std::string server_host_
 
int port_
 
ThriftConnectionType conn_type_
 
bool skip_host_verify_
 
std::string ca_cert_name_
 
std::string trust_cert_file_
 
mapd::shared_ptr< TSSLSocketFactory > factory_
 

Detailed Description

Definition at line 34 of file ThriftClient.h.

Constructor & Destructor Documentation

◆ ThriftClientConnection() [1/3]

ThriftClientConnection::ThriftClientConnection ( const std::string &  server_host,
const int  port,
const ThriftConnectionType  conn_type,
bool  skip_host_verify,
const std::string &  ca_cert_name,
const std::string &  trust_cert_file 
)
inline

Definition at line 36 of file ThriftClient.h.

42  : server_host_(server_host)
43  , port_(port)
44  , conn_type_(conn_type)
45  , skip_host_verify_(skip_host_verify)
46  , ca_cert_name_(ca_cert_name)
47  , trust_cert_file_(trust_cert_file){};
ThriftConnectionType conn_type_
Definition: ThriftClient.h:73
std::string ca_cert_name_
Definition: ThriftClient.h:75
std::string trust_cert_file_
Definition: ThriftClient.h:76
std::string server_host_
Definition: ThriftClient.h:71

◆ ThriftClientConnection() [2/3]

ThriftClientConnection::ThriftClientConnection ( const std::string &  ca_cert_name)

Definition at line 126 of file ThriftClient.cpp.

126  {
127  if (!ca_cert_name.empty()) {
128  factory_ =
129  mapd::shared_ptr<TSSLSocketFactory>(new TSSLSocketFactory(SSLProtocol::SSLTLS));
130  factory_->ciphers("ALL:!ADH:!LOW:!EXP:!MD5:@STRENGTH");
131 
132  factory_->loadTrustedCertificates(ca_cert_name.c_str());
133  factory_->authenticate(false);
134  factory_->access(
135  mapd::shared_ptr<InsecureAccessManager>(new InsecureAccessManager()));
136  }
137 }
mapd::shared_ptr< TSSLSocketFactory > factory_
Definition: ThriftClient.h:78

◆ ThriftClientConnection() [3/3]

ThriftClientConnection::ThriftClientConnection ( )
inline

Definition at line 50 of file ThriftClient.h.

References connect_timeout, and send_timeout.

50 {};

Member Function Documentation

◆ get_protocol()

mapd::shared_ptr< TProtocol > ThriftClientConnection::get_protocol ( )

Definition at line 139 of file ThriftClient.cpp.

References HTTP, HTTPS, mytransport, and to_string().

Referenced by RowToColumnLoader::createConnection().

139  {
140  mapd::shared_ptr<apache::thrift::transport::TTransport> mytransport;
144  port_,
148 
149  } else {
151  }
152 
153  try {
154  mytransport->open();
155  } catch (const apache::thrift::TException& e) {
156  throw apache::thrift::TException(std::string(e.what()) + ": host " + server_host_ +
157  ", port " + std::to_string(port_));
158  }
161  return mapd::shared_ptr<TProtocol>(new TJSONProtocol(mytransport));
162  } else {
163  return mapd::shared_ptr<TProtocol>(new TBinaryProtocol(mytransport));
164  }
165 };
ThriftConnectionType conn_type_
Definition: ThriftClient.h:73
mapd::shared_ptr< TTransport > open_http_client_transport(const std::string &server_host, const int port, const std::string &trust_cert_file_, bool use_https, bool skip_verify)
std::string to_string(char const *&&v)
mapd::shared_ptr< TTransport > open_buffered_client_transport(const std::string &server_host, const int port, const std::string &ca_cert_name, const bool with_timeout=false, const unsigned connect_timeout=0, const unsigned recv_timeount=0, const unsigned send_timeout=0)
std::string ca_cert_name_
Definition: ThriftClient.h:75
mapd::shared_ptr< apache::thrift::transport::TTransport > mytransport
std::string server_host_
Definition: ThriftClient.h:71
+ Here is the call graph for this function:
+ Here is the caller graph for this function:

◆ open_buffered_client_transport()

mapd::shared_ptr< TTransport > ThriftClientConnection::open_buffered_client_transport ( const std::string &  server_host,
const int  port,
const std::string &  ca_cert_name,
const bool  with_timeout = false,
const unsigned  connect_timeout = 0,
const unsigned  recv_timeount = 0,
const unsigned  send_timeout = 0 
)

Definition at line 167 of file ThriftClient.cpp.

174  {
175  mapd::shared_ptr<TTransport> transport;
176 
177  if (!factory_ && !ca_cert_name.empty()) {
178  // need to build a factory once for ssl conection
179  factory_ =
180  mapd::shared_ptr<TSSLSocketFactory>(new TSSLSocketFactory(SSLProtocol::SSLTLS));
181  factory_->ciphers("ALL:!ADH:!LOW:!EXP:!MD5:@STRENGTH");
182  factory_->loadTrustedCertificates(ca_cert_name.c_str());
183  factory_->authenticate(false);
184  factory_->access(
185  mapd::shared_ptr<InsecureAccessManager>(new InsecureAccessManager()));
186  }
187  if (ca_cert_name.empty()) {
188  const auto socket = mapd::make_shared<TSocket>(server_host, port);
189  if (with_timeout) {
190  socket->setConnTimeout(connect_timeout);
191  socket->setRecvTimeout(recv_timeout);
192  socket->setSendTimeout(send_timeout);
193  }
194  transport = mapd::make_shared<TBufferedTransport>(socket);
195  } else {
196  mapd::shared_ptr<TSocket> secure_socket = factory_->createSocket(server_host, port);
197  if (with_timeout) {
198  secure_socket->setConnTimeout(connect_timeout);
199  secure_socket->setRecvTimeout(recv_timeout);
200  secure_socket->setSendTimeout(send_timeout);
201  }
202  transport = mapd::shared_ptr<TTransport>(new TBufferedTransport(secure_socket));
203  }
204 
205  return transport;
206 }
unsigned connect_timeout
Definition: MapDServer.cpp:56
mapd::shared_ptr< TSSLSocketFactory > factory_
Definition: ThriftClient.h:78
unsigned send_timeout
Definition: MapDServer.cpp:58
unsigned recv_timeout
Definition: MapDServer.cpp:57

◆ open_http_client_transport()

mapd::shared_ptr< TTransport > ThriftClientConnection::open_http_client_transport ( const std::string &  server_host,
const int  port,
const std::string &  trust_cert_file_,
bool  use_https,
bool  skip_verify 
)

Definition at line 208 of file ThriftClient.cpp.

213  {
214  std::string trust_cert_file{trust_cert_file_};
215  if (trust_cert_file_.empty()) {
216  static std::list<std::string> v_known_ca_paths({
217  "/etc/ssl/certs/ca-certificates.crt",
218  "/etc/pki/tls/certs/ca-bundle.crt",
219  "/usr/share/ssl/certs/ca-bundle.crt",
220  "/usr/local/share/certs/ca-root.crt",
221  "/etc/ssl/cert.pem",
222  "/etc/ssl/ca-bundle.pem",
223  });
224  for (const auto& known_ca_path : v_known_ca_paths) {
225  if (boost::filesystem::exists(known_ca_path)) {
226  trust_cert_file = known_ca_path;
227  break;
228  }
229  }
230  }
231 
232  if (!factory_) {
233  factory_ = mapd::shared_ptr<TSSLSocketFactory>(new TSSLSocketFactory());
234  }
235  mapd::shared_ptr<TTransport> transport;
236  mapd::shared_ptr<TTransport> socket;
237  if (use_https) {
238  if (skip_verify) {
239  factory_->authenticate(false);
240  factory_->access(
241  mapd::shared_ptr<InsecureAccessManager>(new InsecureAccessManager()));
242  }
243  factory_->loadTrustedCertificates(trust_cert_file.c_str());
244  socket = factory_->createSocket(server_host, port);
245  // transport = mapd::shared_ptr<TTransport>(new THttpClient(socket,
246  // server_host,
247  // "/"));
248  transport =
249  mapd::shared_ptr<TTransport>(new ProxyTHttpClient(socket, server_host, "/"));
250  } else {
251  transport =
252  mapd::shared_ptr<TTransport>(new ProxyTHttpClient(server_host, port, "/"));
253  }
254  return transport;
255 }
mapd::shared_ptr< TSSLSocketFactory > factory_
Definition: ThriftClient.h:78
std::string trust_cert_file_
Definition: ThriftClient.h:76

Member Data Documentation

◆ ca_cert_name_

std::string ThriftClientConnection::ca_cert_name_
private

Definition at line 75 of file ThriftClient.h.

◆ conn_type_

ThriftConnectionType ThriftClientConnection::conn_type_
private

Definition at line 73 of file ThriftClient.h.

◆ factory_

mapd::shared_ptr<TSSLSocketFactory> ThriftClientConnection::factory_
private

Definition at line 78 of file ThriftClient.h.

◆ port_

int ThriftClientConnection::port_
private

Definition at line 72 of file ThriftClient.h.

◆ server_host_

std::string ThriftClientConnection::server_host_
private

Definition at line 71 of file ThriftClient.h.

◆ skip_host_verify_

bool ThriftClientConnection::skip_host_verify_
private

Definition at line 74 of file ThriftClient.h.

◆ trust_cert_file_

std::string ThriftClientConnection::trust_cert_file_
private

Definition at line 76 of file ThriftClient.h.


The documentation for this class was generated from the following files: