MCPcopy Create free account
hub / github.com/Icinga/icinga2 / Connect

Method Connect

lib/cli/consolecommand.cpp:526–562  ·  view source on GitHub ↗

* Connects to host:port and performs a TLS shandshake * * @returns AsioTlsStream pointer for future HTTP connections. */

Source from the content-addressed store, hash-verified

524 * @returns AsioTlsStream pointer for future HTTP connections.
525 */
526Shared<AsioTlsStream>::Ptr ConsoleCommand::Connect()
527{
528 Shared<boost::asio::ssl::context>::Ptr sslContext;
529
530 try {
531 sslContext = MakeAsioSslContext(Empty, Empty, Empty); //TODO: Add support for cert, key, ca parameters
532 } catch(const std::exception& ex) {
533 Log(LogCritical, "DebugConsole")
534 << "Cannot make SSL context: " << ex.what();
535 throw;
536 }
537
538 String host = l_Url->GetHost();
539 String port = l_Url->GetPort();
540
541 Shared<AsioTlsStream>::Ptr stream = Shared<AsioTlsStream>::Make(IoEngine::Get().GetIoContext(), *sslContext, host);
542
543 try {
544 icinga::Connect(stream->lowest_layer(), host, port);
545 } catch (const std::exception& ex) {
546 Log(LogWarning, "DebugConsole")
547 << "Cannot connect to REST API on host '" << host << "' port '" << port << "': " << ex.what();
548 throw;
549 }
550
551 auto& tlsStream (stream->next_layer());
552
553 try {
554 tlsStream.handshake(tlsStream.client);
555 } catch (const std::exception& ex) {
556 Log(LogWarning, "DebugConsole")
557 << "TLS handshake with host '" << host << "' failed: " << ex.what();
558 throw;
559 }
560
561 return stream;
562}
563
564/**
565 * Sends the request via REST API and returns the parsed response.

Callers

nothing calls this directly

Calls 7

MakeAsioSslContextFunction · 0.85
LogClass · 0.85
GetPortMethod · 0.80
handshakeMethod · 0.80
ConnectFunction · 0.50
whatMethod · 0.45
GetHostMethod · 0.45

Tested by

no test coverage detected