diff --git a/CMakeLists.txt b/CMakeLists.txt index 090c8233836ad3908e7d327a8149f51a9b19059b..30ca68bb384bde8acd891875a986b91afdb68e4b 100644 --- a/CMakeLists.txt +++ b/CMakeLists.txt @@ -58,7 +58,6 @@ add_subdirectory(include) add_subdirectory(doc) add_library(caosdb STATIC ${libcaosdb_INCL} ${libcaosdb_SRC}) -add_executable(caosdbcli src/caosdbcli.cpp) ####################################################### ### LINTING with CLANG-TIDY and INCLUDE-WHAT-YOU-USE @@ -103,10 +102,6 @@ if(_LINTING) CXX_CLANG_TIDY "${_CMAKE_CXX_CLANG_TIDY};${_CMAKE_CXX_CLANG_TIDY_CHECKS}" CXX_INCLUDE_WHAT_YOU_USE "${_CMAKE_CXX_INCLUDE_WHAT_YOU_USE}" ) - set_target_properties(caosdbcli PROPERTIES - CXX_CLANG_TIDY "${_CMAKE_CXX_CLANG_TIDY};${_CMAKE_CXX_CLANG_TIDY_CHECKS}" - CXX_INCLUDE_WHAT_YOU_USE "${_CMAKE_CXX_INCLUDE_WHAT_YOU_USE}" - ) endif() @@ -119,69 +114,7 @@ if("${CMAKE_BUILD_TYPE}" MATCHES "Debug") add_subdirectory(test) endif() -#################################################################### -### CODE GENERATION (WITH GRPC) -#################################################################### - -# Protobuf/Grpc source files -set(PROTO_FILES - ${PROJECT_SOURCE_DIR}/proto/proto/caosdb/info/v1alpha1/main.proto -) - -set(PROTO_PATH ${PROJECT_SOURCE_DIR}/proto/proto) - -# compiler binaries -set(_PROTOBUF_PROTOC "${CMAKE_BINARY_DIR}/build_tools/protoc") -set(_GRPC_CPP_PLUGIN_EXECUTABLE "${CMAKE_BINARY_DIR}/build_tools/grpc_cpp_plugin") - -# Generated sources -set(hw_hdrs_path "info/v1alpha1") -set(hw_proto_srcs "${CMAKE_CURRENT_BINARY_DIR}/include/caosdb/${hw_hdrs_path}/main.pb.cc") -set(hw_proto_hdrs "${CMAKE_CURRENT_BINARY_DIR}/include/caosdb/${hw_hdrs_path}/main.pb.h") -set(hw_grpc_srcs "${CMAKE_CURRENT_BINARY_DIR}/include/caosdb/${hw_hdrs_path}/main.grpc.pb.cc") -set(hw_grpc_hdrs "${CMAKE_CURRENT_BINARY_DIR}/include/caosdb/${hw_hdrs_path}/main.grpc.pb.h") - -# compile *proto files to cpp -set(GRPC_GENERATED_HEADERS - "${hw_proto_hdrs}" - "${hw_grpc_hdrs}") -set(GRPC_GENERATED_SOURCES - "${hw_proto_srcs}" - "${hw_grpc_srcs}") -set(GRPC_GENERATED - ${GRPC_GENERATED_SOURCES} - ${GRPC_GENERATED_HEADERS}) -add_custom_command( - OUTPUT ${GRPC_GENERATED} - COMMAND ${_PROTOBUF_PROTOC} - ARGS --grpc_out "${CMAKE_CURRENT_BINARY_DIR}/include" - --cpp_out "${CMAKE_CURRENT_BINARY_DIR}/include" - -I "${PROTO_PATH}" - --plugin=protoc-gen-grpc="${_GRPC_CPP_PLUGIN_EXECUTABLE}" - "${PROTO_FILES}" - DEPENDS "${PROTO_FILES}") - - -# hw_grpc_proto -add_library(caosdb_info_v1alpha1 - ${GRPC_GENERATED}) -target_link_libraries(caosdb_info_v1alpha1 - ${CONAN_LIBS}) -target_include_directories(caosdb_info_v1alpha1 PUBLIC - # headers to include when building from source - ${CONAN_INCLUDE_DIRS} - $<BUILD_INTERFACE:${libcaosdb_SOURCE_DIR}/include> - $<BUILD_INTERFACE:${libcaosdb_BINARY_DIR}/include> - $<INSTALL_INTERFACE:include> - ) - target_link_libraries(caosdb - caosdb_info_v1alpha1 - ${CONAN_LIBS} -) -target_link_libraries(caosdbcli - caosdb - caosdb_info_v1alpha1 ${CONAN_LIBS} ) @@ -217,12 +150,6 @@ target_include_directories(caosdb PUBLIC $<INSTALL_INTERFACE:include> ) -target_include_directories(caosdbcli PUBLIC - ${libcaosdb_SOURCE_DIR}/include> - ${libcaosdb_BINARY_DIR}/include> - ${CONAN_INCLUDE_DIRS} - ) - set(CMAKE_INSTALL_PREFIX "$ENV{HOME}/.local/") # Install libcaosdb in CMAKE_INSTALL_PREFIX (defaults to /usr/local on linux). # To change the install location, run @@ -244,7 +171,6 @@ install( # targets to install TARGETS caosdb - caosdb_info_v1alpha1 ${_GRPC_DEPS} # name of the CMake "export group" containing the targets we want to install EXPORT caosdbTargets @@ -306,7 +232,6 @@ if(AUTOFORMATTING) file(GLOB format_test_sources test/*.cpp) execute_process(COMMAND clang-format -i --verbose ${libcaosdb_INCL} ${libcaosdb_SRC} ${libcaosdb_TEST_SRC} - ${PROJECT_SOURCE_DIR}/src/caosdbcli.cpp ${format_test_sources} WORKING_DIRECTORY ${PROJECT_SOURCE_DIR}) endif() diff --git a/include/CMakeLists.txt b/include/CMakeLists.txt index a71690fae1670511fdf270f9941239404423d8cb..c3bebc2d63c13e849ed6a5894cd4cf001f63b151 100644 --- a/include/CMakeLists.txt +++ b/include/CMakeLists.txt @@ -20,16 +20,9 @@ # add all header files to this list set(libcaosdb_INCL - ${CMAKE_CURRENT_BINARY_DIR}/caosdb/constants.h - ${CMAKE_CURRENT_SOURCE_DIR}/caosdb/connection.h ${CMAKE_CURRENT_SOURCE_DIR}/caosdb/authentication.h ${CMAKE_CURRENT_SOURCE_DIR}/caosdb/utils.h - ${CMAKE_CURRENT_SOURCE_DIR}/caosdb/info.h - ${CMAKE_CURRENT_SOURCE_DIR}/caosdb/exceptions.h ) # pass variable to parent scope set(libcaosdb_INCL ${libcaosdb_INCL} PARENT_SCOPE) - -# initialize constants -configure_file(caosdb/constants.h.in caosdb/constants.h) diff --git a/include/caosdb/connection.h b/include/caosdb/connection.h deleted file mode 100644 index 7c971c0cc738447942b1d6a511ce4af4e83264d6..0000000000000000000000000000000000000000 --- a/include/caosdb/connection.h +++ /dev/null @@ -1,146 +0,0 @@ -/* - * This file is a part of the CaosDB Project. - * - * Copyright (C) 2021 Timm Fitschen <t.fitschen@indiscale.com> - * Copyright (C) 2021 IndiScale GmbH <info@indiscale.com> - * - * This program is free software: you can redistribute it and/or modify - * it under the terms of the GNU Affero General Public License as - * published by the Free Software Foundation, either version 3 of the - * License, or (at your option) any later version. - * - * This program is distributed in the hope that it will be useful, - * but WITHOUT ANY WARRANTY; without even the implied warranty of - * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the - * GNU Affero General Public License for more details. - * - * You should have received a copy of the GNU Affero General Public License - * along with this program. If not, see <https://www.gnu.org/licenses/>. - * - */ - -#ifndef CAOSDB_CONNECTION_H -#define CAOSDB_CONNECTION_H -/** - * @file caosdb/connection.h - * @author Timm Fitschen - * @date 2021-05-18 - * @brief Configuration and setup of the connection. - */ -#include <iosfwd> // for ostream -#include <memory> // for shared_ptr, unique_ptr -#include <string> // for string -#include "caosdb/info/v1alpha1/main.grpc.pb.h" // for GeneralInfoService -namespace caosdb { -namespace authentication { -class Authenticator; -} // namespace authentication -namespace info { -class VersionInfo; -} // namespace info -} // namespace caosdb -namespace grpc { -class ChannelCredentials; -} // namespace grpc - -namespace caosdb::connection { -using caosdb::authentication::Authenticator; -using caosdb::info::VersionInfo; -using caosdb::info::v1alpha1::GeneralInfoService; -using grpc::ChannelCredentials; - -class CACertificateProvider { -public: - [[nodiscard]] auto virtual getCACertPem() const -> std::string = 0; -}; - -class PemFileCACertProvider : public CACertificateProvider { -private: - std::string cacert; - -public: - explicit PemFileCACertProvider(const std::string &path); - [[nodiscard]] auto getCACertPem() const -> std::string override; -}; - -class PemCACertProvider : public CACertificateProvider { -private: - std::string cacert; - -public: - explicit PemCACertProvider(const std::string &cacert); - [[nodiscard]] auto getCACertPem() const -> std::string override; -}; - -/** - * @brief Configuration of the CaosDB connection. - */ -class CaosDBConnectionConfig { -private: - std::string host; - int port; - -public: - CaosDBConnectionConfig(const std::string &host, int port); - friend auto operator<<(std::ostream &out, - const CaosDBConnectionConfig &config) - -> std::ostream &; - - [[nodiscard]] auto virtual toString() const -> std::string = 0; - [[nodiscard]] auto getHost() const -> std::string; - [[nodiscard]] auto getPort() const -> int; - [[nodiscard]] auto virtual getChannelCredentials() const - -> std::shared_ptr<ChannelCredentials> = 0; -}; - -class InsecureCaosDBConnectionConfig : public CaosDBConnectionConfig { -private: - std::shared_ptr<ChannelCredentials> credentials; - -public: - InsecureCaosDBConnectionConfig(const std::string &host, int port); - InsecureCaosDBConnectionConfig( - const std::string &host, int port, - const std::shared_ptr<Authenticator> &authenticator); - [[nodiscard]] auto getChannelCredentials() const - -> std::shared_ptr<ChannelCredentials> override; - [[nodiscard]] auto toString() const -> std::string override; -}; - -class SslCaosDBConnectionConfig : public CaosDBConnectionConfig { -private: - std::shared_ptr<ChannelCredentials> credentials; - std::string cacert; - -public: - SslCaosDBConnectionConfig( - const std::string &host, int port, - const std::shared_ptr<CACertificateProvider> &cacert); - SslCaosDBConnectionConfig( - const std::string &host, int port, - const std::shared_ptr<CACertificateProvider> &cacert, - const std::shared_ptr<Authenticator> &authenticator); - [[nodiscard]] auto getChannelCredentials() const - -> std::shared_ptr<ChannelCredentials> override; - [[nodiscard]] auto toString() const -> std::string override; -}; - -/** - * @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_; - -public: - explicit CaosDBConnection( - const std::shared_ptr<CaosDBConnectionConfig> &config); - friend auto operator<<(std::ostream &out, const CaosDBConnection &connection) - -> std::ostream &; - [[nodiscard]] auto getGeneralInfoService() const - -> GeneralInfoService::Stub &; - [[nodiscard]] auto getVersionInfo() const -> std::unique_ptr<VersionInfo>; -}; -} // namespace caosdb::connection -#endif diff --git a/include/caosdb/exceptions.h b/include/caosdb/exceptions.h deleted file mode 100644 index 59ff3d4f08f6a8718faa2eb2e065d4ed5b04c493..0000000000000000000000000000000000000000 --- a/include/caosdb/exceptions.h +++ /dev/null @@ -1,49 +0,0 @@ -/* - * This file is a part of the CaosDB Project. - * - * Copyright (C) 2021 Timm Fitschen <t.fitschen@indiscale.com> - * Copyright (C) 2021 IndiScale GmbH <info@indiscale.com> - * - * This program is free software: you can redistribute it and/or modify - * it under the terms of the GNU Affero General Public License as - * published by the Free Software Foundation, either version 3 of the - * License, or (at your option) any later version. - * - * This program is distributed in the hope that it will be useful, - * but WITHOUT ANY WARRANTY; without even the implied warranty of - * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the - * GNU Affero General Public License for more details. - * - * You should have received a copy of the GNU Affero General Public License - * along with this program. If not, see <https://www.gnu.org/licenses/>. - * - */ - -#ifndef CAOSDB_EXCEPTIONS_H -#define CAOSDB_EXCEPTIONS_H -#include <stdexcept> -#include <string> - -namespace caosdb::exceptions { -using std::runtime_error; - -/** - * @brief Exception for authentication errors. - */ -class AuthenticationError : public runtime_error { -public: - explicit AuthenticationError(const std::string &what_arg) - : runtime_error(what_arg) {} -}; - -/** - * @brief The connection to the CaosDB server is down. - */ -class ConnectionError : public runtime_error { -public: - explicit ConnectionError(const std::string &what_arg) - : runtime_error(what_arg) {} -}; - -} // namespace caosdb::exceptions -#endif diff --git a/include/caosdb/info.h b/include/caosdb/info.h deleted file mode 100644 index e5961cd862c2dd3bc469e23bdaf4b0278e9a2980..0000000000000000000000000000000000000000 --- a/include/caosdb/info.h +++ /dev/null @@ -1,55 +0,0 @@ -/* - * This file is a part of the CaosDB Project. - * - * Copyright (C) 2021 Timm Fitschen <t.fitschen@indiscale.com> - * Copyright (C) 2021 IndiScale GmbH <info@indiscale.com> - * - * This program is free software: you can redistribute it and/or modify - * it under the terms of the GNU Affero General Public License as - * published by the Free Software Foundation, either version 3 of the - * License, or (at your option) any later version. - * - * This program is distributed in the hope that it will be useful, - * but WITHOUT ANY WARRANTY; without even the implied warranty of - * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the - * GNU Affero General Public License for more details. - * - * You should have received a copy of the GNU Affero General Public License - * along with this program. If not, see <https://www.gnu.org/licenses/>. - * - */ - -#ifndef CAOSDB_INFO_H -#define CAOSDB_INFO_H -/** - * @file caosdb/info.h - * @author Timm Fitschen - * @date 2021-07-02 - * @brief General information about the CaosDBServer. - */ -#include <cstdint> // for uint32_t -#include <string> // for string -#include "caosdb/info/v1alpha1/main.pb.h" // for VersionInfo - -namespace caosdb::info { - -using ProtoVersionInfo = caosdb::info::v1alpha1::VersionInfo; - -/** - * @brief Wrapper class for the VersionInfo protobuf. - */ -class VersionInfo { -private: - ProtoVersionInfo *info; - -public: - explicit VersionInfo(ProtoVersionInfo *info); - [[nodiscard]] auto GetMajor() const -> uint32_t; - [[nodiscard]] auto GetMinor() const -> uint32_t; - [[nodiscard]] auto GetPatch() const -> uint32_t; - [[nodiscard]] auto GetPreRelease() const -> const std::string &; - [[nodiscard]] auto GetBuild() const -> const std::string &; -}; - -} // namespace caosdb::info -#endif diff --git a/src/CMakeLists.txt b/src/CMakeLists.txt index 5f7f41cca95200ede736b84694a36b16388644cd..f2ee51d0beaa6225db7cda0d00225e7b1fce7a5c 100644 --- a/src/CMakeLists.txt +++ b/src/CMakeLists.txt @@ -22,8 +22,6 @@ # add all source files to this list set(libcaosdb_SRC ${CMAKE_CURRENT_SOURCE_DIR}/caosdb/authentication.cpp - ${CMAKE_CURRENT_SOURCE_DIR}/caosdb/connection.cpp - ${CMAKE_CURRENT_SOURCE_DIR}/caosdb/info.cpp ) # pass variable to parent scope diff --git a/src/caosdb/connection.cpp b/src/caosdb/connection.cpp deleted file mode 100644 index 81339c2d397c70b413fd7da32a9a000bfed52810..0000000000000000000000000000000000000000 --- a/src/caosdb/connection.cpp +++ /dev/null @@ -1,183 +0,0 @@ -/* - * - * This file is a part of the CaosDB Project. - * - * Copyright (C) 2021 Timm Fitschen <t.fitschen@indiscale.com> - * Copyright (C) 2021 IndiScale GmbH <info@indiscale.com> - * - * This program is free software: you can redistribute it and/or modify - * it under the terms of the GNU Affero General Public License as - * published by the Free Software Foundation, either version 3 of the - * License, or (at your option) any later version. - * - * This program is distributed in the hope that it will be useful, - * but WITHOUT ANY WARRANTY; without even the implied warranty of - * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the - * GNU Affero General Public License for more details. - * - * You should have received a copy of the GNU Affero General Public License - * along with this program. If not, see <https://www.gnu.org/licenses/>. - * - */ -#include "caosdb/connection.h" -#include <grpcpp/create_channel.h> // for CreateChannel -#include <grpcpp/impl/codegen/client_context.h> // for ClientContext -#include <grpcpp/impl/codegen/status.h> // for Status -#include <grpcpp/security/credentials.h> // for SslCredentials -#include <iostream> // for operator<<, basic_... -#include <stdexcept> // for runtime_error -#include <string> // for operator+, char_tr... -#include "caosdb/authentication.h" // for Authenticator -#include "caosdb/exceptions.h" // for AuthenticationError -#include "caosdb/info/v1alpha1/main.grpc.pb.h" // for GeneralInfoService -#include "caosdb/info/v1alpha1/main.pb.h" // for GetVersionInfoResp... -#include "caosdb/utils.h" // for load_string_file -#include "caosdb/info.h" // for VersionInfo -#include "grpcpp/impl/codegen/status_code_enum.h" // for StatusCode, UNAUTH... -namespace grpc { -class Channel; -} // namespace grpc - -namespace caosdb::connection { -using caosdb::authentication::Authenticator; -using caosdb::exceptions::AuthenticationError; -using caosdb::exceptions::ConnectionError; -using caosdb::info::VersionInfo; -using caosdb::info::v1alpha1::GeneralInfoService; -using caosdb::info::v1alpha1::GetVersionInfoRequest; -using caosdb::info::v1alpha1::GetVersionInfoResponse; -using caosdb::utils::load_string_file; -using grpc::InsecureChannelCredentials; -using grpc::SslCredentials; -using grpc::SslCredentialsOptions; - -PemFileCACertProvider::PemFileCACertProvider(const std::string &path) { - this->cacert = load_string_file(path); -} - -auto PemFileCACertProvider::getCACertPem() const -> std::string { - return this->cacert; -} - -PemCACertProvider::PemCACertProvider(const std::string &cacert) { - this->cacert = cacert; -} - -auto PemCACertProvider::getCACertPem() const -> std::string { - return this->cacert; -} - -CaosDBConnectionConfig::CaosDBConnectionConfig(const std::string &host, - int port) { - this->host = host; - this->port = port; -} - -auto CaosDBConnectionConfig::getHost() const -> std::string { - return this->host; -} - -auto CaosDBConnectionConfig::getPort() const -> int { return this->port; } - -auto operator<<(std::ostream &out, const CaosDBConnectionConfig &config) - -> std::ostream & { - out << config.toString(); - return out; -} - -InsecureCaosDBConnectionConfig::InsecureCaosDBConnectionConfig( - const std::string &host, int port) - : CaosDBConnectionConfig(host, port) { - this->credentials = InsecureChannelCredentials(); -} - -InsecureCaosDBConnectionConfig::InsecureCaosDBConnectionConfig( - const std::string &host, int port, - const std::shared_ptr<Authenticator> &authenticator) - : CaosDBConnectionConfig(host, port) { - this->credentials = grpc::CompositeChannelCredentials( - InsecureChannelCredentials(), authenticator->getCallCredentials()); -} - -auto InsecureCaosDBConnectionConfig::getChannelCredentials() const - -> std::shared_ptr<ChannelCredentials> { - return this->credentials; -} - -auto InsecureCaosDBConnectionConfig::toString() const -> std::string { - return "InsecureCaosDBConnectionConfig(" + this->getHost() + "," + - std::to_string(this->getPort()) + ")"; -} - -SslCaosDBConnectionConfig::SslCaosDBConnectionConfig( - const std::string &host, int port, - const std::shared_ptr<CACertificateProvider> &cacert) - : CaosDBConnectionConfig(host, port) { - SslCredentialsOptions options; - options.pem_root_certs = cacert->getCACertPem(); - this->cacert = cacert->getCACertPem(); - this->credentials = SslCredentials(options); -} - -SslCaosDBConnectionConfig::SslCaosDBConnectionConfig( - const std::string &host, int port, - const std::shared_ptr<CACertificateProvider> &cacert, - const std::shared_ptr<Authenticator> &authenticator) - : CaosDBConnectionConfig(host, port) { - - SslCredentialsOptions options; - options.pem_root_certs = cacert->getCACertPem(); - this->cacert = cacert->getCACertPem(); - this->credentials = grpc::CompositeChannelCredentials( - SslCredentials(options), authenticator->getCallCredentials()); -} - -auto SslCaosDBConnectionConfig::getChannelCredentials() const - -> std::shared_ptr<ChannelCredentials> { - return this->credentials; -} - -auto SslCaosDBConnectionConfig::toString() const -> std::string { - return "SslCaosDBConnectionConfig(" + this->getHost() + "," + - std::to_string(this->getPort()) + "," + this->cacert + ")"; -} - -CaosDBConnection::CaosDBConnection( - const std::shared_ptr<CaosDBConnectionConfig> &config) { - this->config = config; - const std::string target = - this->config->getHost() + ":" + std::to_string(this->config->getPort()); - this->channel = - grpc::CreateChannel(target, this->config->getChannelCredentials()); - this->stub_ = GeneralInfoService::NewStub(this->channel); -} - -auto operator<<(std::ostream &out, const CaosDBConnection &connection) - -> std::ostream & { - out << "CaosDBConnection(" << *(connection.config) << ")"; - return out; -} - -[[nodiscard]] auto CaosDBConnection::getVersionInfo() const - -> std::unique_ptr<VersionInfo> { - const GetVersionInfoRequest request; - GetVersionInfoResponse response; - grpc::ClientContext context; - const grpc::Status status = - this->stub_->GetVersionInfo(&context, request, &response); - - if (!status.ok()) { - switch (status.error_code()) { - case grpc::StatusCode::UNAUTHENTICATED: - throw AuthenticationError(status.error_message()); - case grpc::StatusCode::UNAVAILABLE: - throw ConnectionError(status.error_message()); - default: - std::cout << status.error_code() << "\n"; - throw std::runtime_error(status.error_message()); - } - } - return std::make_unique<VersionInfo>(response.release_version_info()); -} - -} // namespace caosdb::connection diff --git a/src/caosdb/info.cpp b/src/caosdb/info.cpp deleted file mode 100644 index b492dade80118abd331019adc5272511c50266d1..0000000000000000000000000000000000000000 --- a/src/caosdb/info.cpp +++ /dev/null @@ -1,50 +0,0 @@ -/* - * This file is a part of the CaosDB Project. - * - * Copyright (C) 2021 Timm Fitschen <t.fitschen@indiscale.com> - * Copyright (C) 2021 IndiScale GmbH <info@indiscale.com> - * - * This program is free software: you can redistribute it and/or modify - * it under the terms of the GNU Affero General Public License as - * published by the Free Software Foundation, either version 3 of the - * License, or (at your option) any later version. - * - * This program is distributed in the hope that it will be useful, - * but WITHOUT ANY WARRANTY; without even the implied warranty of - * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the - * GNU Affero General Public License for more details. - * - * You should have received a copy of the GNU Affero General Public License - * along with this program. If not, see <https://www.gnu.org/licenses/>. - * - */ - -#include "caosdb/info.h" -#include "caosdb/info/v1alpha1/main.pb.h" // for GetVersionInfoResponse - -namespace caosdb::info { -using ProtoVersionInfo = caosdb::info::v1alpha1::VersionInfo; - -VersionInfo::VersionInfo(ProtoVersionInfo *info) { this->info = info; } - -[[nodiscard]] auto VersionInfo::GetMajor() const -> uint32_t { - return this->info->major(); -} - -[[nodiscard]] auto VersionInfo::GetMinor() const -> uint32_t { - return this->info->minor(); -} - -[[nodiscard]] auto VersionInfo::GetPatch() const -> uint32_t { - return this->info->patch(); -} - -[[nodiscard]] auto VersionInfo::GetPreRelease() const -> const std::string & { - return this->info->pre_release(); -} - -[[nodiscard]] auto VersionInfo::GetBuild() const -> const std::string & { - return this->info->build(); -} - -} // namespace caosdb::info diff --git a/src/caosdbcli.cpp b/src/caosdbcli.cpp deleted file mode 100644 index 7dc2d718317d6d9be2f2d1166bcaa658c78b6ecf..0000000000000000000000000000000000000000 --- a/src/caosdbcli.cpp +++ /dev/null @@ -1,68 +0,0 @@ -/* - * - * This file is a part of the CaosDB Project. - * - * Copyright (C) 2021 Timm Fitschen <t.fitschen@indiscale.com> - * Copyright (C) 2021 IndiScale GmbH <info@indiscale.com> - * - * This program is free software: you can redistribute it and/or modify - * it under the terms of the GNU Affero General Public License as - * published by the Free Software Foundation, either version 3 of the - * License, or (at your option) any later version. - * - * This program is distributed in the hope that it will be useful, - * but WITHOUT ANY WARRANTY; without even the implied warranty of - * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the - * GNU Affero General Public License for more details. - * - * You should have received a copy of the GNU Affero General Public License - * along with this program. If not, see <https://www.gnu.org/licenses/>. - * - */ - -// A simple caosdb client -#include <iostream> -#include <memory> -#include <string> -#include "caosdb/constants.h" -#include "caosdb/connection.h" -#include "caosdb/authentication.h" -#include "caosdb/utils.h" -#include "caosdb/info.h" - -auto main() -> int { - - std::cout << "CaosDB (libcaosdb " << caosdb::LIBCAOSDB_VERSION_MINOR << "." - << caosdb::LIBCAOSDB_VERSION_MINOR << "." - << caosdb::LIBCAOSDB_VERSION_PATCH << ")" << std::endl; - std::cout << "We don't miss the H of caos." << std::endl; - - const auto pem_file = - caosdb::utils::get_env_var("CAOSDB_SERVER_CA_PEM", std::string()); - const auto host = - caosdb::utils::get_env_var("CAOSDB_SERVER_HOST", "localhost"); - const auto port_str = - caosdb::utils::get_env_var("CAOSDB_SERVER_PORT", "8443"); - const auto port = std::stoi(port_str); - const auto user = caosdb::utils::get_env_var("CAOSDB_USER", "admin"); - const auto password = caosdb::utils::get_env_var("CAOSDB_PASSWORD", "caosdb"); - 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>( - user, password); - auto cacert = - std::make_shared<caosdb::connection::PemFileCACertProvider>(pem_file); - auto config = std::make_shared<caosdb::connection::SslCaosDBConnectionConfig>( - host, port, cacert); - caosdb::connection::CaosDBConnection connection(config); - std::cout << std::endl << connection << std::endl; - const auto &v_info = connection.getVersionInfo(); - std::cout << "VersionInfo(" << v_info->GetMajor() << "." << v_info->GetMinor() - << "." << v_info->GetPatch() << "-" << v_info->GetPreRelease() - << "-" << v_info->GetBuild() << ")" << std::endl; - return 0; -} diff --git a/test/CMakeLists.txt b/test/CMakeLists.txt index d1e1c4df28c3f0398a26c1d87f5a2be821da2deb..cdf4a48307e293082a4eb280e2f62f555a9f6955 100644 --- a/test/CMakeLists.txt +++ b/test/CMakeLists.txt @@ -20,9 +20,8 @@ # append all the test cases here (file name without the ".cpp" suffix) set(test_cases - test_connection test_utils - test_info + test_authentication ) @@ -47,7 +46,7 @@ foreach (i RANGE "${len_test_cases}") set(libcaosdb_TEST_SRC "${CMAKE_CURRENT_SOURCE_DIR}/${test_case_name}.cpp ${libcaosdb_TEST_SRC}") target_link_libraries(${test_case_name} PRIVATE caosdb - caosdb_info_v1alpha1 ${CONAN_LIBS_GTEST} ${CONAN_LIBS_BOOST}) + ${CONAN_LIBS_GTEST} ${CONAN_LIBS_BOOST}) if(_LINTING) set_target_properties(${test_case_name} PROPERTIES diff --git a/include/caosdb/constants.h.in b/test/test_authentication.cpp similarity index 60% rename from include/caosdb/constants.h.in rename to test/test_authentication.cpp index 02c0341d17b77bbf843debea349af45b91516662..67019eee389cf02a27a78c43308972e5402a1825 100644 --- a/include/caosdb/constants.h.in +++ b/test/test_authentication.cpp @@ -1,5 +1,5 @@ + /* - * * This file is a part of the CaosDB Project. * * Copyright (C) 2021 Timm Fitschen <t.fitschen@indiscale.com> @@ -19,14 +19,18 @@ * along with this program. If not, see <https://www.gnu.org/licenses/>. * */ +#include <memory> // for allocator +#include "caosdb/authentication.h" // for PlainPasswordAuthenticator +#include "gtest/gtest_pred_impl.h" // for Test, SuiteApiResolver, TEST, Tes... + +namespace caosdb::connection { +using caosdb::authentication::PlainPasswordAuthenticator; + +TEST(test_connection, connection_ssl_authentication_error_wrong_credentials) { + const auto *const user = "not-a-user-23461237"; + const auto *const password = "very-c-cred"; + + auto auth = PlainPasswordAuthenticator(user, password); +} -#ifndef CAOSDB_CONSTANTS_H -#define CAOSDB_CONSTANTS_H -namespace caosdb { -// clang-format off -constexpr int LIBCAOSDB_VERSION_MAJOR = @libcaosdb_VERSION_MAJOR@; -constexpr int LIBCAOSDB_VERSION_MINOR = @libcaosdb_VERSION_MINOR@; -constexpr int LIBCAOSDB_VERSION_PATCH = @libcaosdb_VERSION_PATCH@; -// clang-format on -} // namespace caosdb -#endif +} // namespace caosdb::connection