/* Copyright (c) 2018-2019 Nokia. Licensed under the Apache License, Version 2.0 (the "License"); you may not use this file except in compliance with the License. You may obtain a copy of the License at http://www.apache.org/licenses/LICENSE-2.0 Unless required by applicable law or agreed to in writing, software distributed under the License is distributed on an "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. See the License for the specific language governing permissions and limitations under the License. */ #ifndef SHAREDDATALAYER_CONFIGURATIONREADER_HPP_ #define SHAREDDATALAYER_CONFIGURATIONREADER_HPP_ #define DB_HOST_ENV_VAR_NAME "DBAAS_SERVICE_HOST" #define DB_PORT_ENV_VAR_NAME "DBAAS_SERVICE_PORT" #include #include #include #include #include #include "private/configurationpaths.hpp" #include "private/logger.hpp" namespace shareddatalayer { class DatabaseConfiguration; class NamespaceConfigurations; class System; class ConfigurationReader { public: explicit ConfigurationReader(std::shared_ptr logger); ConfigurationReader(const Directories& directories, System& system, std::shared_ptr logger); ~ConfigurationReader(); void readDatabaseConfiguration(DatabaseConfiguration& databaseConfiguration); void readNamespaceConfigurations(NamespaceConfigurations& namespaceConfigurations); /** * Overrides existing json configuration with json format input stream given as * parameter. Does not override existing configration if existing configration * originates from environment variable. Meant for UT usage. */ void readConfigurationFromInputStream(const std::istream& input); private: const std::string dbHostEnvVariableName; std::string dbHostEnvVariableValue; const std::string dbPortEnvVariableName; std::string dbPortEnvVariableValue; boost::optional jsonDatabaseConfiguration; std::string sourceForDatabaseConfiguration; std::unordered_map> jsonNamespaceConfigurations; std::shared_ptr logger; void readConfigurationFromDirectories(const Directories& directories); template void readConfiguration(T& input, const std::string& sourceName); }; } #endif