OmniSciDB  17c254d2f8
 All Classes Namespaces Files Functions Variables Typedefs Enumerations Enumerator Friends Macros Pages
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 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::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:79
std::string ca_cert_name_
Definition: ThriftClient.h:81
std::string trust_cert_file_
Definition: ThriftClient.h:82
std::string server_host_
Definition: ThriftClient.h:77
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:79
mapd::shared_ptr< TSSLSocketFactory > factory_
Definition: ThriftClient.h:84
std::string trust_cert_file_
Definition: ThriftClient.h:82
std::string server_host_
Definition: ThriftClient.h:77
ThriftClientConnection::ThriftClientConnection ( )
inline

Definition at line 55 of file ThriftClient.h.

55 {};
ThriftClientConnection::~ThriftClientConnection ( )
virtual

Definition at line 144 of file ThriftClient.cpp.

144 {}

Member Function Documentation

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:79
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:81
std::string server_host_
Definition: ThriftClient.h:77

+ Here is the call graph for this function:

+ Here is the caller graph for this function:

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

References factory_, and using_X509_store_.

Referenced by get_protocol().

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

+ Here is the caller graph for this function:

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

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

Referenced by get_protocol().

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

+ Here is the call graph for this function:

+ Here is the caller graph for this function:

Member Data Documentation

std::string ThriftClientConnection::ca_cert_name_
private

Definition at line 81 of file ThriftClient.h.

Referenced by get_protocol().

ThriftConnectionType ThriftClientConnection::conn_type_
private

Definition at line 79 of file ThriftClient.h.

Referenced by get_protocol(), and ThriftClientConnection().

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

Definition at line 78 of file ThriftClient.h.

Referenced by get_protocol().

std::string ThriftClientConnection::server_host_
private

Definition at line 77 of file ThriftClient.h.

Referenced by get_protocol().

bool ThriftClientConnection::skip_host_verify_
private

Definition at line 80 of file ThriftClient.h.

Referenced by get_protocol(), and ThriftClientConnection().

std::string ThriftClientConnection::trust_cert_file_
private

Definition at line 82 of file ThriftClient.h.

Referenced by open_http_client_transport().

bool ThriftClientConnection::using_X509_store_ = false
private

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