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
## Code Formatting
* `clang-format -i --verbose **/*.c **/*.h`
* `clang-format -i --verbose **/*.cpp **/*.h`
## Documentation
......
......@@ -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
......
......@@ -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;
......
......@@ -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;
}
......
......@@ -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
......@@ -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();
......
......@@ -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
......
0% Loading or .
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment