summaryrefslogtreecommitdiff
path: root/redfish-core/lib/network_protocol.hpp
diff options
context:
space:
mode:
Diffstat (limited to 'redfish-core/lib/network_protocol.hpp')
-rw-r--r--redfish-core/lib/network_protocol.hpp37
1 files changed, 21 insertions, 16 deletions
diff --git a/redfish-core/lib/network_protocol.hpp b/redfish-core/lib/network_protocol.hpp
index 00b5d9e309..747abbf97d 100644
--- a/redfish-core/lib/network_protocol.hpp
+++ b/redfish-core/lib/network_protocol.hpp
@@ -259,17 +259,24 @@ inline void handleNTPProtocolEnabled(
"TimeSyncMethod", "NTP/ProtocolEnabled", timeSyncMethod);
}
+// Redfish states that ip addresses can be
+// string, to set a value
+// null, to delete the value
+// object_t, empty json object, to ignore the value
+using IpAddress =
+ std::variant<std::string, nlohmann::json::object_t, std::nullptr_t>;
+
inline void
handleNTPServersPatch(const std::shared_ptr<bmcweb::AsyncResp>& asyncResp,
- const std::vector<nlohmann::json>& ntpServerObjects,
+ const std::vector<IpAddress>& ntpServerObjects,
std::vector<std::string> currentNtpServers)
{
std::vector<std::string>::iterator currentNtpServer =
currentNtpServers.begin();
for (size_t index = 0; index < ntpServerObjects.size(); index++)
{
- const nlohmann::json& ntpServer = ntpServerObjects[index];
- if (ntpServer.is_null())
+ const IpAddress& ntpServer = ntpServerObjects[index];
+ if (std::holds_alternative<std::nullptr_t>(ntpServer))
{
// Can't delete an item that doesn't exist
if (currentNtpServer == currentNtpServers.end())
@@ -284,22 +291,22 @@ inline void
continue;
}
const nlohmann::json::object_t* ntpServerObject =
- ntpServer.get_ptr<const nlohmann::json::object_t*>();
+ std::get_if<nlohmann::json::object_t>(&ntpServer);
if (ntpServerObject != nullptr)
{
if (!ntpServerObject->empty())
{
- messages::propertyValueNotInList(asyncResp->res, ntpServer,
- "NTP/NTPServers/" +
- std::to_string(index));
+ messages::propertyValueNotInList(
+ asyncResp->res, *ntpServerObject,
+ "NTP/NTPServers/" + std::to_string(index));
return;
}
// Can't retain an item that doesn't exist
if (currentNtpServer == currentNtpServers.end())
{
- messages::propertyValueOutOfRange(asyncResp->res, ntpServer,
- "NTP/NTPServers/" +
- std::to_string(index));
+ messages::propertyValueOutOfRange(
+ asyncResp->res, *ntpServerObject,
+ "NTP/NTPServers/" + std::to_string(index));
return;
}
@@ -308,13 +315,10 @@ inline void
continue;
}
- const std::string* ntpServerStr =
- ntpServer.get_ptr<const std::string*>();
+ const std::string* ntpServerStr = std::get_if<std::string>(&ntpServer);
if (ntpServerStr == nullptr)
{
- messages::propertyValueTypeError(asyncResp->res, ntpServer,
- "NTP/NTPServers/" +
- std::to_string(index));
+ messages::internalError(asyncResp->res);
return;
}
if (currentNtpServer == currentNtpServers.end())
@@ -470,7 +474,8 @@ inline void handleManagersNetworkProtocolPatch(
return;
}
std::optional<std::string> newHostName;
- std::optional<std::vector<nlohmann::json>> ntpServerObjects;
+
+ std::optional<std::vector<IpAddress>> ntpServerObjects;
std::optional<bool> ntpEnabled;
std::optional<bool> ipmiEnabled;
std::optional<bool> sshEnabled;