diff --git a/README_SETUP.md b/README_SETUP.md index 5cbe1d42077b8d6d10473cc294a4fed783b6faee..a537665d85893a13cd5f652cfd23add2759cdbed 100644 --- a/README_SETUP.md +++ b/README_SETUP.md @@ -35,7 +35,7 @@ The coverage report can be viewed in a browser by opening ## Code Formatting -* `clang-format -i --verbose **/*.c **/*.h` +* `clang-format -i --verbose **/*.cpp **/*.h` ## Documentation diff --git a/include/authentication.h b/include/authentication.h index 25f56550e1bb89eaf986d0f115cf2b01e3ec4a12..cf8a7bf86830e682231858a180a8c95ea88287f8 100644 --- a/include/authentication.h +++ b/include/authentication.h @@ -36,18 +36,19 @@ namespace caosdb { namespace authentication { -using grpc::MetadataCredentialsPlugin; -using grpc::string_ref; +using caosdb::utils::base64_encode; using grpc::AuthContext; +using grpc::MetadataCredentialsPlugin; using grpc::Status; -using caosdb::utils::base64_encode; +using grpc::string_ref; /** * @brief Abstract base class for authenticators. */ class Authenticator { public: - virtual auto getCallCredentials() const -> std::shared_ptr<grpc::CallCredentials> = 0; + virtual auto getCallCredentials() const + -> std::shared_ptr<grpc::CallCredentials> = 0; }; /** @@ -59,23 +60,26 @@ class MetadataCredentialsPluginImpl : public MetadataCredentialsPlugin { private: std::string key; std::string value; + public: MetadataCredentialsPluginImpl(std::string key, std::string value); - Status GetMetadata( - string_ref service_url, string_ref method_name, - const AuthContext& channel_auth_context, - std::multimap<grpc::string, grpc::string>* metadata) override; + Status + GetMetadata(string_ref service_url, string_ref method_name, + const AuthContext &channel_auth_context, + std::multimap<grpc::string, grpc::string> *metadata) override; }; class PlainPasswordAuthenticator : public Authenticator { private: std::string basic; -public: - PlainPasswordAuthenticator(const std::string& username, const std::string& password); - auto getCallCredentials() const -> std::shared_ptr<grpc::CallCredentials> override; +public: + PlainPasswordAuthenticator(const std::string &username, + const std::string &password); + auto getCallCredentials() const + -> std::shared_ptr<grpc::CallCredentials> override; }; } // namespace authentication } // namespace caosdb diff --git a/include/connection.h b/include/connection.h index abe12af13d6e5f4decadf0b2d8bf81a9022c7c22..0b535fa0642e9f797dac1f6a511506a1a760ca24 100644 --- a/include/connection.h +++ b/include/connection.h @@ -49,10 +49,10 @@ class VersionInfo; } // namespace caosdb namespace caosdb { +using caosdb::authentication::Authenticator; using caosdb::info::v1alpha1::GeneralInfoService; using caosdb::info::v1alpha1::VersionInfo; using grpc::ChannelCredentials; -using caosdb::authentication::Authenticator; class CACertificateProvider { public: @@ -118,9 +118,9 @@ public: 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); + 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; diff --git a/include/utils.h b/include/utils.h index 4d7e3ea1a60026342ecac9676825ee0711356262..75e04bee03aa2abb435d740d03db5faede3fb569 100644 --- a/include/utils.h +++ b/include/utils.h @@ -66,7 +66,7 @@ inline auto get_env_var(const std::string &key, const std::string &fall_back) * @brief * @todo use boost-beast's implementation */ -inline auto base64_encode(const std::string& plain) -> std::string { +inline auto base64_encode(const std::string &plain) -> std::string { return plain; } diff --git a/src/authentication.cpp b/src/authentication.cpp index 0b7f47b755ae592a56b3dbf9b1c7c4068d15e825..9286a857b1a886e8b48f083e2ab169045102d98b 100644 --- a/src/authentication.cpp +++ b/src/authentication.cpp @@ -27,31 +27,36 @@ #include <utility> namespace caosdb::authentication { -using grpc::MetadataCredentialsPlugin; -using grpc::string_ref; +using caosdb::utils::base64_encode; using grpc::AuthContext; +using grpc::MetadataCredentialsPlugin; using grpc::Status; -using caosdb::utils::base64_encode; +using grpc::string_ref; -MetadataCredentialsPluginImpl::MetadataCredentialsPluginImpl(std::string key, std::string value) : key(std::move(key)), value(std::move(value)) {}; +MetadataCredentialsPluginImpl::MetadataCredentialsPluginImpl(std::string key, + std::string value) + : key(std::move(key)), value(std::move(value)){}; auto MetadataCredentialsPluginImpl::GetMetadata( - string_ref /*service_url*/, string_ref /*method_name*/, - const AuthContext& /*channel_auth_context*/, - std::multimap<grpc::string, grpc::string>* metadata) -> Status { + string_ref /*service_url*/, string_ref /*method_name*/, + const AuthContext & /*channel_auth_context*/, + std::multimap<grpc::string, grpc::string> *metadata) -> Status { - metadata->insert(std::make_pair(this->key, this->value)); - return Status::OK; - }; + metadata->insert(std::make_pair(this->key, this->value)); + return Status::OK; +}; -PlainPasswordAuthenticator::PlainPasswordAuthenticator(const std::string& username, const std::string& password) { - this->basic = "Basic " + base64_encode(username + ":" + password); - }; +PlainPasswordAuthenticator::PlainPasswordAuthenticator( + const std::string &username, const std::string &password) { + this->basic = "Basic " + base64_encode(username + ":" + password); +}; - auto PlainPasswordAuthenticator::getCallCredentials() const -> std::shared_ptr<grpc::CallCredentials> { - auto call_creds = grpc::MetadataCredentialsFromPlugin(std::unique_ptr<grpc::MetadataCredentialsPlugin>( - new MetadataCredentialsPluginImpl("authentication", this->basic))); - return call_creds; - }; +auto PlainPasswordAuthenticator::getCallCredentials() const + -> std::shared_ptr<grpc::CallCredentials> { + auto call_creds = grpc::MetadataCredentialsFromPlugin( + std::unique_ptr<grpc::MetadataCredentialsPlugin>( + new MetadataCredentialsPluginImpl("authentication", this->basic))); + return call_creds; +}; } // namespace caosdb::authentication diff --git a/src/caosdbcli.cpp b/src/caosdbcli.cpp index e2830885418f02938c54f217162507fb1b59bc0a..1d18c07b8036089e2e9a539b1c5a3ca44afdc3b6 100644 --- a/src/caosdbcli.cpp +++ b/src/caosdbcli.cpp @@ -37,15 +37,20 @@ auto main() -> int { << 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", "8000"); + 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", "8000"); const auto port = std::stoi(port_str); - auto auth = std::make_shared<caosdb::authentication::PlainPasswordAuthenticator>("tf", "vuY36moa"); + auto auth = + std::make_shared<caosdb::authentication::PlainPasswordAuthenticator>( + "tf", "vuY36moa"); auto cacert = std::make_shared<caosdb::PemFileCACertProvider>(pem_file); - auto config = - std::make_shared<caosdb::SslCaosDBConnectionConfig>(host, port, cacert, auth); + auto config = std::make_shared<caosdb::SslCaosDBConnectionConfig>( + host, port, cacert, auth); caosdb::CaosDBConnection connection(config); std::cout << std::endl << connection << std::endl; const auto &v_info = connection.getVersionInfo(); diff --git a/src/connection.cpp b/src/connection.cpp index 5505fb85e31fbea95ac4176747a55ff89c9f47c8..5f0d798c0579bc3b3f454293e824a0f0c73727e9 100644 --- a/src/connection.cpp +++ b/src/connection.cpp @@ -34,6 +34,7 @@ #include "caosdb/info/v1alpha1/main.pb.h" namespace caosdb { +using caosdb::authentication::Authenticator; using caosdb::info::v1alpha1::GeneralInfoService; using caosdb::info::v1alpha1::GetVersionInfoRequest; using caosdb::info::v1alpha1::GetVersionInfoResponse; @@ -42,7 +43,6 @@ using caosdb::utils::load_string_file; using grpc::InsecureChannelCredentials; using grpc::SslCredentials; using grpc::SslCredentialsOptions; -using caosdb::authentication::Authenticator; PemFileCACertProvider::PemFileCACertProvider(const std::string &path) { this->cacert = load_string_file(path); @@ -111,8 +111,8 @@ SslCaosDBConnectionConfig::SslCaosDBConnectionConfig( SslCredentialsOptions options; options.pem_root_certs = cacert->getCACertPem(); - this->credentials = grpc::CompositeChannelCredentials(SslCredentials(options), authenticator->getCallCredentials()); - + this->credentials = grpc::CompositeChannelCredentials( + SslCredentials(options), authenticator->getCallCredentials()); } auto SslCaosDBConnectionConfig::getChannelCredentials() const