blob: 3cd94d449b5dff6c8807860d55803d2b52a6e257 [file] [log] [blame]
#pragma once
#include <nlohmann/json.hpp>
#include <unordered_set>
#include <vector>
constexpr const char* globalSchema = "global.json";
constexpr const char* currentConfiguration = "/var/configuration/system.json";
constexpr const char* schemaDirectory = PACKAGE_DIR "schemas";
class Configuration
{
public:
explicit Configuration(
const std::vector<std::filesystem::path>& configurationDirectories);
std::unordered_set<std::string> probeInterfaces;
std::vector<nlohmann::json> configurations;
protected:
void loadConfigurations();
void filterProbeInterfaces();
private:
std::vector<std::filesystem::path> configurationDirectories;
};
bool writeJsonFiles(const nlohmann::json& systemConfiguration);
template <typename JsonType>
bool setJsonFromPointer(const std::string& ptrStr, const JsonType& value,
nlohmann::json& systemConfiguration)
{
try
{
nlohmann::json::json_pointer ptr(ptrStr);
nlohmann::json& ref = systemConfiguration[ptr];
ref = value;
return true;
}
catch (const std::out_of_range&)
{
return false;
}
}
void deriveNewConfiguration(const nlohmann::json& oldConfiguration,
nlohmann::json& newConfiguration);
bool validateJson(const nlohmann::json& schemaFile,
const nlohmann::json& input);