blob: f7f0b3149aaa8b89a3ea847e87072517b647e814 [file] [log] [blame]
Christopher Meisbdaa6b22025-04-02 10:49:02 +02001#pragma once
2
3#include <nlohmann/json.hpp>
4
Christopher Meisf7252572025-06-11 13:22:05 +02005#include <unordered_set>
6#include <vector>
Christopher Meisbdaa6b22025-04-02 10:49:02 +02007
Christopher Meisbdaa6b22025-04-02 10:49:02 +02008constexpr const char* globalSchema = "global.json";
9constexpr const char* hostConfigurationDirectory = SYSCONF_DIR "configurations";
10constexpr const char* configurationDirectory = PACKAGE_DIR "configurations";
11constexpr const char* currentConfiguration = "/var/configuration/system.json";
Alexander Hansenddc8eb62025-04-25 18:08:51 +020012constexpr const char* schemaDirectory = PACKAGE_DIR "schemas";
Christopher Meisbdaa6b22025-04-02 10:49:02 +020013
Christopher Meisf7252572025-06-11 13:22:05 +020014class Configuration
15{
16 public:
17 explicit Configuration();
18 std::unordered_set<std::string> probeInterfaces;
19 std::vector<nlohmann::json> configurations;
Christopher Meisbdaa6b22025-04-02 10:49:02 +020020
Christopher Meisf7252572025-06-11 13:22:05 +020021 private:
22 void loadConfigurations();
23 void filterProbeInterfaces();
24};
25
26bool writeJsonFiles(const nlohmann::json& systemConfiguration);
Christopher Meisbdaa6b22025-04-02 10:49:02 +020027
28template <typename JsonType>
29bool setJsonFromPointer(const std::string& ptrStr, const JsonType& value,
30 nlohmann::json& systemConfiguration)
31{
32 try
33 {
34 nlohmann::json::json_pointer ptr(ptrStr);
35 nlohmann::json& ref = systemConfiguration[ptr];
36 ref = value;
37 return true;
38 }
39 catch (const std::out_of_range&)
40 {
41 return false;
42 }
43}
44
45void deriveNewConfiguration(const nlohmann::json& oldConfiguration,
46 nlohmann::json& newConfiguration);
47
48bool validateJson(const nlohmann::json& schemaFile,
49 const nlohmann::json& input);