caosdb/configuration.h

namespace caosdb::configuration

Variables

const std::string logger_name = "caosdb::configuration"
class ConfigurationManager
#include <configuration.h>

Reads the configuration file and keeps the configuration. Singleton.

Currently, this class can only read a single configuration file. No merging or overwriting is supported.

Public Functions

ConfigurationManager(ConfigurationManager const&) = delete
void operator=(ConfigurationManager const&) = delete

Public Static Functions

static inline ConfigurationManager &GetInstance()
static inline auto Reset() noexcept -> int

See mReset.

static inline auto Clear() noexcept -> int

See mClear.

static inline auto LoadSingleJSONConfiguration(const path &json_file) -> void

See mLoadSingleJSONConfiguration.

static inline auto GetConnectionConfiguration(const std::string &name) -> std::unique_ptr<ConnectionConfiguration>

See mGetConnectionConfiguration.

static inline auto GetDefaultConnectionConfiguration() -> std::unique_ptr<ConnectionConfiguration>

Return the ConnectionConfiguration for the default connection.

static inline auto GetDefaultConnectionName() -> std::string

See mGetDefaultConnectionName.

Private Functions

inline ConfigurationManager()
auto InitializeDefaults() -> int

Initialize this ConfigurationManager with the defaults.

Currently, this means, that the ConfigurationManager attempts to load the first existing file from the LIBCAOSDB_CONFIGURATION_FILES_PRECEDENCE list of file locations.

auto GetConfiguration() const -> const object&

Return a json object representing the current configuration.

auto GetConnections() const -> const object&

Return the connection configurations.

auto GetConnection(const std::string &name) const -> const object&

Return the configuration for the connection with the given name (as a json object).

auto mReset() noexcept -> int

Reset this ConfigurationManager.

The current configuration is deleted and a new configuration is being loaded via InitializeDefaults.

auto mClear() noexcept -> int

Clear this ConfigurationManager.

Afterwards, this ConfigurationManager is uninitilized.

In contrast to mReset, this method only deletes the current configuration but does not load a new one via InitializeDefaults.

auto mLoadSingleJSONConfiguration(const path &json_file) -> void

Load a configuration from a json file.

auto mGetConnectionConfiguration(const std::string &name) const -> std::unique_ptr<ConnectionConfiguration>

Return the ConnectionConfiguration for the connection of the given name.

auto mGetDefaultConnectionName() const -> std::string

Return the ConnectionConfiguration for the default connection.

Private Members

value json_configuration
ConnectionConfigurationHelper connection_configuration_helper
LoggingConfigurationHelper logging_configuration_helper
class ConnectionConfiguration
#include <configuration.h>

Configuration of the CaosDB connection.

Subclassed by caosdb::configuration::InsecureConnectionConfiguration, caosdb::configuration::TlsConnectionConfiguration

Public Functions

ConnectionConfiguration(const std::string &host, int port)
virtual ~ConnectionConfiguration() = default
virtual auto ToString() const -> std::string = 0
auto GetHost() const -> std::string
auto GetPort() const -> int
virtual auto GetChannelCredentials() const -> std::shared_ptr<ChannelCredentials> = 0

Private Members

std::string host
int port

Friends

friend friend auto operator<< (std::ostream &out, const ConnectionConfiguration &configuration) -> std::ostream &
class ConnectionConfigurationHelper
#include <configuration.h>

Helper class (no state, just member functions) which should only be used by the ConfigurationManager to construct Connection instances from the stored configuration.

Private Functions

auto CreateCertificateProvider(const object &from) const -> std::unique_ptr<CertificateProvider>
Parameters

from – - a single connection configuration.

auto CreateAuthenticator(const object &from) const -> std::unique_ptr<Authenticator>
Parameters

from – - a single connection configuration.

auto CreateConnectionConfiguration(const bool tls, const std::string &host, const int port, const CertificateProvider *certificate_provider, const Authenticator *authenticator) const -> std::unique_ptr<ConnectionConfiguration>
Parameters

from – - a single connection configuration.

auto IsTls(const object &from) const -> bool
Parameters

from – - a single connection configuration.

auto CreateConnectionConfiguration(const object &from) const -> std::unique_ptr<ConnectionConfiguration>
Parameters

from – - a single connection configuration.

Friends

friend class ConfigurationManager
class InsecureConnectionConfiguration : public caosdb::configuration::ConnectionConfiguration

Public Functions

InsecureConnectionConfiguration(const std::string &host, int port)
virtual auto GetChannelCredentials() const -> std::shared_ptr<ChannelCredentials> override
virtual auto ToString() const -> std::string override

Private Members

std::shared_ptr<ChannelCredentials> credentials
class LoggingConfigurationHelper
#include <configuration.h>

Helper class (no state, just member functions) which should only be used by the ConfigurationManager to initialize the logging framework from the stored configuration.

Private Functions

auto ConvertLogLevel(const std::string &string_level) const -> int
auto CreateConsoleSinkConfiguration(const object &from, const std::string &name, int level) const -> std::shared_ptr<caosdb::logging::SinkConfiguration>
auto CreateSyslogSinkConfiguration(const object &from, const std::string &name, int level) const -> std::shared_ptr<caosdb::logging::SinkConfiguration>
auto CreateFileSinkConfiguration(const object &from, const std::string &name, int level) const -> std::shared_ptr<caosdb::logging::SinkConfiguration>
auto CreateSinkConfiguration(const object &from, const std::string &name, int default_level) const -> std::shared_ptr<caosdb::logging::SinkConfiguration>
auto CreateLoggingConfiguration(const object &from) const -> caosdb::logging::LoggingConfiguration

Friends

friend class ConfigurationManager
class TlsConnectionConfiguration : public caosdb::configuration::ConnectionConfiguration

Public Functions

TlsConnectionConfiguration(const std::string &host, int port)
TlsConnectionConfiguration(const std::string &host, int port, const Authenticator &authenticator)
TlsConnectionConfiguration(const std::string &host, int port, const CertificateProvider &certificate_provider)
TlsConnectionConfiguration(const std::string &host, int port, const CertificateProvider &certificate_provider, const Authenticator &authenticator)
virtual auto GetChannelCredentials() const -> std::shared_ptr<ChannelCredentials> override
virtual auto ToString() const -> std::string override

Private Members

std::shared_ptr<ChannelCredentials> credentials
std::string certificate_provider