Skip to content
Snippets Groups Projects
Verified Commit 1cfb409a authored by Timm Fitschen's avatar Timm Fitschen
Browse files

STY: formatting

parent 365f2695
No related branches found
No related tags found
No related merge requests found
Pipeline #9588 failed
...@@ -35,7 +35,7 @@ The coverage report can be viewed in a browser by opening ...@@ -35,7 +35,7 @@ The coverage report can be viewed in a browser by opening
## Code Formatting ## Code Formatting
* `clang-format -i --verbose **/*.c **/*.h` * `clang-format -i --verbose **/*.cpp **/*.h`
## Documentation ## Documentation
......
...@@ -36,18 +36,19 @@ ...@@ -36,18 +36,19 @@
namespace caosdb { namespace caosdb {
namespace authentication { namespace authentication {
using grpc::MetadataCredentialsPlugin; using caosdb::utils::base64_encode;
using grpc::string_ref;
using grpc::AuthContext; using grpc::AuthContext;
using grpc::MetadataCredentialsPlugin;
using grpc::Status; using grpc::Status;
using caosdb::utils::base64_encode; using grpc::string_ref;
/** /**
* @brief Abstract base class for authenticators. * @brief Abstract base class for authenticators.
*/ */
class Authenticator { class Authenticator {
public: 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 { ...@@ -59,23 +60,26 @@ class MetadataCredentialsPluginImpl : public MetadataCredentialsPlugin {
private: private:
std::string key; std::string key;
std::string value; std::string value;
public: public:
MetadataCredentialsPluginImpl(std::string key, std::string value); MetadataCredentialsPluginImpl(std::string key, std::string value);
Status GetMetadata( Status
string_ref service_url, string_ref method_name, GetMetadata(string_ref service_url, string_ref method_name,
const AuthContext& channel_auth_context, const AuthContext &channel_auth_context,
std::multimap<grpc::string, grpc::string>* metadata) override; std::multimap<grpc::string, grpc::string> *metadata) override;
}; };
class PlainPasswordAuthenticator : public Authenticator { class PlainPasswordAuthenticator : public Authenticator {
private: private:
std::string basic; 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 authentication
} // namespace caosdb } // namespace caosdb
......
...@@ -49,10 +49,10 @@ class VersionInfo; ...@@ -49,10 +49,10 @@ class VersionInfo;
} // namespace caosdb } // namespace caosdb
namespace caosdb { namespace caosdb {
using caosdb::authentication::Authenticator;
using caosdb::info::v1alpha1::GeneralInfoService; using caosdb::info::v1alpha1::GeneralInfoService;
using caosdb::info::v1alpha1::VersionInfo; using caosdb::info::v1alpha1::VersionInfo;
using grpc::ChannelCredentials; using grpc::ChannelCredentials;
using caosdb::authentication::Authenticator;
class CACertificateProvider { class CACertificateProvider {
public: public:
...@@ -118,9 +118,9 @@ public: ...@@ -118,9 +118,9 @@ public:
const std::string &host, int port, const std::string &host, int port,
const std::shared_ptr<CACertificateProvider> &cacert); const std::shared_ptr<CACertificateProvider> &cacert);
SslCaosDBConnectionConfig( SslCaosDBConnectionConfig(
const std::string &host, int port, const std::string &host, int port,
const std::shared_ptr<CACertificateProvider> &cacert, const std::shared_ptr<CACertificateProvider> &cacert,
const std::shared_ptr<Authenticator> &authenticator); const std::shared_ptr<Authenticator> &authenticator);
[[nodiscard]] auto getChannelCredentials() const [[nodiscard]] auto getChannelCredentials() const
-> std::shared_ptr<ChannelCredentials> override; -> std::shared_ptr<ChannelCredentials> override;
[[nodiscard]] auto toString() const -> std::string override; [[nodiscard]] auto toString() const -> std::string override;
......
...@@ -66,7 +66,7 @@ inline auto get_env_var(const std::string &key, const std::string &fall_back) ...@@ -66,7 +66,7 @@ inline auto get_env_var(const std::string &key, const std::string &fall_back)
* @brief * @brief
* @todo use boost-beast's implementation * @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; return plain;
} }
......
...@@ -27,31 +27,36 @@ ...@@ -27,31 +27,36 @@
#include <utility> #include <utility>
namespace caosdb::authentication { namespace caosdb::authentication {
using grpc::MetadataCredentialsPlugin; using caosdb::utils::base64_encode;
using grpc::string_ref;
using grpc::AuthContext; using grpc::AuthContext;
using grpc::MetadataCredentialsPlugin;
using grpc::Status; 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( auto MetadataCredentialsPluginImpl::GetMetadata(
string_ref /*service_url*/, string_ref /*method_name*/, string_ref /*service_url*/, string_ref /*method_name*/,
const AuthContext& /*channel_auth_context*/, const AuthContext & /*channel_auth_context*/,
std::multimap<grpc::string, grpc::string>* metadata) -> Status { std::multimap<grpc::string, grpc::string> *metadata) -> Status {
metadata->insert(std::make_pair(this->key, this->value)); metadata->insert(std::make_pair(this->key, this->value));
return Status::OK; return Status::OK;
}; };
PlainPasswordAuthenticator::PlainPasswordAuthenticator(const std::string& username, const std::string& password) { PlainPasswordAuthenticator::PlainPasswordAuthenticator(
this->basic = "Basic " + base64_encode(username + ":" + password); 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 PlainPasswordAuthenticator::getCallCredentials() const
auto call_creds = grpc::MetadataCredentialsFromPlugin(std::unique_ptr<grpc::MetadataCredentialsPlugin>( -> std::shared_ptr<grpc::CallCredentials> {
new MetadataCredentialsPluginImpl("authentication", this->basic))); auto call_creds = grpc::MetadataCredentialsFromPlugin(
return call_creds; std::unique_ptr<grpc::MetadataCredentialsPlugin>(
}; new MetadataCredentialsPluginImpl("authentication", this->basic)));
return call_creds;
};
} // namespace caosdb::authentication } // namespace caosdb::authentication
...@@ -37,15 +37,20 @@ auto main() -> int { ...@@ -37,15 +37,20 @@ auto main() -> int {
<< caosdb::LIBCAOSDB_VERSION_PATCH << ")" << std::endl; << caosdb::LIBCAOSDB_VERSION_PATCH << ")" << std::endl;
std::cout << "We don't miss the H of caos." << 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 pem_file =
const auto host = caosdb::utils::get_env_var("CAOSDB_SERVER_HOST", "localhost"); caosdb::utils::get_env_var("CAOSDB_SERVER_CA_PEM", std::string());
const auto port_str = caosdb::utils::get_env_var("CAOSDB_SERVER_PORT", "8000"); 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); 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 cacert = std::make_shared<caosdb::PemFileCACertProvider>(pem_file);
auto config = auto config = std::make_shared<caosdb::SslCaosDBConnectionConfig>(
std::make_shared<caosdb::SslCaosDBConnectionConfig>(host, port, cacert, auth); host, port, cacert, auth);
caosdb::CaosDBConnection connection(config); caosdb::CaosDBConnection connection(config);
std::cout << std::endl << connection << std::endl; std::cout << std::endl << connection << std::endl;
const auto &v_info = connection.getVersionInfo(); const auto &v_info = connection.getVersionInfo();
......
...@@ -34,6 +34,7 @@ ...@@ -34,6 +34,7 @@
#include "caosdb/info/v1alpha1/main.pb.h" #include "caosdb/info/v1alpha1/main.pb.h"
namespace caosdb { namespace caosdb {
using caosdb::authentication::Authenticator;
using caosdb::info::v1alpha1::GeneralInfoService; using caosdb::info::v1alpha1::GeneralInfoService;
using caosdb::info::v1alpha1::GetVersionInfoRequest; using caosdb::info::v1alpha1::GetVersionInfoRequest;
using caosdb::info::v1alpha1::GetVersionInfoResponse; using caosdb::info::v1alpha1::GetVersionInfoResponse;
...@@ -42,7 +43,6 @@ using caosdb::utils::load_string_file; ...@@ -42,7 +43,6 @@ using caosdb::utils::load_string_file;
using grpc::InsecureChannelCredentials; using grpc::InsecureChannelCredentials;
using grpc::SslCredentials; using grpc::SslCredentials;
using grpc::SslCredentialsOptions; using grpc::SslCredentialsOptions;
using caosdb::authentication::Authenticator;
PemFileCACertProvider::PemFileCACertProvider(const std::string &path) { PemFileCACertProvider::PemFileCACertProvider(const std::string &path) {
this->cacert = load_string_file(path); this->cacert = load_string_file(path);
...@@ -111,8 +111,8 @@ SslCaosDBConnectionConfig::SslCaosDBConnectionConfig( ...@@ -111,8 +111,8 @@ SslCaosDBConnectionConfig::SslCaosDBConnectionConfig(
SslCredentialsOptions options; SslCredentialsOptions options;
options.pem_root_certs = cacert->getCACertPem(); 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 auto SslCaosDBConnectionConfig::getChannelCredentials() const
......
0% Loading or .
You are about to add 0 people to the discussion. Proceed with caution.
Please register or to comment