OmniSciDB  d2f719934e
 All Classes Namespaces Files Functions Variables Typedefs Enumerations Enumerator Friends Macros Groups 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, std::shared_ptr< TSSLSocketFactory > factory)
 
 ThriftClientConnection ()
 
std::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::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::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
 
std::shared_ptr
< TSSLSocketFactory > 
factory_
 

Detailed Description

Definition at line 33 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 35 of file ThriftClient.h.

41  : server_host_(server_host)
42  , port_(port)
43  , conn_type_(conn_type)
44  , skip_host_verify_(skip_host_verify)
45  , ca_cert_name_(ca_cert_name)
46  , 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,
std::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_.

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

Definition at line 54 of file ThriftClient.h.

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

Definition at line 144 of file ThriftClient.cpp.

144 {}

Member Function Documentation

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

Definition at line 167 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().

167  {
168  std::shared_ptr<apache::thrift::transport::TTransport> mytransport;
172  port_,
176 
177  } else {
179  }
180 
181  try {
182  mytransport->open();
183  } catch (const apache::thrift::TException& e) {
184  throw apache::thrift::TException(std::string(e.what()) + ": host " + server_host_ +
185  ", port " + std::to_string(port_));
186  }
189  return std::shared_ptr<TProtocol>(new TJSONProtocol(mytransport));
190  } else {
191  return std::shared_ptr<TProtocol>(new TBinaryProtocol(mytransport));
192  }
193 }
ThriftConnectionType conn_type_
Definition: ThriftClient.h:79
std::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::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 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:

std::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 195 of file ThriftClient.cpp.

References factory_, and using_X509_store_.

Referenced by get_protocol().

203  {
204  std::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  std::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(std::shared_ptr<InsecureAccessManager>(new InsecureAccessManager()));
214  }
215  if (!using_X509_store_ && ca_cert_name.empty()) {
216  const auto socket = std::make_shared<TSocket>(server_host, port);
217  if (with_timeout) {
218  socket->setKeepAlive(with_keepalive);
219  socket->setConnTimeout(connect_timeout);
220  socket->setRecvTimeout(recv_timeout);
221  socket->setSendTimeout(send_timeout);
222  }
223  transport = std::make_shared<TBufferedTransport>(socket);
224  } else {
225  std::shared_ptr<TSocket> secure_socket = factory_->createSocket(server_host, port);
226  if (with_timeout) {
227  secure_socket->setKeepAlive(with_keepalive);
228  secure_socket->setConnTimeout(connect_timeout);
229  secure_socket->setRecvTimeout(recv_timeout);
230  secure_socket->setSendTimeout(send_timeout);
231  }
232  transport = std::shared_ptr<TTransport>(new TBufferedTransport(secure_socket));
233  }
234 
235  return transport;
236 }
unsigned connect_timeout
unsigned send_timeout
bool with_keepalive
unsigned recv_timeout
std::shared_ptr< TSSLSocketFactory > factory_
Definition: ThriftClient.h:84

+ Here is the caller graph for this function:

std::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 238 of file ThriftClient.cpp.

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

Referenced by get_protocol().

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

+ 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().

std::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: