summaryrefslogtreecommitdiff
path: root/redfish-core/lib
diff options
context:
space:
mode:
authorEd Tanous <edtanous@google.com>2022-07-09 21:17:36 +0300
committerEd Tanous <ed@tanous.net>2022-09-12 19:42:37 +0300
commit613dabea03cd2f5cb999be37aaf539280c63ea7a (patch)
treefbf586118f079918883c97caec8b1b8fd43967f1 /redfish-core/lib
parent188cb6294105a045a445619415d01843de8c3732 (diff)
downloadbmcweb-613dabea03cd2f5cb999be37aaf539280c63ea7a.tar.xz
Remove nlohmann brace initialization
There's a few last places (outside of tests) where we still use nlohmann brace initialization. Per the transforms we've been doing, move these to constructing the objects explicitly, using operator[], nlohmann::object_t and nlohmann::array_t. Theses were found by manual inspection grepping for all uses of nlohmann::json. This is done to reduce binary size and reduce the number of intermediate objects being constructed. This commit saves a trivial amount of size (~4KB, Half a percent of total) and in addition but makes our construction consistent. Tested: Redfish service validator passes. Signed-off-by: Ed Tanous <edtanous@google.com> Change-Id: I7478479a9fdc41b254eef325002d413c1fb411a0
Diffstat (limited to 'redfish-core/lib')
-rw-r--r--redfish-core/lib/account_service.hpp19
-rw-r--r--redfish-core/lib/certificate_service.hpp19
-rw-r--r--redfish-core/lib/ethernet.hpp7
-rw-r--r--redfish-core/lib/event_service.hpp13
-rw-r--r--redfish-core/lib/hypervisor_system.hpp11
-rw-r--r--redfish-core/lib/log_services.hpp28
-rw-r--r--redfish-core/lib/managers.hpp15
-rw-r--r--redfish-core/lib/message_registries.hpp37
-rw-r--r--redfish-core/lib/metric_report.hpp13
-rw-r--r--redfish-core/lib/metric_report_definition.hpp8
-rw-r--r--redfish-core/lib/systems.hpp6
-rw-r--r--redfish-core/lib/task.hpp7
-rw-r--r--redfish-core/lib/trigger.hpp13
-rw-r--r--redfish-core/lib/virtual_media.hpp2
14 files changed, 115 insertions, 83 deletions
diff --git a/redfish-core/lib/account_service.hpp b/redfish-core/lib/account_service.hpp
index 5d8bb15f6c..91bd024952 100644
--- a/redfish-core/lib/account_service.hpp
+++ b/redfish-core/lib/account_service.hpp
@@ -182,10 +182,18 @@ inline void parseLDAPConfigData(nlohmann::json& jsonResponse,
{
BMCWEB_LOG_DEBUG << "Pushing the data groupName="
<< obj.second.groupName << "\n";
- roleMapArray.push_back(
- {nlohmann::json::array({"RemoteGroup", obj.second.groupName}),
- nlohmann::json::array(
- {"LocalRole", getRoleIdFromPrivilege(obj.second.privilege)})});
+
+ nlohmann::json::array_t remoteGroupArray;
+ nlohmann::json::object_t remoteGroup;
+ remoteGroup["RemoteGroup"] = obj.second.groupName;
+ remoteGroupArray.emplace_back(std::move(remoteGroup));
+ roleMapArray.emplace_back(std::move(remoteGroupArray));
+
+ nlohmann::json::array_t localRoleArray;
+ nlohmann::json::object_t localRole;
+ localRole["LocalRole"] = getRoleIdFromPrivilege(obj.second.privilege);
+ localRoleArray.emplace_back(std::move(localRole));
+ roleMapArray.emplace_back(std::move(localRoleArray));
}
}
@@ -1733,7 +1741,8 @@ inline void
asyncResp->res.jsonValue["Name"] = "User Account";
asyncResp->res.jsonValue["Description"] = "User Account";
asyncResp->res.jsonValue["Password"] = nullptr;
- asyncResp->res.jsonValue["AccountTypes"] = {"Redfish"};
+ asyncResp->res.jsonValue["AccountTypes"] =
+ nlohmann::json::array_t({"Redfish"});
for (const auto& interface : userIt->second)
{
diff --git a/redfish-core/lib/certificate_service.hpp b/redfish-core/lib/certificate_service.hpp
index ebd9436f9b..d3aedd00a7 100644
--- a/redfish-core/lib/certificate_service.hpp
+++ b/redfish-core/lib/certificate_service.hpp
@@ -78,15 +78,16 @@ inline void requestRoutesCertificateService(App& app)
asyncResp->res.jsonValue["CertificateLocations"]["@odata.id"] =
"/redfish/v1/CertificateService/CertificateLocations";
}
- asyncResp->res
- .jsonValue["Actions"]["#CertificateService.ReplaceCertificate"] = {
- {"target",
- "/redfish/v1/CertificateService/Actions/CertificateService.ReplaceCertificate"},
- {"CertificateType@Redfish.AllowableValues", {"PEM"}}};
- asyncResp->res
- .jsonValue["Actions"]["#CertificateService.GenerateCSR"] = {
- {"target",
- "/redfish/v1/CertificateService/Actions/CertificateService.GenerateCSR"}};
+ nlohmann::json& actions = asyncResp->res.jsonValue["Actions"];
+ nlohmann::json& replace =
+ actions["#CertificateService.ReplaceCertificate"];
+ replace["target"] =
+ "/redfish/v1/CertificateService/Actions/CertificateService.ReplaceCertificate";
+ nlohmann::json::array_t allowed;
+ allowed.push_back("PEM");
+ replace["CertificateType@Redfish.AllowableValues"] = std::move(allowed);
+ actions["#CertificateService.GenerateCSR"]["target"] =
+ "/redfish/v1/CertificateService/Actions/CertificateService.GenerateCSR";
});
} // requestRoutesCertificateService
diff --git a/redfish-core/lib/ethernet.hpp b/redfish-core/lib/ethernet.hpp
index 9fb125d280..3530d79667 100644
--- a/redfish-core/lib/ethernet.hpp
+++ b/redfish-core/lib/ethernet.hpp
@@ -1660,9 +1660,9 @@ inline void parseInterfaceData(
jsonResponse["FQDN"] = fqdn;
}
- jsonResponse["VLANs"] = {
- {"@odata.id",
- "/redfish/v1/Managers/bmc/EthernetInterfaces/" + ifaceId + "/VLANs"}};
+ jsonResponse["VLANs"]["@odata.id"] =
+ crow::utility::urlFromPieces("redfish", "v1", "Managers", "bmc",
+ "EthernetInterfaces", ifaceId, "VLANs");
jsonResponse["NameServers"] = ethData.nameServers;
jsonResponse["StaticNameServers"] = ethData.staticNameServers;
@@ -1673,7 +1673,6 @@ inline void parseInterfaceData(
ipv4StaticArray = nlohmann::json::array();
for (const auto& ipv4Config : ipv4Data)
{
-
std::string gatewayStr = ipv4Config.gateway;
if (gatewayStr.empty())
{
diff --git a/redfish-core/lib/event_service.hpp b/redfish-core/lib/event_service.hpp
index 9c5b378dd9..d473c8e047 100644
--- a/redfish-core/lib/event_service.hpp
+++ b/redfish-core/lib/event_service.hpp
@@ -83,13 +83,16 @@ inline void requestRoutesEventService(App& app)
asyncResp->res.jsonValue["RegistryPrefixes"] = supportedRegPrefixes;
asyncResp->res.jsonValue["ResourceTypes"] = supportedResourceTypes;
- nlohmann::json supportedSSEFilters = {
- {"EventFormatType", true}, {"MessageId", true},
- {"MetricReportDefinition", true}, {"RegistryPrefix", true},
- {"OriginResource", false}, {"ResourceType", false}};
+ nlohmann::json::object_t supportedSSEFilters;
+ supportedSSEFilters["EventFormatType"] = true;
+ supportedSSEFilters["MessageId"] = true;
+ supportedSSEFilters["MetricReportDefinition"] = true;
+ supportedSSEFilters["RegistryPrefix"] = true;
+ supportedSSEFilters["OriginResource"] = false;
+ supportedSSEFilters["ResourceType"] = false;
asyncResp->res.jsonValue["SSEFilterPropertiesSupported"] =
- supportedSSEFilters;
+ std::move(supportedSSEFilters);
});
BMCWEB_ROUTE(app, "/redfish/v1/EventService/")
diff --git a/redfish-core/lib/hypervisor_system.hpp b/redfish-core/lib/hypervisor_system.hpp
index b75dec1390..78bf6269a5 100644
--- a/redfish-core/lib/hypervisor_system.hpp
+++ b/redfish-core/lib/hypervisor_system.hpp
@@ -137,11 +137,12 @@ inline void
}
// Object present so system support limited ComputerSystem Action
- aResp->res.jsonValue["Actions"]["#ComputerSystem.Reset"] = {
- {"target",
- "/redfish/v1/Systems/hypervisor/Actions/ComputerSystem.Reset"},
- {"@Redfish.ActionInfo",
- "/redfish/v1/Systems/hypervisor/ResetActionInfo"}};
+ nlohmann::json& reset =
+ aResp->res.jsonValue["Actions"]["#ComputerSystem.Reset"];
+ reset["target"] =
+ "/redfish/v1/Systems/hypervisor/Actions/ComputerSystem.Reset";
+ reset["@Redfish.ActionInfo"] =
+ "/redfish/v1/Systems/hypervisor/ResetActionInfo";
},
"xyz.openbmc_project.ObjectMapper",
"/xyz/openbmc_project/object_mapper",
diff --git a/redfish-core/lib/log_services.hpp b/redfish-core/lib/log_services.hpp
index faa295adc1..1b52d00f9a 100644
--- a/redfish-core/lib/log_services.hpp
+++ b/redfish-core/lib/log_services.hpp
@@ -972,9 +972,12 @@ inline void requestRoutesSystemLogServiceCollection(App& app)
{
nlohmann::json& logServiceArrayLocal =
asyncResp->res.jsonValue["Members"];
- logServiceArrayLocal.push_back(
- {{"@odata.id",
- "/redfish/v1/Systems/system/LogServices/PostCodes"}});
+ nlohmann::json::object_t member;
+ member["@odata.id"] =
+ "/redfish/v1/Systems/system/LogServices/PostCodes";
+
+ logServiceArrayLocal.push_back(std::move(member));
+
asyncResp->res.jsonValue["Members@odata.count"] =
logServiceArrayLocal.size();
return;
@@ -2013,8 +2016,9 @@ inline void handleBMCLogServicesCollectionGet(
logServiceArray = nlohmann::json::array();
#ifdef BMCWEB_ENABLE_REDFISH_BMC_JOURNAL
- logServiceArray.push_back(
- {{"@odata.id", "/redfish/v1/Managers/bmc/LogServices/Journal"}});
+ nlohmann::json::object_t journal;
+ journal["@odata.id"] = "/redfish/v1/Managers/bmc/LogServices/Journal";
+ logServiceArray.push_back(std::move(journal));
#endif
asyncResp->res.jsonValue["Members@odata.count"] = logServiceArray.size();
@@ -2041,15 +2045,17 @@ inline void handleBMCLogServicesCollectionGet(
{
if (path == "/xyz/openbmc_project/dump/bmc")
{
- logServiceArrayLocal.push_back(
- {{"@odata.id",
- "/redfish/v1/Managers/bmc/LogServices/Dump"}});
+ nlohmann::json::object_t member;
+ member["@odata.id"] =
+ "/redfish/v1/Managers/bmc/LogServices/Dump";
+ logServiceArrayLocal.push_back(std::move(member));
}
else if (path == "/xyz/openbmc_project/dump/faultlog")
{
- logServiceArrayLocal.push_back(
- {{"@odata.id",
- "/redfish/v1/Managers/bmc/LogServices/FaultLog"}});
+ nlohmann::json::object_t member;
+ member["@odata.id"] =
+ "/redfish/v1/Managers/bmc/LogServices/FaultLog";
+ logServiceArrayLocal.push_back(std::move(member));
}
}
diff --git a/redfish-core/lib/managers.hpp b/redfish-core/lib/managers.hpp
index a52b7b5281..1955de113a 100644
--- a/redfish-core/lib/managers.hpp
+++ b/redfish-core/lib/managers.hpp
@@ -400,8 +400,8 @@ inline void
chassis = "#IllegalValue";
}
nlohmann::json& zone = zones[name];
- zone["Chassis"] = {
- {"@odata.id", "/redfish/v1/Chassis/" + chassis}};
+ zone["Chassis"]["@odata.id"] =
+ "/redfish/v1/Chassis/" + chassis;
zone["@odata.id"] =
"/redfish/v1/Managers/bmc#/Oem/OpenBmc/Fan/FanZones/" +
name;
@@ -2000,7 +2000,8 @@ inline void requestRoutesManager(App& app)
asyncResp->res.jsonValue["Actions"]["#Manager.ResetToDefaults"];
resetToDefaults["target"] =
"/redfish/v1/Managers/bmc/Actions/Manager.ResetToDefaults";
- resetToDefaults["ResetType@Redfish.AllowableValues"] = {"ResetAll"};
+ resetToDefaults["ResetType@Redfish.AllowableValues"] =
+ nlohmann::json::array_t({"ResetAll"});
std::pair<std::string, std::string> redfishDateTimeOffset =
redfish::time_utils::getDateTimeOffsetNow();
@@ -2015,15 +2016,15 @@ inline void requestRoutesManager(App& app)
// Fill in SerialConsole info
asyncResp->res.jsonValue["SerialConsole"]["ServiceEnabled"] = true;
asyncResp->res.jsonValue["SerialConsole"]["MaxConcurrentSessions"] = 15;
- asyncResp->res.jsonValue["SerialConsole"]["ConnectTypesSupported"] = {
- "IPMI", "SSH"};
+ asyncResp->res.jsonValue["SerialConsole"]["ConnectTypesSupported"] =
+ nlohmann::json::array_t({"IPMI", "SSH"});
#ifdef BMCWEB_ENABLE_KVM
// Fill in GraphicalConsole info
asyncResp->res.jsonValue["GraphicalConsole"]["ServiceEnabled"] = true;
asyncResp->res.jsonValue["GraphicalConsole"]["MaxConcurrentSessions"] =
4;
- asyncResp->res
- .jsonValue["GraphicalConsole"]["ConnectTypesSupported"] = {"KVMIP"};
+ asyncResp->res.jsonValue["GraphicalConsole"]["ConnectTypesSupported"] =
+ nlohmann::json::array_t({"KVMIP"});
#endif // BMCWEB_ENABLE_KVM
asyncResp->res.jsonValue["Links"]["ManagerForServers@odata.count"] = 1;
diff --git a/redfish-core/lib/message_registries.hpp b/redfish-core/lib/message_registries.hpp
index 09d32b7d26..9d6f109360 100644
--- a/redfish-core/lib/message_registries.hpp
+++ b/redfish-core/lib/message_registries.hpp
@@ -25,6 +25,8 @@
#include <query.hpp>
#include <registries/privilege_registry.hpp>
+#include <array>
+
namespace redfish
{
@@ -46,11 +48,16 @@ inline void handleMessageRegistryFileCollectionGet(
asyncResp->res.jsonValue["Description"] =
"Collection of MessageRegistryFiles";
asyncResp->res.jsonValue["Members@odata.count"] = 4;
- asyncResp->res.jsonValue["Members"] = {
- {{"@odata.id", "/redfish/v1/Registries/Base"}},
- {{"@odata.id", "/redfish/v1/Registries/TaskEvent"}},
- {{"@odata.id", "/redfish/v1/Registries/ResourceEvent"}},
- {{"@odata.id", "/redfish/v1/Registries/OpenBMC"}}};
+
+ nlohmann::json& members = asyncResp->res.jsonValue["Members"];
+ for (const char* memberName :
+ std::to_array({"Base", "TaskEvent", "ResourceEvent", "OpenBMC"}))
+ {
+ nlohmann::json::object_t member;
+ member["@odata.id"] = crow::utility::urlFromPieces(
+ "redfish", "v1", "Registries", memberName);
+ members.emplace_back(std::move(member));
+ }
}
inline void requestRoutesMessageRegistryFileCollection(App& app)
@@ -113,18 +120,22 @@ inline void handleMessageRoutesMessageRegistryFileGet(
dmtf + registry + " Message Registry File Location";
asyncResp->res.jsonValue["Id"] = header->registryPrefix;
asyncResp->res.jsonValue["Registry"] = header->id;
- asyncResp->res.jsonValue["Languages"] = {"en"};
- asyncResp->res.jsonValue["Languages@odata.count"] = 1;
- asyncResp->res.jsonValue["Location"] = {
- {{"Language", "en"},
- {"Uri", "/redfish/v1/Registries/" + registry + "/" + registry}}};
-
- asyncResp->res.jsonValue["Location@odata.count"] = 1;
+ nlohmann::json::array_t languages;
+ languages.push_back("en");
+ asyncResp->res.jsonValue["Languages@odata.count"] = languages.size();
+ asyncResp->res.jsonValue["Languages"] = std::move(languages);
+ nlohmann::json::array_t locationMembers;
+ nlohmann::json::object_t location;
+ location["Language"] = "en";
+ location["Uri"] = "/redfish/v1/Registries/" + registry + "/" + registry;
if (url != nullptr)
{
- asyncResp->res.jsonValue["Location"][0]["PublicationUri"] = url;
+ location["PublicationUri"] = url;
}
+ locationMembers.emplace_back(std::move(location));
+ asyncResp->res.jsonValue["Location@odata.count"] = locationMembers.size();
+ asyncResp->res.jsonValue["Location"] = std::move(locationMembers);
}
inline void requestRoutesMessageRegistryFile(App& app)
diff --git a/redfish-core/lib/metric_report.hpp b/redfish-core/lib/metric_report.hpp
index 18830f139b..6b79c5124a 100644
--- a/redfish-core/lib/metric_report.hpp
+++ b/redfish-core/lib/metric_report.hpp
@@ -29,12 +29,13 @@ inline nlohmann::json toMetricValues(const Readings& readings)
for (const auto& [id, metadata, sensorValue, timestamp] : readings)
{
- metricValues.push_back({
- {"MetricId", id},
- {"MetricProperty", metadata},
- {"MetricValue", std::to_string(sensorValue)},
- {"Timestamp", redfish::time_utils::getDateTimeUintMs(timestamp)},
- });
+ nlohmann::json::object_t metricReport;
+ metricReport["MetricId"] = id;
+ metricReport["MetricProperty"] = metadata;
+ metricReport["MetricValue"] = std::to_string(sensorValue);
+ metricReport["Timestamp"] =
+ redfish::time_utils::getDateTimeUintMs(timestamp);
+ metricValues.push_back(std::move(metricReport));
}
return metricValues;
diff --git a/redfish-core/lib/metric_report_definition.hpp b/redfish-core/lib/metric_report_definition.hpp
index 37e903173c..e15e920b64 100644
--- a/redfish-core/lib/metric_report_definition.hpp
+++ b/redfish-core/lib/metric_report_definition.hpp
@@ -87,10 +87,10 @@ inline void
for (const auto& [sensorPath, operationType, metricId, metadata] :
*readingParameters)
{
- metrics.push_back({
- {"MetricId", metricId},
- {"MetricProperties", {metadata}},
- });
+ nlohmann::json::object_t metric;
+ metric["MetricId"] = metricId;
+ metric["MetricProperties"] = nlohmann::json::array_t({metadata});
+ metrics.push_back(std::move(metric));
}
}
diff --git a/redfish-core/lib/systems.hpp b/redfish-core/lib/systems.hpp
index 24e6d4101e..975e90bc3c 100644
--- a/redfish-core/lib/systems.hpp
+++ b/redfish-core/lib/systems.hpp
@@ -881,7 +881,7 @@ inline void getBootOverrideType(const std::shared_ptr<bmcweb::AsyncResp>& aResp)
aResp->res.jsonValue["Boot"]
["BootSourceOverrideMode@Redfish.AllowableValues"] =
- {"Legacy", "UEFI"};
+ nlohmann::json::array_t({"Legacy", "UEFI"});
auto rfType = dbusToRfBootType(bootType);
if (rfType.empty())
@@ -2939,8 +2939,8 @@ inline void requestRoutesSystems(App& app)
asyncResp->res.jsonValue["GraphicalConsole"]["ServiceEnabled"] = true;
asyncResp->res.jsonValue["GraphicalConsole"]["MaxConcurrentSessions"] =
4;
- asyncResp->res
- .jsonValue["GraphicalConsole"]["ConnectTypesSupported"] = {"KVMIP"};
+ asyncResp->res.jsonValue["GraphicalConsole"]["ConnectTypesSupported"] =
+ nlohmann::json::array_t({"KVMIP"});
#endif // BMCWEB_ENABLE_KVM
constexpr const std::array<const char*, 4> inventoryForSystems = {
diff --git a/redfish-core/lib/task.hpp b/redfish-core/lib/task.hpp
index b40d522d46..fe3b9908bb 100644
--- a/redfish-core/lib/task.hpp
+++ b/redfish-core/lib/task.hpp
@@ -448,9 +448,10 @@ inline void requestRoutesTaskCollection(App& app)
{
continue; // shouldn't be possible
}
- members.emplace_back(
- nlohmann::json{{"@odata.id", "/redfish/v1/TaskService/Tasks/" +
- std::to_string(task->index)}});
+ nlohmann::json::object_t member;
+ member["@odata.id"] =
+ "redfish/v1/TaskService/Tasks/" + std::to_string(task->index);
+ members.emplace_back(std::move(member));
}
});
}
diff --git a/redfish-core/lib/trigger.hpp b/redfish-core/lib/trigger.hpp
index 5e2f05003a..811d355124 100644
--- a/redfish-core/lib/trigger.hpp
+++ b/redfish-core/lib/trigger.hpp
@@ -100,13 +100,12 @@ inline std::optional<nlohmann::json::array_t>
{
return std::nullopt;
}
-
- triggers.push_back({
- {"Name", name},
- {"Severity", severity},
- {"DwellTime", *duration},
- {"Value", value},
- });
+ nlohmann::json::object_t trigger;
+ trigger["Name"] = name;
+ trigger["Severity"] = severity;
+ trigger["DwellTime"] = *duration;
+ trigger["Value"] = value;
+ triggers.push_back(std::move(trigger));
}
return {std::move(triggers)};
diff --git a/redfish-core/lib/virtual_media.hpp b/redfish-core/lib/virtual_media.hpp
index 15dcdb9169..af38163fb8 100644
--- a/redfish-core/lib/virtual_media.hpp
+++ b/redfish-core/lib/virtual_media.hpp
@@ -155,7 +155,7 @@ inline nlohmann::json vmItemTemplate(const std::string& name,
item["Name"] = "Virtual Removable Media";
item["Id"] = resName;
item["WriteProtected"] = true;
- item["MediaTypes"] = {"CD", "USBStick"};
+ item["MediaTypes"] = nlohmann::json::array_t({"CD", "USBStick"});
item["TransferMethod"] = "Stream";
item["Oem"]["OpenBMC"]["@odata.type"] =
"#OemVirtualMedia.v1_0_0.VirtualMedia";