Use readJson to simplify update
Similar to other places where we've ported the depth-based readJson
support forward, this commit ports the UpdateService handler to simplify
the code.
Signed-off-by: Ed Tanous <edtanous@google.com>
Change-Id: Ia9841a10b4414f81205d3f9b49ec8aab8f9d491d
diff --git a/redfish-core/lib/update_service.hpp b/redfish-core/lib/update_service.hpp
index 74e1101..6259114 100644
--- a/redfish-core/lib/update_service.hpp
+++ b/redfish-core/lib/update_service.hpp
@@ -36,6 +36,8 @@
#include <array>
#include <filesystem>
+#include <optional>
+#include <string>
#include <string_view>
namespace redfish
@@ -672,22 +674,31 @@
std::vector<std::string> targets;
nlohmann::json content =
nlohmann::json::parse(formpart.content);
- if (!json_util::readJson(content, asyncResp->res, "Targets",
- targets, "@Redfish.OperationApplyTime",
- applyTime))
+ nlohmann::json::object_t* obj =
+ content.get_ptr<nlohmann::json::object_t*>();
+ if (obj == nullptr)
+ {
+ messages::propertyValueFormatError(asyncResp->res, targets,
+ "UpdateParameters");
+ return;
+ }
+
+ if (!json_util::readJsonObject(
+ *obj, asyncResp->res, "Targets", targets,
+ "@Redfish.OperationApplyTime", applyTime))
{
return;
}
if (targets.size() != 1)
{
- messages::propertyValueFormatError(asyncResp->res,
- "Targets", "");
+ messages::propertyValueFormatError(asyncResp->res, targets,
+ "Targets");
return;
}
if (targets[0] != "/redfish/v1/Managers/bmc")
{
- messages::propertyValueNotInList(asyncResp->res,
- "Targets/0", targets[0]);
+ messages::propertyValueNotInList(asyncResp->res, targets[0],
+ "Targets/0");
return;
}
targetFound = true;
@@ -846,36 +857,17 @@
}
BMCWEB_LOG_DEBUG("doPatch...");
- std::optional<nlohmann::json> pushUriOptions;
- if (!json_util::readJsonPatch(req, asyncResp->res, "HttpPushUriOptions",
- pushUriOptions))
+ std::optional<std::string> applyTime;
+ if (!json_util::readJsonPatch(
+ req, asyncResp->res,
+ "HttpPushUriOptions/HttpPushUriApplyTime/ApplyTime", applyTime))
{
return;
}
- if (pushUriOptions)
+ if (applyTime)
{
- std::optional<nlohmann::json> pushUriApplyTime;
- if (!json_util::readJson(*pushUriOptions, asyncResp->res,
- "HttpPushUriApplyTime", pushUriApplyTime))
- {
- return;
- }
-
- if (pushUriApplyTime)
- {
- std::optional<std::string> applyTime;
- if (!json_util::readJson(*pushUriApplyTime, asyncResp->res,
- "ApplyTime", applyTime))
- {
- return;
- }
-
- if (applyTime)
- {
- setApplyTime(asyncResp, *applyTime);
- }
- }
+ setApplyTime(asyncResp, *applyTime);
}
});