summaryrefslogtreecommitdiff
path: root/redfish-core
diff options
context:
space:
mode:
authorEd Tanous <edtanous@google.com>2022-05-05 21:48:31 +0300
committerEd Tanous <ed@tanous.net>2024-03-21 02:28:50 +0300
commit7cb59f655a3e68b23ec720d286c71805c5c9a895 (patch)
treea5231d97d6c6ad290c686736fc112f7558e3f1a6 /redfish-core
parent4d1db045ef30d0b717220d2ef61530c2b1fb0bb1 (diff)
downloadbmcweb-7cb59f655a3e68b23ec720d286c71805c5c9a895.tar.xz
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
Diffstat (limited to 'redfish-core')
-rw-r--r--redfish-core/lib/update_service.hpp56
1 files changed, 24 insertions, 32 deletions
diff --git a/redfish-core/lib/update_service.hpp b/redfish-core/lib/update_service.hpp
index 74e110170a..62591149a3 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 @@ inline void
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 @@ inline void requestRoutesUpdateService(App& app)
}
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);
}
});