OmniSciDB  8a228a1076
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 &server_host, const int port, const ThriftConnectionType conn_type, bool skip_host_verify, mapd::shared_ptr< TSSLSocketFactory > factory)
 
 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 bool with_keepalive=true, 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 ()
 
virtual ~ThriftClientConnection ()
 

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_
 
bool using_X509_store_ = false
 
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:80
std::string ca_cert_name_
Definition: ThriftClient.h:82
std::string trust_cert_file_
Definition: ThriftClient.h:83
std::string server_host_
Definition: ThriftClient.h:78

◆ ThriftClientConnection() [2/3]

ThriftClientConnection::ThriftClientConnection ( const std::string &  server_host,
const int  port,
const ThriftConnectionType  conn_type,
bool  skip_host_verify,
mapd::shared_ptr< TSSLSocketFactory >  factory 
)

Definition at line 145 of file ThriftClient.cpp.

References BINARY_SSL, conn_type_, factory_, HTTPS, skip_host_verify_, and using_X509_store_.

151  : server_host_(server_host)
152  , port_(port)
153  , conn_type_(conn_type)
154  , skip_host_verify_(skip_host_verify)
155  , trust_cert_file_("") {
156  if (factory && (conn_type_ == ThriftConnectionType::BINARY_SSL ||
158  using_X509_store_ = true;
159  factory_ = factory;
160  factory_->ciphers("ALL:!ADH:!LOW:!EXP:!MD5:@STRENGTH");
161  if (skip_host_verify_) {
162  factory_->access(
163  mapd::shared_ptr<InsecureAccessManager>(new InsecureAccessManager()));
164  }
165  }
166 }
ThriftConnectionType conn_type_
Definition: ThriftClient.h:80
mapd::shared_ptr< TSSLSocketFactory > factory_
Definition: ThriftClient.h:85
std::string trust_cert_file_
Definition: ThriftClient.h:83
std::string server_host_
Definition: ThriftClient.h:78

◆ ThriftClientConnection() [3/3]

ThriftClientConnection::ThriftClientConnection ( )
inline

Definition at line 55 of file ThriftClient.h.

References connect_timeout, send_timeout, and with_keepalive.

55 {};

◆ ~ThriftClientConnection()

ThriftClientConnection::~ThriftClientConnection ( )
virtual

Definition at line 144 of file ThriftClient.cpp.

144 {}

Member Function Documentation

◆ get_protocol()

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

Definition at line 168 of file ThriftClient.cpp.

References ca_cert_name_, conn_type_, HTTP, HTTPS, open_buffered_client_transport(), open_http_client_transport(), port_, server_host_, skip_host_verify_, and to_string().

Referenced by RowToColumnLoader::createConnection().

168  {
169  mapd::shared_ptr<apache::thrift::transport::TTransport> mytransport;
173  port_,
177 
178  } else {
180  }
181 
182  try {
183  mytransport->open();
184  } catch (const apache::thrift::TException& e) {
185  throw apache::thrift::TException(std::string(e.what()) + ": host " + server_host_ +
186  ", port " + std::to_string(port_));
187  }
190  return mapd::shared_ptr<TProtocol>(new TJSONProtocol(mytransport));
191  } else {
192  return mapd::shared_ptr<TProtocol>(new TBinaryProtocol(mytransport));
193  }
194 }
ThriftConnectionType conn_type_
Definition: ThriftClient.h:80
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)
std::string ca_cert_name_
Definition: ThriftClient.h:82
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 bool with_keepalive=true, const unsigned connect_timeout=0, const unsigned recv_timeount=0, const unsigned send_timeout=0)
std::string server_host_
Definition: ThriftClient.h:78
+ 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 bool  with_keepalive = true,
const unsigned  connect_timeout = 0,
const unsigned  recv_timeount = 0,
const unsigned  send_timeout = 0 
)

Definition at line 196 of file ThriftClient.cpp.

References factory_, and using_X509_store_.

Referenced by get_protocol().

204  {
205  mapd::shared_ptr<TTransport> transport;
206 
207  if (!factory_ && !ca_cert_name.empty()) {
208  // need to build a factory once for ssl conection
209  factory_ =
210  mapd::shared_ptr<TSSLSocketFactory>(new TSSLSocketFactory(SSLProtocol::SSLTLS));
211  factory_->ciphers("ALL:!ADH:!LOW:!EXP:!MD5:@STRENGTH");
212  factory_->loadTrustedCertificates(ca_cert_name.c_str());
213  factory_->authenticate(false);
214  factory_->access(
215  mapd::shared_ptr<InsecureAccessManager>(new InsecureAccessManager()));
216  }
217  if (!using_X509_store_ && ca_cert_name.empty()) {
218  const auto socket = mapd::make_shared<TSocket>(server_host, port);
219  if (with_timeout) {
220  socket->setKeepAlive(with_keepalive);
221  socket->setConnTimeout(connect_timeout);
222  socket->setRecvTimeout(recv_timeout);
223  socket->setSendTimeout(send_timeout);
224  }
225  transport = mapd::make_shared<TBufferedTransport>(socket);
226  } else {
227  mapd::shared_ptr<TSocket> secure_socket = factory_->createSocket(server_host, port);
228  if (with_timeout) {
229  secure_socket->setKeepAlive(with_keepalive);
230  secure_socket->setConnTimeout(connect_timeout);
231  secure_socket->setRecvTimeout(recv_timeout);
232  secure_socket->setSendTimeout(send_timeout);
233  }
234  transport = mapd::shared_ptr<TTransport>(new TBufferedTransport(secure_socket));
235  }
236 
237  return transport;
238 }
unsigned connect_timeout
unsigned send_timeout
mapd::shared_ptr< TSSLSocketFactory > factory_
Definition: ThriftClient.h:85
bool with_keepalive
unsigned recv_timeout
+ Here is the caller graph for this function:

◆ 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 240 of file ThriftClient.cpp.

References check_standard_ca(), factory_, trust_cert_file_, and using_X509_store_.

Referenced by get_protocol().

245  {
246  trust_cert_file_ = trust_cert_fileX;
248 
249  if (!factory_) {
250  factory_ =
251  mapd::shared_ptr<TSSLSocketFactory>(new TSSLSocketFactory(SSLProtocol::SSLTLS));
252  }
253  mapd::shared_ptr<TTransport> transport;
254  mapd::shared_ptr<TTransport> socket;
255  if (use_https) {
256  if (skip_verify) {
257  factory_->authenticate(false);
258  factory_->access(
259  mapd::shared_ptr<InsecureAccessManager>(new InsecureAccessManager()));
260  }
261  if (!using_X509_store_) {
262  factory_->loadTrustedCertificates(trust_cert_file_.c_str());
263  }
264  socket = factory_->createSocket(server_host, port);
265  // transport = mapd::shared_ptr<TTransport>(new THttpClient(socket,
266  // server_host,
267  // "/"));
268  transport =
269  mapd::shared_ptr<TTransport>(new ProxyTHttpClient(socket, server_host, "/"));
270  } else {
271  transport =
272  mapd::shared_ptr<TTransport>(new ProxyTHttpClient(server_host, port, "/"));
273  }
274  return transport;
275 }
void check_standard_ca(std::string &ca_cert_file)
mapd::shared_ptr< TSSLSocketFactory > factory_
Definition: ThriftClient.h:85
std::string trust_cert_file_
Definition: ThriftClient.h:83
+ Here is the call graph for this function:
+ Here is the caller graph for this function:

Member Data Documentation

◆ ca_cert_name_

std::string ThriftClientConnection::ca_cert_name_
private

Definition at line 82 of file ThriftClient.h.

Referenced by get_protocol().

◆ conn_type_

ThriftConnectionType ThriftClientConnection::conn_type_
private

Definition at line 80 of file ThriftClient.h.

Referenced by get_protocol(), and ThriftClientConnection().

◆ factory_

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

◆ port_

int ThriftClientConnection::port_
private

Definition at line 79 of file ThriftClient.h.

Referenced by get_protocol().

◆ server_host_

std::string ThriftClientConnection::server_host_
private

Definition at line 78 of file ThriftClient.h.

Referenced by get_protocol().

◆ skip_host_verify_

bool ThriftClientConnection::skip_host_verify_
private

Definition at line 81 of file ThriftClient.h.

Referenced by get_protocol(), and ThriftClientConnection().

◆ trust_cert_file_

std::string ThriftClientConnection::trust_cert_file_
private

Definition at line 83 of file ThriftClient.h.

Referenced by open_http_client_transport().

◆ using_X509_store_

bool ThriftClientConnection::using_X509_store_ = false
private

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