blob: b3b2cdc11c8136175fb9c71adf4ad3b225378e94 [file] [log] [blame]
Christopher Meisbdaa6b22025-04-02 10:49:02 +02001#pragma once
2
3#include <nlohmann/json.hpp>
4
5#include <list>
6#include <set>
7
8namespace configuration
9{
10constexpr const char* globalSchema = "global.json";
11constexpr const char* hostConfigurationDirectory = SYSCONF_DIR "configurations";
12constexpr const char* configurationDirectory = PACKAGE_DIR "configurations";
13constexpr const char* currentConfiguration = "/var/configuration/system.json";
14constexpr const char* schemaDirectory = PACKAGE_DIR "configurations/schemas";
15
16bool writeJsonFiles(const nlohmann::json& systemConfiguration);
17
18bool loadConfigurations(std::list<nlohmann::json>& configurations);
19
20template <typename JsonType>
21bool setJsonFromPointer(const std::string& ptrStr, const JsonType& value,
22 nlohmann::json& systemConfiguration)
23{
24 try
25 {
26 nlohmann::json::json_pointer ptr(ptrStr);
27 nlohmann::json& ref = systemConfiguration[ptr];
28 ref = value;
29 return true;
30 }
31 catch (const std::out_of_range&)
32 {
33 return false;
34 }
35}
36
37void deriveNewConfiguration(const nlohmann::json& oldConfiguration,
38 nlohmann::json& newConfiguration);
39
40bool validateJson(const nlohmann::json& schemaFile,
41 const nlohmann::json& input);
42
43std::set<std::string> getProbeInterfaces();
44
45} // namespace configuration