diff --git a/CMakeLists.txt b/CMakeLists.txt index c803bca531d6bb691c9fae4f175850a6cc183216..063015ac36bd17bcee0661003f13fae349abbde2 100644 --- a/CMakeLists.txt +++ b/CMakeLists.txt @@ -35,6 +35,7 @@ set(CMAKE_MODULE_PATH "${PROJECT_SOURCE_DIR}/cmake" ${CMAKE_MODULE_PATH}) ########################################### ### DEPENDENCY MANAGEMENT with CONAN ########################################### +message(STATUS "Build directory ${CMAKE_BINARY_DIR}") include(${CMAKE_BINARY_DIR}/conanbuildinfo.cmake) conan_basic_setup() @@ -53,10 +54,15 @@ add_executable(caosdbcli src/caosdbcli.cpp) ### LINTING with CLANG-TIDY and INCLUDE-WHAT-YOU-USE ####################################################### -# linting is active when BUILD_TYPE == "Debug" -if("${CMAKE_BUILD_TYPE}" MATCHES "Debug") +option(LINTING "Enable linting with clang-tidy and iwyu when in non-Debug build-type" OFF) +if("${CMAKE_BUILD_TYPE}" MATCHES "Debug" OR LINTING) set(_LINTING ON) endif() +option(SKIP_LINTING "Skip linting even when in Debug build-type" OFF) +if("${CMAKE_BUILD_TYPE}" MATCHES "Debug" AND SKIP_LINTING) + message(WARNING "Skipping linting due to SKIP_LINTING option") + set(_LINTING OFF) +endif() if(_LINTING) find_program(iwyu NAMES include-what-you-use iwyu diff --git a/include/caosdb/connection.h b/include/caosdb/connection.h index 3e5be41d19abe96360b595effe72a13b6ed61ee4..7c971c0cc738447942b1d6a511ce4af4e83264d6 100644 --- a/include/caosdb/connection.h +++ b/include/caosdb/connection.h @@ -110,6 +110,7 @@ public: class SslCaosDBConnectionConfig : public CaosDBConnectionConfig { private: std::shared_ptr<ChannelCredentials> credentials; + std::string cacert; public: SslCaosDBConnectionConfig( @@ -128,6 +129,7 @@ public: * @brief A reusable connection to a CaosDBServer. */ class CaosDBConnection { + std::shared_ptr<grpc::Channel> channel; std::shared_ptr<CaosDBConnectionConfig> config; std::unique_ptr<GeneralInfoService::Stub> stub_; diff --git a/src/caosdb/connection.cpp b/src/caosdb/connection.cpp index 220513317baa0460785f06215edb6c8843cbfd3f..81339c2d397c70b413fd7da32a9a000bfed52810 100644 --- a/src/caosdb/connection.cpp +++ b/src/caosdb/connection.cpp @@ -115,6 +115,7 @@ SslCaosDBConnectionConfig::SslCaosDBConnectionConfig( : CaosDBConnectionConfig(host, port) { SslCredentialsOptions options; options.pem_root_certs = cacert->getCACertPem(); + this->cacert = cacert->getCACertPem(); this->credentials = SslCredentials(options); } @@ -126,6 +127,7 @@ SslCaosDBConnectionConfig::SslCaosDBConnectionConfig( SslCredentialsOptions options; options.pem_root_certs = cacert->getCACertPem(); + this->cacert = cacert->getCACertPem(); this->credentials = grpc::CompositeChannelCredentials( SslCredentials(options), authenticator->getCallCredentials()); } @@ -137,7 +139,7 @@ auto SslCaosDBConnectionConfig::getChannelCredentials() const auto SslCaosDBConnectionConfig::toString() const -> std::string { return "SslCaosDBConnectionConfig(" + this->getHost() + "," + - std::to_string(this->getPort()) + ")"; + std::to_string(this->getPort()) + "," + this->cacert + ")"; } CaosDBConnection::CaosDBConnection( @@ -145,9 +147,9 @@ CaosDBConnection::CaosDBConnection( this->config = config; const std::string target = this->config->getHost() + ":" + std::to_string(this->config->getPort()); - const std::shared_ptr<grpc::Channel> &channel = + this->channel = grpc::CreateChannel(target, this->config->getChannelCredentials()); - this->stub_ = GeneralInfoService::NewStub(channel); + this->stub_ = GeneralInfoService::NewStub(this->channel); } auto operator<<(std::ostream &out, const CaosDBConnection &connection) @@ -162,7 +164,7 @@ auto operator<<(std::ostream &out, const CaosDBConnection &connection) GetVersionInfoResponse response; grpc::ClientContext context; const grpc::Status status = - stub_->GetVersionInfo(&context, request, &response); + this->stub_->GetVersionInfo(&context, request, &response); if (!status.ok()) { switch (status.error_code()) { diff --git a/src/caosdbcli.cpp b/src/caosdbcli.cpp index 1aaab5423a6fdb550a68bb71f7833443cb93ff7a..7dc2d718317d6d9be2f2d1166bcaa658c78b6ecf 100644 --- a/src/caosdbcli.cpp +++ b/src/caosdbcli.cpp @@ -49,6 +49,7 @@ auto main() -> int { std::cout << "USER: " << user << "\n"; std::cout << "PORT: " << port_str << "\n"; std::cout << "HOST: " << host << "\n"; + std::cout << "CACERT: " << pem_file << "\n"; auto auth = std::make_shared<caosdb::authentication::PlainPasswordAuthenticator>( diff --git a/test/test_utils.cpp b/test/test_utils.cpp index 245b0af4a03da5afc853a02993e1bb4acbbb0c55..619caee06a4d1d6981e863058302ee15042f7b3e 100644 --- a/test/test_utils.cpp +++ b/test/test_utils.cpp @@ -28,9 +28,9 @@ #include <boost/beast/core/detail/base64.hpp> TEST(test_utils, base64_encode) { - auto test_plain = std::string("Test"); - auto test_encoded = std::string("VGVzdA=="); - ASSERT_EQ(4, test_plain.size()); - ASSERT_EQ(8, boost::beast::detail::base64::encoded_size(test_plain.size())); + auto test_plain = std::string("admin:caosdb"); + auto test_encoded = std::string("YWRtaW46Y2Fvc2Ri"); + ASSERT_EQ(12, test_plain.size()); + ASSERT_EQ(16, boost::beast::detail::base64::encoded_size(test_plain.size())); ASSERT_EQ(test_encoded, caosdb::utils::base64_encode(test_plain)); }