summaryrefslogtreecommitdiff
path: root/redfish-core
diff options
context:
space:
mode:
authorJiaqing Zhao <jiaqing.zhao@intel.com>2022-03-29 18:11:31 +0300
committerJiaqing Zhao <jiaqing.zhao@intel.com>2022-04-06 11:59:56 +0300
commit5f4c798d0a1e0827363e167e54f4fb1dbffe9efa (patch)
treea03fd7c3eda405a122e744599d5bb03504be3af6 /redfish-core
parent45ca1b868e47978a4d2e8ebb680cb384e804c97e (diff)
downloadbmcweb-5f4c798d0a1e0827363e167e54f4fb1dbffe9efa.tar.xz
Use multi-depth readJson to handle PATCH NetworkProtocol
The new multi-depth readJson simplifies the PATCH handler and removes 3 extra readJson calls. Tested: Verified PATCH /redfish/v1/Managers/bmc/NetworkProtocol works exactly the same as before, all modifiable properties are handled properly. Change-Id: I836010273b5150576d6bc33eae82acda2de70e67 Signed-off-by: Jiaqing Zhao <jiaqing.zhao@intel.com>
Diffstat (limited to 'redfish-core')
-rw-r--r--redfish-core/lib/network_protocol.hpp86
1 files changed, 30 insertions, 56 deletions
diff --git a/redfish-core/lib/network_protocol.hpp b/redfish-core/lib/network_protocol.hpp
index 7e50b46776..362163aaa6 100644
--- a/redfish-core/lib/network_protocol.hpp
+++ b/redfish-core/lib/network_protocol.hpp
@@ -29,6 +29,7 @@
#include <optional>
#include <variant>
+
namespace redfish
{
@@ -410,16 +411,23 @@ inline void requestRoutesNetworkProtocol(App& app)
return;
}
std::optional<std::string> newHostName;
- std::optional<nlohmann::json> ntp;
- std::optional<nlohmann::json> ipmi;
- std::optional<nlohmann::json> ssh;
-
- if (!json_util::readJsonPatch(req, asyncResp->res, "NTP", ntp,
- "HostName", newHostName, "IPMI", ipmi,
- "SSH", ssh))
+ std::optional<std::vector<std::string>> ntpServers;
+ std::optional<bool> ntpEnabled;
+ std::optional<bool> ipmiEnabled;
+ std::optional<bool> sshEnabled;
+
+ // clang-format off
+ if (!json_util::readJsonPatch(
+ req, asyncResp->res,
+ "HostName", newHostName,
+ "NTP/NTPServers", ntpServers,
+ "NTP/ProtocolEnabled", ntpEnabled,
+ "IPMI/ProtocolEnabled", ipmiEnabled,
+ "SSH/ProtocolEnabled", sshEnabled))
{
return;
}
+ // clang-format on
asyncResp->res.result(boost::beast::http::status::no_content);
if (newHostName)
@@ -428,62 +436,28 @@ inline void requestRoutesNetworkProtocol(App& app)
return;
}
- if (ntp)
+ if (ntpEnabled)
{
- std::optional<std::vector<std::string>> ntpServers;
- std::optional<bool> ntpEnabled;
- if (!json_util::readJson(*ntp, asyncResp->res, "NTPServers",
- ntpServers, "ProtocolEnabled",
- ntpEnabled))
- {
- return;
- }
-
- if (ntpEnabled)
- {
- handleNTPProtocolEnabled(*ntpEnabled, asyncResp);
- }
-
- if (ntpServers)
- {
- stl_utils::removeDuplicate(*ntpServers);
- handleNTPServersPatch(asyncResp, *ntpServers);
- }
+ handleNTPProtocolEnabled(*ntpEnabled, asyncResp);
}
-
- if (ipmi)
+ if (ntpServers)
{
- std::optional<bool> ipmiProtocolEnabled;
- if (!json_util::readJson(*ipmi, asyncResp->res,
- "ProtocolEnabled",
- ipmiProtocolEnabled))
- {
- return;
- }
-
- if (ipmiProtocolEnabled)
- {
- handleProtocolEnabled(
- *ipmiProtocolEnabled, asyncResp,
- "/xyz/openbmc_project/control/service/phosphor_2dipmi_2dnet_40");
- }
+ stl_utils::removeDuplicate(*ntpServers);
+ handleNTPServersPatch(asyncResp, *ntpServers);
}
- if (ssh)
+ if (ipmiEnabled)
{
- std::optional<bool> sshProtocolEnabled;
- if (!json_util::readJson(*ssh, asyncResp->res,
- "ProtocolEnabled", sshProtocolEnabled))
- {
- return;
- }
+ handleProtocolEnabled(
+ *ipmiEnabled, asyncResp,
+ "/xyz/openbmc_project/control/service/phosphor_2dipmi_2dnet_40");
+ }
- if (sshProtocolEnabled)
- {
- handleProtocolEnabled(
- *sshProtocolEnabled, asyncResp,
- "/xyz/openbmc_project/control/service/dropbear");
- }
+ if (sshEnabled)
+ {
+ handleProtocolEnabled(
+ *sshEnabled, asyncResp,
+ "/xyz/openbmc_project/control/service/dropbear");
}
});