xref: /openbmc/entity-manager/src/entity_manager/configuration.hpp (revision fc9e7fda2bd21c5cc9afca2cef8af0f19b28dc08)
1 #pragma once
2 
3 #include <nlohmann/json.hpp>
4 
5 #include <list>
6 #include <set>
7 
8 namespace configuration
9 {
10 constexpr const char* globalSchema = "global.json";
11 constexpr const char* hostConfigurationDirectory = SYSCONF_DIR "configurations";
12 constexpr const char* configurationDirectory = PACKAGE_DIR "configurations";
13 constexpr const char* currentConfiguration = "/var/configuration/system.json";
14 constexpr const char* schemaDirectory = PACKAGE_DIR "configurations/schemas";
15 
16 bool writeJsonFiles(const nlohmann::json& systemConfiguration);
17 
18 bool loadConfigurations(std::list<nlohmann::json>& configurations);
19 
20 template <typename JsonType>
setJsonFromPointer(const std::string & ptrStr,const JsonType & value,nlohmann::json & systemConfiguration)21 bool 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 
37 void deriveNewConfiguration(const nlohmann::json& oldConfiguration,
38                             nlohmann::json& newConfiguration);
39 
40 bool validateJson(const nlohmann::json& schemaFile,
41                   const nlohmann::json& input);
42 
43 std::set<std::string> getProbeInterfaces();
44 
45 } // namespace configuration
46