Wire Sysio Wire Sysion 1.0.0
Loading...
Searching...
No Matches
sysio::http_client_plugin Class Reference

#include <http_client_plugin.hpp>

Inheritance diagram for sysio::http_client_plugin:
Collaboration diagram for sysio::http_client_plugin:

Public Member Functions

 http_client_plugin ()
 
virtual ~http_client_plugin ()
 
virtual void set_program_options (options_description &, options_description &cfg) override
 
void plugin_initialize (const variables_map &options)
 
void plugin_startup ()
 
void plugin_shutdown ()
 
http_clientget_client ()
 
- Public Member Functions inherited from appbase::plugin< http_client_plugin >
 plugin ()
 
virtual ~plugin ()
 
virtual state get_state () const override
 
virtual const std::string & name () const override
 
virtual void register_dependencies ()
 
virtual void initialize (const variables_map &options) override
 
virtual void handle_sighup () override
 
virtual void startup () override
 
virtual void shutdown () override
 
- Public Member Functions inherited from appbase::abstract_plugin
virtual ~abstract_plugin ()
 

Additional Inherited Members

- Public Types inherited from appbase::abstract_plugin
enum  state { registered , initialized , started , stopped }
 
- Protected Member Functions inherited from appbase::plugin< http_client_plugin >
 plugin (const string &name)
 

Detailed Description

Definition at line 9 of file http_client_plugin.hpp.

Constructor & Destructor Documentation

◆ http_client_plugin()

sysio::http_client_plugin::http_client_plugin ( )

Definition at line 8 of file http_client_plugin.cpp.

8:my(new http_client()){}

◆ ~http_client_plugin()

sysio::http_client_plugin::~http_client_plugin ( )
virtual

Definition at line 9 of file http_client_plugin.cpp.

9{}

Member Function Documentation

◆ get_client()

http_client & sysio::http_client_plugin::get_client ( )
inline

Definition at line 22 of file http_client_plugin.hpp.

22 {
23 return *my;
24 }

◆ plugin_initialize()

void sysio::http_client_plugin::plugin_initialize ( const variables_map & options)

Definition at line 21 of file http_client_plugin.cpp.

21 {
22 try {
23 if( options.count( "https-client-root-cert" )) {
24 const std::vector<std::string> root_pems = options["https-client-root-cert"].as<std::vector<std::string>>();
25 for( const auto& root_pem : root_pems ) {
26 std::string pem_str = root_pem;
27 if( !boost::algorithm::starts_with( pem_str, "-----BEGIN CERTIFICATE-----\n" )) {
28 try {
29 auto infile = std::ifstream( pem_str );
30 std::stringstream sstr;
31 sstr << infile.rdbuf();
32 pem_str = sstr.str();
33 SYS_ASSERT( boost::algorithm::starts_with( pem_str, "-----BEGIN CERTIFICATE-----\n" ),
34 chain::invalid_http_client_root_cert,
35 "File does not appear to be a PEM encoded certificate" );
36 } catch ( const std::bad_alloc& ) {
37 throw;
38 } catch ( const boost::interprocess::bad_alloc& ) {
39 throw;
40 } catch ( const fc::exception& e ) {
41 elog( "Failed to read PEM ${f} : ${e}", ("f", root_pem)( "e", e.to_detail_string()));
42 } catch ( const std::exception& e ) {
43 elog( "Failed to read PEM ${f} : ${e}", ("f", root_pem)( "e", fc::std_exception_wrapper::from_current_exception(e).to_detail_string()));
44 }
45 }
46
47 try {
48 my->add_cert( pem_str );
49 } catch ( const std::bad_alloc& ) {
50 throw;
51 } catch ( const boost::interprocess::bad_alloc& ) {
52 throw;
53 } catch ( const fc::exception& e ) {
54 elog( "Failed to read PEM : ${e} \n${pem}\n", ("pem", pem_str)( "e", e.to_detail_string()));
55 } catch ( const std::exception& e ) {
56 elog( "Failed to read PEM : ${e} \n${pem}\n", ("pem", pem_str)( "e", fc::std_exception_wrapper::from_current_exception(e).to_detail_string()));
57 }
58 }
59 }
60
61 my->set_verify_peers( options.at( "https-client-validate-peers" ).as<bool>());
63}
#define SYS_ASSERT(expr, exc_type, FORMAT,...)
Definition exceptions.hpp:7
Used to generate a useful error report when an exception is thrown.
Definition exception.hpp:58
std::string to_detail_string(log_level ll=log_level::all) const
static std_exception_wrapper from_current_exception(const std::exception &e)
#define FC_LOG_AND_RETHROW()
#define elog(FORMAT,...)
Definition logger.hpp:130
Here is the call graph for this function:

◆ plugin_shutdown()

void sysio::http_client_plugin::plugin_shutdown ( )

Definition at line 69 of file http_client_plugin.cpp.

69 {
70
71}

◆ plugin_startup()

void sysio::http_client_plugin::plugin_startup ( )

Definition at line 65 of file http_client_plugin.cpp.

65 {
66
67}

◆ set_program_options()

void sysio::http_client_plugin::set_program_options ( options_description & ,
options_description & cfg )
overridevirtual

Implements appbase::abstract_plugin.

Definition at line 11 of file http_client_plugin.cpp.

11 {
12 cfg.add_options()
13 ("https-client-root-cert", boost::program_options::value<vector<string>>()->composing()->multitoken(),
14 "PEM encoded trusted root certificate (or path to file containing one) used to validate any TLS connections made. (may specify multiple times)\n")
15 ("https-client-validate-peers", boost::program_options::value<bool>()->default_value(true),
16 "true: validate that the peer certificates are valid and trusted, false: ignore cert errors")
17 ;
18
19}

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