From c456bbbf61cbfb44c4f8b3219f78723347cafd3b Mon Sep 17 00:00:00 2001
From: Timm Fitschen <t.fitschen@indiscale.com>
Date: Wed, 30 Jun 2021 12:40:56 +0200
Subject: [PATCH] WIP: conan

---
 CMakeLists.txt                  | 15 ++++++++-------
 include/caosdb/authentication.h | 23 +++++++++++++----------
 include/caosdb/connection.h     | 27 +++++++--------------------
 include/caosdb/utils.h          |  8 ++++----
 src/caosdb/authentication.cpp   | 13 +++++++------
 src/caosdb/connection.cpp       | 27 ++++++++++++++-------------
 6 files changed, 53 insertions(+), 60 deletions(-)

diff --git a/CMakeLists.txt b/CMakeLists.txt
index 039800c..26de3c7 100644
--- a/CMakeLists.txt
+++ b/CMakeLists.txt
@@ -54,7 +54,8 @@ if(NOT clang_tidy)
     message(STATUS "clang-tidy: Not found")
 else()
     message(STATUS "clang-tidy: ${clang_tidy}")
-    set(_CMAKE_CXX_CLANG_TIDY "${clang_tidy}" "--header-filter=connection.h"
+    set(_CMAKE_CXX_CLANG_TIDY "${clang_tidy}"
+        "--header-filter=caosdb/.*[^\(\.pb\.h\)]$"
         "--checks=*,-fuchsia-*,-llvm-include-order,-llvmlibc-*"
         "--warnings-as-errors=*")
 endif()
@@ -68,12 +69,12 @@ set_target_properties(caosdb PROPERTIES
     CXX_CLANG_TIDY "${_CMAKE_CXX_CLANG_TIDY}"
     CXX_INCLUDE_WHAT_YOU_USE "${_CMAKE_CXX_INCLUDE_WHAT_YOU_USE}"
     )
-add_executable(caosdbcli src/caosdbcli.cpp)
-set_target_properties(caosdbcli PROPERTIES
-    CXX_CLANG_TIDY "${_CMAKE_CXX_CLANG_TIDY}"
-    CXX_INCLUDE_WHAT_YOU_USE "${_CMAKE_CXX_INCLUDE_WHAT_YOU_USE}"
-    )
-target_link_libraries(caosdbcli caosdb ${CONAN_LIBS})
+#add_executable(caosdbcli src/caosdbcli.cpp)
+#set_target_properties(caosdbcli PROPERTIES
+    #CXX_CLANG_TIDY "${_CMAKE_CXX_CLANG_TIDY}"
+    #CXX_INCLUDE_WHAT_YOU_USE "${_CMAKE_CXX_INCLUDE_WHAT_YOU_USE}"
+    #)
+#target_link_libraries(caosdbcli caosdb caosdb_info_v1alpha1 ${CONAN_LIBS})
 
 if("${CMAKE_BUILD_TYPE}" MATCHES "Debug")
     # supress warnings during build of gtest
diff --git a/include/caosdb/authentication.h b/include/caosdb/authentication.h
index a1fdca8..de3f984 100644
--- a/include/caosdb/authentication.h
+++ b/include/caosdb/authentication.h
@@ -27,12 +27,15 @@
  * @date 2021-06-28
  * @brief Configuration and setup of the client authentication.
  */
-#include <string>
-#include <iosfwd>
-#include <memory>
-#include <grpc/grpc.h>
-#include <grpcpp/security/credentials.h>
-#include "caosdb/utils.h"
+
+#include <grpcpp/security/credentials.h>     // for MetadataCredentialsPlugin
+#include <map>                               // for multimap
+#include <memory>                            // for shared_ptr
+#include <string>                            // for string
+#include "caosdb/utils.h"                    // for base64_encode
+#include "grpcpp/impl/codegen/status.h"      // for Status
+#include "grpcpp/impl/codegen/string_ref.h"  // for string_ref
+namespace grpc { class AuthContext; }
 
 namespace caosdb {
 namespace authentication {
@@ -47,7 +50,7 @@ using grpc::string_ref;
  */
 class Authenticator {
 public:
-  virtual auto getCallCredentials() const
+  [[nodiscard]] virtual auto getCallCredentials() const
     -> std::shared_ptr<grpc::CallCredentials> = 0;
 };
 
@@ -64,10 +67,10 @@ private:
 public:
   MetadataCredentialsPluginImpl(std::string key, std::string value);
 
-  Status
+  auto
   GetMetadata(string_ref service_url, string_ref method_name,
               const AuthContext &channel_auth_context,
-              std::multimap<grpc::string, grpc::string> *metadata) override;
+              std::multimap<grpc::string, grpc::string> *metadata) -> Status override;
 };
 
 class PlainPasswordAuthenticator : public Authenticator {
@@ -78,7 +81,7 @@ public:
   PlainPasswordAuthenticator(const std::string &username,
                              const std::string &password);
 
-  auto getCallCredentials() const
+  [[nodiscard]] auto getCallCredentials() const
     -> std::shared_ptr<grpc::CallCredentials> override;
 };
 } // namespace authentication
diff --git a/include/caosdb/connection.h b/include/caosdb/connection.h
index 978fdcc..c233dce 100644
--- a/include/caosdb/connection.h
+++ b/include/caosdb/connection.h
@@ -27,26 +27,13 @@
  * @date 2021-05-18
  * @brief Configuration and setup of the connection.
  */
-#include <string>
-#include <iosfwd>
-#include "caosdb/authentication.h"
-#include <memory>
-#include <grpc/grpc.h>
-#include <grpcpp/channel.h>
-#include <grpcpp/client_context.h>
-#include <grpcpp/create_channel.h>
-#include <grpcpp/security/credentials.h>
-#include "caosdb/info/v1alpha1/main.grpc.pb.h"
-namespace grpc {
-class ChannelCredentials;
-} // namespace grpc
-namespace caosdb {
-namespace info {
-namespace v1alpha1 {
-class VersionInfo;
-} // namespace v1alpha1
-} // namespace info
-} // namespace caosdb
+#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 caosdb { namespace info { namespace v1alpha1 { class VersionInfo; } } }
+namespace grpc { class ChannelCredentials; }
 
 namespace caosdb::connection {
 using caosdb::authentication::Authenticator;
diff --git a/include/caosdb/utils.h b/include/caosdb/utils.h
index 79393b1..e00c180 100644
--- a/include/caosdb/utils.h
+++ b/include/caosdb/utils.h
@@ -52,14 +52,14 @@ inline auto load_string_file(const std::string &path) -> std::string {
  * fall_back value.
  */
 inline auto get_env_var(const std::string &key, const std::string &fall_back)
-  -> const std::string {
+  -> std::string {
   const char *val = getenv(key.c_str());
   if (val == nullptr) {
     return fall_back;
-  } else {
-    const auto result = std::string(val);
-    return result;
   }
+
+  auto result = std::string(val);
+  return result;
 }
 
 /**
diff --git a/src/caosdb/authentication.cpp b/src/caosdb/authentication.cpp
index 5e6a89a..4ff2185 100644
--- a/src/caosdb/authentication.cpp
+++ b/src/caosdb/authentication.cpp
@@ -18,13 +18,14 @@
  * along with this program. If not, see <https://www.gnu.org/licenses/>.
  *
  */
-#include <string>
-#include <memory>
 #include "caosdb/authentication.h"
-#include <grpcpp/impl/codegen/status.h>
-#include <grpcpp/impl/codegen/string_ref.h>
-#include <map>
-#include <utility>
+#include <grpcpp/impl/codegen/status.h>      // for Status, Status::OK
+#include <grpcpp/impl/codegen/string_ref.h>  // for string_ref
+#include <map>                               // for multimap
+#include <memory>                            // for allocator, shared_ptr
+#include <string>                            // for basic_string, operator+
+#include <utility>                           // for pair, move, make_pair
+#include "grpcpp/security/credentials.h"     // for MetadataCredentialsFromP...
 
 namespace caosdb::authentication {
 using caosdb::utils::base64_encode;
diff --git a/src/caosdb/connection.cpp b/src/caosdb/connection.cpp
index 635c8bd..f7fe592 100644
--- a/src/caosdb/connection.cpp
+++ b/src/caosdb/connection.cpp
@@ -19,20 +19,21 @@
  * along with this program. If not, see <https://www.gnu.org/licenses/>.
  *
  */
-
-#include <grpcpp/create_channel.h>
-#include <grpcpp/impl/codegen/client_context.h>
-#include <grpcpp/impl/codegen/status.h>
-#include <grpcpp/security/credentials.h>
-#include <iostream>
-#include <stdexcept>
-#include <string>
-#include "caosdb/info/v1alpha1/main.grpc.pb.h"
-#include "caosdb/info/v1alpha1/main.pb.h"
-#include "caosdb/exceptions.h"
 #include "caosdb/connection.h"
-#include "caosdb/utils.h"
-#include "caosdb/authentication.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 "grpcpp/impl/codegen/status_code_enum.h"  // for StatusCode, UNAUTH...
+namespace grpc { class Channel; }
 
 namespace caosdb::connection {
 using caosdb::authentication::Authenticator;
-- 
GitLab