summaryrefslogtreecommitdiff
path: root/include/persistent_data.hpp
diff options
context:
space:
mode:
authorEd Tanous <edtanous@google.com>2022-03-15 20:44:42 +0300
committerEd Tanous <edtanous@google.com>2022-05-13 01:08:18 +0300
commit1476687deb1697d865b20458a0097c9ab5fd44e2 (patch)
tree6964ba82c382d03522f7a413a61ae1164b8e242e /include/persistent_data.hpp
parent1656b296313d75b172dcdbe5f37ff1d1b54800dc (diff)
downloadbmcweb-1476687deb1697d865b20458a0097c9ab5fd44e2.tar.xz
Remove brace initialization of json objects
Brace initialization of json objects, while quite interesting from an academic sense, are very difficult for people to grok, and lead to inconsistencies. This patchset aims to remove a majority of them in lieu of operator[]. Interestingly, this saves about 1% of the binary size of bmcweb. This also has an added benefit that as a design pattern, we're never constructing a new object, then moving it into place, we're always adding to the existing object, which in the future _could_ make things like OEM schemas or properties easier, as there's no case where we're completely replacing the response object. Tested: Ran redfish service validator. No new failures. Signed-off-by: Ed Tanous <edtanous@google.com> Change-Id: Iae409b0a40ddd3ae6112cb2d52c6f6ab388595fe
Diffstat (limited to 'include/persistent_data.hpp')
-rw-r--r--include/persistent_data.hpp81
1 files changed, 42 insertions, 39 deletions
diff --git a/include/persistent_data.hpp b/include/persistent_data.hpp
index 6d0f7c1a1d..1ca925eb23 100644
--- a/include/persistent_data.hpp
+++ b/include/persistent_data.hpp
@@ -207,25 +207,25 @@ class ConfigFile
const auto& c = SessionStore::getInstance().getAuthMethodsConfig();
const auto& eventServiceConfig =
EventServiceStore::getInstance().getEventServiceConfig();
- nlohmann::json data{
- {"auth_config",
- {{"XToken", c.xtoken},
- {"Cookie", c.cookie},
- {"SessionToken", c.sessionToken},
- {"BasicAuth", c.basic},
- {"TLS", c.tls}}
+ nlohmann::json::object_t data;
+ nlohmann::json& authConfig = data["auth_config"];
- },
- {"eventservice_config",
- {{"ServiceEnabled", eventServiceConfig.enabled},
- {"DeliveryRetryAttempts", eventServiceConfig.retryAttempts},
- {"DeliveryRetryIntervalSeconds",
- eventServiceConfig.retryTimeoutInterval}}
+ authConfig["XToken"] = c.xtoken;
+ authConfig["Cookie"] = c.cookie;
+ authConfig["SessionToken"] = c.sessionToken;
+ authConfig["BasicAuth"] = c.basic;
+ authConfig["TLS"] = c.tls;
- },
- {"system_uuid", systemUuid},
- {"revision", jsonRevision},
- {"timeout", SessionStore::getInstance().getTimeoutInSeconds()}};
+ nlohmann::json& eventserviceConfig = data["eventservice_config"];
+ eventserviceConfig["ServiceEnabled"] = eventServiceConfig.enabled;
+ eventserviceConfig["DeliveryRetryAttempts"] =
+ eventServiceConfig.retryAttempts;
+ eventserviceConfig["DeliveryRetryIntervalSeconds"] =
+ eventServiceConfig.retryTimeoutInterval;
+
+ data["system_uuid"] = systemUuid;
+ data["revision"] = jsonRevision;
+ data["timeout"] = SessionStore::getInstance().getTimeoutInSeconds();
nlohmann::json& sessions = data["sessions"];
sessions = nlohmann::json::array();
@@ -234,16 +234,16 @@ class ConfigFile
if (p.second->persistence !=
persistent_data::PersistenceType::SINGLE_REQUEST)
{
- sessions.push_back({
- {"unique_id", p.second->uniqueId},
- {"session_token", p.second->sessionToken},
- {"username", p.second->username},
- {"csrf_token", p.second->csrfToken},
- {"client_ip", p.second->clientIp},
+ nlohmann::json::object_t session;
+ session["unique_id"] = p.second->uniqueId;
+ session["session_token"] = p.second->sessionToken;
+ session["username"] = p.second->username;
+ session["csrf_token"] = p.second->csrfToken;
+ session["client_ip"] = p.second->clientIp;
#ifdef BMCWEB_ENABLE_IBM_MANAGEMENT_CONSOLE
- {"client_id", p.second->clientId},
+ session["client_id"] = p.second->clientId;
#endif
- });
+ sessions.push_back(std::move(session));
}
}
nlohmann::json& subscriptions = data["subscriptions"];
@@ -270,20 +270,23 @@ class ConfigFile
headers[std::move(name)] = header.value();
}
- subscriptions.push_back({
- {"Id", subValue->id},
- {"Context", subValue->customText},
- {"DeliveryRetryPolicy", subValue->retryPolicy},
- {"Destination", subValue->destinationUrl},
- {"EventFormatType", subValue->eventFormatType},
- {"HttpHeaders", std::move(headers)},
- {"MessageIds", subValue->registryMsgIds},
- {"Protocol", subValue->protocol},
- {"RegistryPrefixes", subValue->registryPrefixes},
- {"ResourceTypes", subValue->resourceTypes},
- {"SubscriptionType", subValue->subscriptionType},
- {"MetricReportDefinitions", subValue->metricReportDefinitions},
- });
+ nlohmann::json::object_t subscription;
+
+ subscription["Id"] = subValue->id;
+ subscription["Context"] = subValue->customText;
+ subscription["DeliveryRetryPolicy"] = subValue->retryPolicy;
+ subscription["Destination"] = subValue->destinationUrl;
+ subscription["EventFormatType"] = subValue->eventFormatType;
+ subscription["HttpHeaders"] = std::move(headers);
+ subscription["MessageIds"] = subValue->registryMsgIds;
+ subscription["Protocol"] = subValue->protocol;
+ subscription["RegistryPrefixes"] = subValue->registryPrefixes;
+ subscription["ResourceTypes"] = subValue->resourceTypes;
+ subscription["SubscriptionType"] = subValue->subscriptionType;
+ subscription["MetricReportDefinitions"] =
+ subValue->metricReportDefinitions;
+
+ subscriptions.push_back(std::move(subscription));
}
persistentFile << data;
}