summaryrefslogtreecommitdiff
path: root/redfish-core/src
diff options
context:
space:
mode:
authorJason M. Bills <jason.m.bills@linux.intel.com>2018-10-09 22:45:45 +0300
committerJason M. Bills <jason.m.bills@linux.intel.com>2018-10-23 03:00:16 +0300
commitf12894f8bd7fc26ffa16e5a89072e6c19095f866 (patch)
treee2e2e1629f80a29efca04bd9714525465575549e /redfish-core/src
parent9712f8ac42746e65f32c2bc3de0835846652568e (diff)
downloadbmcweb-f12894f8bd7fc26ffa16e5a89072e6c19095f866.tar.xz
Improve the Redfish error reporting interface
Makes the Redfish error reporting interface automatically handle setting the http status and JSON content in the response object. When using an AsyncResp object, this allows for simply calling the Redfish error and returning. Change-Id: Icfdce2de763225f070e8dd61e591f296703f46bb Signed-off-by: Jason M. Bills <jason.m.bills@linux.intel.com>
Diffstat (limited to 'redfish-core/src')
-rw-r--r--redfish-core/src/error_messages.cpp1586
-rw-r--r--redfish-core/src/utils/json_utils.cpp482
2 files changed, 993 insertions, 1075 deletions
diff --git a/redfish-core/src/error_messages.cpp b/redfish-core/src/error_messages.cpp
index a8077629ac..949ce0fef3 100644
--- a/redfish-core/src/error_messages.cpp
+++ b/redfish-core/src/error_messages.cpp
@@ -23,8 +23,8 @@ namespace redfish
namespace messages
{
-void addMessageToErrorJson(nlohmann::json& target,
- const nlohmann::json& message)
+static void addMessageToErrorJson(nlohmann::json& target,
+ const nlohmann::json& message)
{
auto& error = target["error"];
@@ -75,7 +75,8 @@ void addMessageToErrorJson(nlohmann::json& target,
extended_info.push_back(message);
}
-void addMessageToJsonRoot(nlohmann::json& target, const nlohmann::json& message)
+static void addMessageToJsonRoot(nlohmann::json& target,
+ const nlohmann::json& message)
{
if (!target[messages::messageAnnotation].is_array())
{
@@ -86,8 +87,9 @@ void addMessageToJsonRoot(nlohmann::json& target, const nlohmann::json& message)
target[messages::messageAnnotation].push_back(message);
}
-void addMessageToJson(nlohmann::json& target, const nlohmann::json& message,
- const std::string& fieldPath)
+static void addMessageToJson(nlohmann::json& target,
+ const nlohmann::json& message,
+ const std::string& fieldPath)
{
nlohmann::json_pointer<nlohmann::json> extendedInfo(
fieldPath + messages::messageAnnotation);
@@ -102,10 +104,6 @@ void addMessageToJson(nlohmann::json& target, const nlohmann::json& message,
target[extendedInfo].push_back(message);
}
-/*********************************
- * AUTOGENERATED FUNCTIONS START *
- *********************************/
-
/**
* @internal
* @brief Formats ResourceInUse message into JSON
@@ -113,18 +111,22 @@ void addMessageToJson(nlohmann::json& target, const nlohmann::json& message,
* See header file for more information
* @endinternal
*/
-nlohmann::json resourceInUse()
+void resourceInUse(crow::Response& res)
{
- return nlohmann::json{
- {"@odata.type", "/redfish/v1/$metadata#Message.v1_0_0.Message"},
- {"MessageId", "Base.1.2.0.ResourceInUse"},
- {"Message", "The change to the requested resource failed because the "
- "resource is in "
- "use or in transition."},
- {"Severity", "Warning"},
- {"Resolution",
- "Remove the condition and resubmit the request if the operation "
- "failed."}};
+ res.result(boost::beast::http::status::service_unavailable);
+ addMessageToErrorJson(
+ res.jsonValue,
+ nlohmann::json{
+ {"@odata.type", "/redfish/v1/$metadata#Message.v1_0_0.Message"},
+ {"MessageId", "Base.1.2.0.ResourceInUse"},
+ {"Message",
+ "The change to the requested resource failed because the "
+ "resource is in "
+ "use or in transition."},
+ {"Severity", "Warning"},
+ {"Resolution",
+ "Remove the condition and resubmit the request if the operation "
+ "failed."}});
}
/**
@@ -134,17 +136,21 @@ nlohmann::json resourceInUse()
* See header file for more information
* @endinternal
*/
-nlohmann::json malformedJSON()
+void malformedJSON(crow::Response& res)
{
- return nlohmann::json{
- {"@odata.type", "/redfish/v1/$metadata#Message.v1_0_0.Message"},
- {"MessageId", "Base.1.2.0.MalformedJSON"},
- {"Message", "The request body submitted was malformed JSON and could "
- "not be parsed "
- "by the receiving service."},
- {"Severity", "Critical"},
- {"Resolution", "Ensure that the request body is valid JSON and "
- "resubmit the request."}};
+ res.result(boost::beast::http::status::bad_request);
+ addMessageToErrorJson(
+ res.jsonValue,
+ nlohmann::json{
+ {"@odata.type", "/redfish/v1/$metadata#Message.v1_0_0.Message"},
+ {"MessageId", "Base.1.2.0.MalformedJSON"},
+ {"Message",
+ "The request body submitted was malformed JSON and could "
+ "not be parsed "
+ "by the receiving service."},
+ {"Severity", "Critical"},
+ {"Resolution", "Ensure that the request body is valid JSON and "
+ "resubmit the request."}});
}
/**
@@ -154,16 +160,20 @@ nlohmann::json malformedJSON()
* See header file for more information
* @endinternal
*/
-nlohmann::json resourceMissingAtURI(const std::string& arg1)
+void resourceMissingAtURI(crow::Response& res, const std::string& arg1)
{
- return nlohmann::json{
- {"@odata.type", "/redfish/v1/$metadata#Message.v1_0_0.Message"},
- {"MessageId", "Base.1.2.0.ResourceMissingAtURI"},
- {"Message", "The resource at the URI " + arg1 + " was not found."},
- {"Severity", "Critical"},
- {"Resolution", "Place a valid resource at the URI or correct the URI "
- "and resubmit the "
- "request."}};
+ res.result(boost::beast::http::status::bad_request);
+ addMessageToErrorJson(
+ res.jsonValue,
+ nlohmann::json{
+ {"@odata.type", "/redfish/v1/$metadata#Message.v1_0_0.Message"},
+ {"MessageId", "Base.1.2.0.ResourceMissingAtURI"},
+ {"Message", "The resource at the URI " + arg1 + " was not found."},
+ {"Severity", "Critical"},
+ {"Resolution",
+ "Place a valid resource at the URI or correct the URI "
+ "and resubmit the "
+ "request."}});
}
/**
@@ -173,21 +183,25 @@ nlohmann::json resourceMissingAtURI(const std::string& arg1)
* See header file for more information
* @endinternal
*/
-nlohmann::json actionParameterValueFormatError(const std::string& arg1,
- const std::string& arg2,
- const std::string& arg3)
-{
- return nlohmann::json{
- {"@odata.type", "/redfish/v1/$metadata#Message.v1_0_0.Message"},
- {"MessageId", "Base.1.2.0.ActionParameterValueFormatError"},
- {"Message",
- "The value " + arg1 + " for the parameter " + arg2 +
- " in the action " + arg3 +
- " is of a different format than the parameter can accept."},
- {"Severity", "Warning"},
- {"Resolution",
- "Correct the value for the parameter in the request body and resubmit "
- "the request if the operation failed."}};
+void actionParameterValueFormatError(crow::Response& res,
+ const std::string& arg1,
+ const std::string& arg2,
+ const std::string& arg3)
+{
+ res.result(boost::beast::http::status::bad_request);
+ addMessageToErrorJson(
+ res.jsonValue,
+ nlohmann::json{
+ {"@odata.type", "/redfish/v1/$metadata#Message.v1_0_0.Message"},
+ {"MessageId", "Base.1.2.0.ActionParameterValueFormatError"},
+ {"Message",
+ "The value " + arg1 + " for the parameter " + arg2 +
+ " in the action " + arg3 +
+ " is of a different format than the parameter can accept."},
+ {"Severity", "Warning"},
+ {"Resolution", "Correct the value for the parameter in the request "
+ "body and resubmit "
+ "the request if the operation failed."}});
}
/**
@@ -197,18 +211,46 @@ nlohmann::json actionParameterValueFormatError(const std::string& arg1,
* See header file for more information
* @endinternal
*/
-nlohmann::json internalError()
+void internalError(crow::Response& res)
{
- return nlohmann::json{
- {"@odata.type", "/redfish/v1/$metadata#Message.v1_0_0.Message"},
- {"MessageId", "Base.1.2.0.InternalError"},
- {"Message",
- "The request failed due to an internal service error. The service is "
- "still operational."},
- {"Severity", "Critical"},
- {"Resolution", "Resubmit the request. If the problem persists, "
- "consider resetting the "
- "service."}};
+ res.result(boost::beast::http::status::internal_server_error);
+ addMessageToErrorJson(
+ res.jsonValue,
+ nlohmann::json{
+ {"@odata.type", "/redfish/v1/$metadata#Message.v1_0_0.Message"},
+ {"MessageId", "Base.1.2.0.InternalError"},
+ {"Message", "The request failed due to an internal service error. "
+ "The service is "
+ "still operational."},
+ {"Severity", "Critical"},
+ {"Resolution", "Resubmit the request. If the problem persists, "
+ "consider resetting the "
+ "service."}});
+}
+
+/**
+ * @internal
+ * @brief Formats InternalError message into JSON for the specified field
+ *
+ * See header file for more information
+ * @endinternal
+ */
+void internalError(crow::Response& res, const std::string& field)
+{
+ res.result(boost::beast::http::status::internal_server_error);
+ addMessageToJson(
+ res.jsonValue,
+ nlohmann::json{
+ {"@odata.type", "/redfish/v1/$metadata#Message.v1_0_0.Message"},
+ {"MessageId", "Base.1.2.0.InternalError"},
+ {"Message", "The request failed due to an internal service error. "
+ "The service is "
+ "still operational."},
+ {"Severity", "Critical"},
+ {"Resolution", "Resubmit the request. If the problem persists, "
+ "consider resetting the "
+ "service."}},
+ field);
}
/**
@@ -218,17 +260,20 @@ nlohmann::json internalError()
* See header file for more information
* @endinternal
*/
-nlohmann::json unrecognizedRequestBody()
+void unrecognizedRequestBody(crow::Response& res)
{
- return nlohmann::json{
- {"@odata.type", "/redfish/v1/$metadata#Message.v1_0_0.Message"},
- {"MessageId", "Base.1.2.0.UnrecognizedRequestBody"},
- {"Message",
- "The service detected a malformed request body that it was unable to "
- "interpret."},
- {"Severity", "Warning"},
- {"Resolution",
- "Correct the request body and resubmit the request if it failed."}};
+ res.result(boost::beast::http::status::bad_request);
+ addMessageToErrorJson(
+ res.jsonValue,
+ nlohmann::json{
+ {"@odata.type", "/redfish/v1/$metadata#Message.v1_0_0.Message"},
+ {"MessageId", "Base.1.2.0.UnrecognizedRequestBody"},
+ {"Message", "The service detected a malformed request body that it "
+ "was unable to "
+ "interpret."},
+ {"Severity", "Warning"},
+ {"Resolution", "Correct the request body and resubmit the request "
+ "if it failed."}});
}
/**
@@ -238,19 +283,22 @@ nlohmann::json unrecognizedRequestBody()
* See header file for more information
* @endinternal
*/
-nlohmann::json resourceAtUriUnauthorized(const std::string& arg1,
- const std::string& arg2)
+void resourceAtUriUnauthorized(crow::Response& res, const std::string& arg1,
+ const std::string& arg2)
{
- return nlohmann::json{
- {"@odata.type", "/redfish/v1/$metadata#Message.v1_0_0.Message"},
- {"MessageId", "Base.1.2.0.ResourceAtUriUnauthorized"},
- {"Message", "While accessing the resource at " + arg1 +
- ", the service received an authorization error " +
- arg2 + "."},
- {"Severity", "Critical"},
- {"Resolution",
- "Ensure that the appropriate access is provided for the service in "
- "order for it to access the URI."}};
+ res.result(boost::beast::http::status::forbidden);
+ addMessageToErrorJson(
+ res.jsonValue,
+ nlohmann::json{
+ {"@odata.type", "/redfish/v1/$metadata#Message.v1_0_0.Message"},
+ {"MessageId", "Base.1.2.0.ResourceAtUriUnauthorized"},
+ {"Message", "While accessing the resource at " + arg1 +
+ ", the service received an authorization error " +
+ arg2 + "."},
+ {"Severity", "Critical"},
+ {"Resolution", "Ensure that the appropriate access is provided for "
+ "the service in "
+ "order for it to access the URI."}});
}
/**
@@ -260,19 +308,22 @@ nlohmann::json resourceAtUriUnauthorized(const std::string& arg1,
* See header file for more information
* @endinternal
*/
-nlohmann::json actionParameterUnknown(const std::string& arg1,
- const std::string& arg2)
+void actionParameterUnknown(crow::Response& res, const std::string& arg1,
+ const std::string& arg2)
{
- return nlohmann::json{
- {"@odata.type", "/redfish/v1/$metadata#Message.v1_0_0.Message"},
- {"MessageId", "Base.1.2.0.ActionParameterUnknown"},
- {"Message", "The action " + arg1 +
- " was submitted with the invalid parameter " + arg2 +
- "."},
- {"Severity", "Warning"},
- {"Resolution",
- "Correct the invalid parameter and resubmit the request if the "
- "operation failed."}};
+ res.result(boost::beast::http::status::bad_request);
+ addMessageToErrorJson(
+ res.jsonValue,
+ nlohmann::json{
+ {"@odata.type", "/redfish/v1/$metadata#Message.v1_0_0.Message"},
+ {"MessageId", "Base.1.2.0.ActionParameterUnknown"},
+ {"Message", "The action " + arg1 +
+ " was submitted with the invalid parameter " +
+ arg2 + "."},
+ {"Severity", "Warning"},
+ {"Resolution",
+ "Correct the invalid parameter and resubmit the request if the "
+ "operation failed."}});
}
/**
@@ -282,16 +333,20 @@ nlohmann::json actionParameterUnknown(const std::string& arg1,
* See header file for more information
* @endinternal
*/
-nlohmann::json resourceCannotBeDeleted()
+void resourceCannotBeDeleted(crow::Response& res)
{
- return nlohmann::json{
- {"@odata.type", "/redfish/v1/$metadata#Message.v1_0_0.Message"},
- {"MessageId", "Base.1.2.0.ResourceCannotBeDeleted"},
- {"Message",
- "The delete request failed because the resource requested cannot be "
- "deleted."},
- {"Severity", "Critical"},
- {"Resolution", "Do not attempt to delete a non-deletable resource."}};
+ res.result(boost::beast::http::status::forbidden);
+ addMessageToErrorJson(
+ res.jsonValue,
+ nlohmann::json{
+ {"@odata.type", "/redfish/v1/$metadata#Message.v1_0_0.Message"},
+ {"MessageId", "Base.1.2.0.ResourceCannotBeDeleted"},
+ {"Message", "The delete request failed because the resource "
+ "requested cannot be "
+ "deleted."},
+ {"Severity", "Critical"},
+ {"Resolution",
+ "Do not attempt to delete a non-deletable resource."}});
}
/**
@@ -301,16 +356,20 @@ nlohmann::json resourceCannotBeDeleted()
* See header file for more information
* @endinternal
*/
-nlohmann::json propertyDuplicate(const std::string& arg1)
+void propertyDuplicate(crow::Response& res, const std::string& arg1)
{
- return nlohmann::json{
- {"@odata.type", "/redfish/v1/$metadata#Message.v1_0_0.Message"},
- {"MessageId", "Base.1.2.0.PropertyDuplicate"},
- {"Message", "The property " + arg1 + " was duplicated in the request."},
- {"Severity", "Warning"},
- {"Resolution",
- "Remove the duplicate property from the request body and resubmit the "
- "request if the operation failed."}};
+ res.result(boost::beast::http::status::bad_request);
+ addMessageToErrorJson(
+ res.jsonValue,
+ nlohmann::json{
+ {"@odata.type", "/redfish/v1/$metadata#Message.v1_0_0.Message"},
+ {"MessageId", "Base.1.2.0.PropertyDuplicate"},
+ {"Message",
+ "The property " + arg1 + " was duplicated in the request."},
+ {"Severity", "Warning"},
+ {"Resolution", "Remove the duplicate property from the request "
+ "body and resubmit the "
+ "request if the operation failed."}});
}
/**
@@ -320,16 +379,19 @@ nlohmann::json propertyDuplicate(const std::string& arg1)
* See header file for more information
* @endinternal
*/
-nlohmann::json serviceTemporarilyUnavailable(const std::string& arg1)
+void serviceTemporarilyUnavailable(crow::Response& res, const std::string& arg1)
{
- return nlohmann::json{
- {"@odata.type", "/redfish/v1/$metadata#Message.v1_0_0.Message"},
- {"MessageId", "Base.1.2.0.ServiceTemporarilyUnavailable"},
- {"Message", "The service is temporarily unavailable. Retry in " +
- arg1 + " seconds."},
- {"Severity", "Critical"},
- {"Resolution",
- "Wait for the indicated retry duration and retry the operation."}};
+ res.result(boost::beast::http::status::service_unavailable);
+ addMessageToErrorJson(
+ res.jsonValue,
+ nlohmann::json{
+ {"@odata.type", "/redfish/v1/$metadata#Message.v1_0_0.Message"},
+ {"MessageId", "Base.1.2.0.ServiceTemporarilyUnavailable"},
+ {"Message", "The service is temporarily unavailable. Retry in " +
+ arg1 + " seconds."},
+ {"Severity", "Critical"},
+ {"Resolution", "Wait for the indicated retry duration and retry "
+ "the operation."}});
}
/**
@@ -339,20 +401,22 @@ nlohmann::json serviceTemporarilyUnavailable(const std::string& arg1)
* See header file for more information
* @endinternal
*/
-nlohmann::json resourceAlreadyExists(const std::string& arg1,
- const std::string& arg2,
- const std::string& arg3)
+void resourceAlreadyExists(crow::Response& res, const std::string& arg1,
+ const std::string& arg2, const std::string& arg3)
{
- return nlohmann::json{
- {"@odata.type", "/redfish/v1/$metadata#Message.v1_0_0.Message"},
- {"MessageId", "Base.1.2.0.ResourceAlreadyExists"},
- {"Message", "The requested resource of type " + arg1 +
- " with the property " + arg2 + " with the value " +
- arg3 + " already exists."},
- {"Severity", "Critical"},
- {"Resolution",
- "Do not repeat the create operation as the resource has already been "
- "created."}};
+ res.result(boost::beast::http::status::bad_request);
+ addMessageToErrorJson(
+ res.jsonValue,
+ nlohmann::json{
+ {"@odata.type", "/redfish/v1/$metadata#Message.v1_0_0.Message"},
+ {"MessageId", "Base.1.2.0.ResourceAlreadyExists"},
+ {"Message", "The requested resource of type " + arg1 +
+ " with the property " + arg2 + " with the value " +
+ arg3 + " already exists."},
+ {"Severity", "Critical"},
+ {"Resolution", "Do not repeat the create operation as the resource "
+ "has already been "
+ "created."}});
}
/**
@@ -362,16 +426,21 @@ nlohmann::json resourceAlreadyExists(const std::string& arg1,
* See header file for more information
* @endinternal
*/
-nlohmann::json accountForSessionNoLongerExists()
+void accountForSessionNoLongerExists(crow::Response& res,
+ const std::string& fieldPath)
{
- return nlohmann::json{
- {"@odata.type", "/redfish/v1/$metadata#Message.v1_0_0.Message"},
- {"MessageId", "Base.1.2.0.AccountForSessionNoLongerExists"},
- {"Message", "The account for the current session has been removed, "
- "thus the current "
- "session has been removed as well."},
- {"Severity", "OK"},
- {"Resolution", "Attempt to connect with a valid account."}};
+ res.result(boost::beast::http::status::forbidden);
+ addMessageToJson(
+ res.jsonValue,
+ nlohmann::json{
+ {"@odata.type", "/redfish/v1/$metadata#Message.v1_0_0.Message"},
+ {"MessageId", "Base.1.2.0.AccountForSessionNoLongerExists"},
+ {"Message", "The account for the current session has been removed, "
+ "thus the current "
+ "session has been removed as well."},
+ {"Severity", "OK"},
+ {"Resolution", "Attempt to connect with a valid account."}},
+ fieldPath);
}
/**
@@ -381,18 +450,23 @@ nlohmann::json accountForSessionNoLongerExists()
* See header file for more information
* @endinternal
*/
-nlohmann::json createFailedMissingReqProperties(const std::string& arg1)
+void createFailedMissingReqProperties(crow::Response& res,
+ const std::string& arg1)
{
- return nlohmann::json{
- {"@odata.type", "/redfish/v1/$metadata#Message.v1_0_0.Message"},
- {"MessageId", "Base.1.2.0.CreateFailedMissingReqProperties"},
- {"Message",
- "The create operation failed because the required property " + arg1 +
- " was missing from the request."},
- {"Severity", "Critical"},
- {"Resolution",
- "Correct the body to include the required property with a valid value "
- "and resubmit the request if the operation failed."}};
+ res.result(boost::beast::http::status::bad_request);
+ addMessageToErrorJson(
+ res.jsonValue,
+ nlohmann::json{
+ {"@odata.type", "/redfish/v1/$metadata#Message.v1_0_0.Message"},
+ {"MessageId", "Base.1.2.0.CreateFailedMissingReqProperties"},
+ {"Message",
+ "The create operation failed because the required property " +
+ arg1 + " was missing from the request."},
+ {"Severity", "Critical"},
+ {"Resolution",
+ "Correct the body to include the required property with a valid "
+ "value "
+ "and resubmit the request if the operation failed."}});
}
/**
@@ -402,19 +476,50 @@ nlohmann::json createFailedMissingReqProperties(const std::string& arg1)
* See header file for more information
* @endinternal
*/
-nlohmann::json propertyValueFormatError(const std::string& arg1,
- const std::string& arg2)
+void propertyValueFormatError(crow::Response& res, const std::string& arg1,
+ const std::string& arg2)
{
- return nlohmann::json{
- {"@odata.type", "/redfish/v1/$metadata#Message.v1_0_0.Message"},
- {"MessageId", "Base.1.2.0.PropertyValueFormatError"},
- {"Message",
- "The value " + arg1 + " for the property " + arg2 +
- " is of a different format than the property can accept."},
- {"Severity", "Warning"},
- {"Resolution",
- "Correct the value for the property in the request body and resubmit "
- "the request if the operation failed."}};
+ res.result(boost::beast::http::status::bad_request);
+ addMessageToErrorJson(
+ res.jsonValue,
+ nlohmann::json{
+ {"@odata.type", "/redfish/v1/$metadata#Message.v1_0_0.Message"},
+ {"MessageId", "Base.1.2.0.PropertyValueFormatError"},
+ {"Message",
+ "The value " + arg1 + " for the property " + arg2 +
+ " is of a different format than the property can accept."},
+ {"Severity", "Warning"},
+ {"Resolution", "Correct the value for the property in the request "
+ "body and resubmit "
+ "the request if the operation failed."}});
+}
+
+/**
+ * @internal
+ * @brief Formats PropertyValueFormatError message into JSON for the specified
+ * property
+ *
+ * See header file for more information
+ * @endinternal
+ */
+void propertyValueFormatError(crow::Response& res, const std::string& arg1,
+ const std::string& arg2,
+ const std::string property)
+{
+ res.result(boost::beast::http::status::bad_request);
+ addMessageToJson(
+ res.jsonValue,
+ nlohmann::json{
+ {"@odata.type", "/redfish/v1/$metadata#Message.v1_0_0.Message"},
+ {"MessageId", "Base.1.2.0.PropertyValueFormatError"},
+ {"Message",
+ "The value " + arg1 + " for the property " + arg2 +
+ " is of a different format than the property can accept."},
+ {"Severity", "Warning"},
+ {"Resolution", "Correct the value for the property in the request "
+ "body and resubmit "
+ "the request if the operation failed."}},
+ property);
}
/**
@@ -424,18 +529,49 @@ nlohmann::json propertyValueFormatError(const std::string& arg1,
* See header file for more information
* @endinternal
*/
-nlohmann::json propertyValueNotInList(const std::string& arg1,
- const std::string& arg2)
+void propertyValueNotInList(crow::Response& res, const std::string& arg1,
+ const std::string& arg2)
+{
+ res.result(boost::beast::http::status::bad_request);
+ addMessageToErrorJson(
+ res.jsonValue,
+ nlohmann::json{
+ {"@odata.type", "/redfish/v1/$metadata#Message.v1_0_0.Message"},
+ {"MessageId", "Base.1.2.0.PropertyValueNotInList"},
+ {"Message", "The value " + arg1 + " for the property " + arg2 +
+ " is not in the list of acceptable values."},
+ {"Severity", "Warning"},
+ {"Resolution",
+ "Choose a value from the enumeration list that the implementation "
+ "can "
+ "support and resubmit the request if the operation failed."}});
+}
+
+/**
+ * @internal
+ * @brief Formats PropertyValueNotInList message into JSON for the specified
+ * property
+ *
+ * See header file for more information
+ * @endinternal
+ */
+void propertyValueNotInList(crow::Response& res, const std::string& arg1,
+ const std::string& arg2, const std::string property)
{
- return nlohmann::json{
- {"@odata.type", "/redfish/v1/$metadata#Message.v1_0_0.Message"},
- {"MessageId", "Base.1.2.0.PropertyValueNotInList"},
- {"Message", "The value " + arg1 + " for the property " + arg2 +
- " is not in the list of acceptable values."},
- {"Severity", "Warning"},
- {"Resolution",
- "Choose a value from the enumeration list that the implementation can "
- "support and resubmit the request if the operation failed."}};
+ res.result(boost::beast::http::status::bad_request);
+ addMessageToJson(
+ res.jsonValue,
+ nlohmann::json{
+ {"@odata.type", "/redfish/v1/$metadata#Message.v1_0_0.Message"},
+ {"MessageId", "Base.1.2.0.PropertyValueNotInList"},
+ {"Message", "The value " + arg1 + " for the property " + arg2 +
+ " is not in the list of acceptable values."},
+ {"Severity", "Warning"},
+ {"Resolution",
+ "Choose a value from the enumeration list that the implementation "
+ "can "
+ "support and resubmit the request if the operation failed."}},
+ property);
}
/**
@@ -445,17 +581,20 @@ nlohmann::json propertyValueNotInList(const std::string& arg1,
* See header file for more information
* @endinternal
*/
-nlohmann::json resourceAtUriInUnknownFormat(const std::string& arg1)
+void resourceAtUriInUnknownFormat(crow::Response& res, const std::string& arg1)
{
- return nlohmann::json{
- {"@odata.type", "/redfish/v1/$metadata#Message.v1_0_0.Message"},
- {"MessageId", "Base.1.2.0.ResourceAtUriInUnknownFormat"},
- {"Message", "The resource at " + arg1 +
- " is in a format not recognized by the service."},
- {"Severity", "Critical"},
- {"Resolution",
- "Place an image or resource or file that is recognized by the service "
- "at the URI."}};
+ res.result(boost::beast::http::status::bad_request);
+ addMessageToErrorJson(
+ res.jsonValue,
+ nlohmann::json{
+ {"@odata.type", "/redfish/v1/$metadata#Message.v1_0_0.Message"},
+ {"MessageId", "Base.1.2.0.ResourceAtUriInUnknownFormat"},
+ {"Message", "The resource at " + arg1 +
+ " is in a format not recognized by the service."},
+ {"Severity", "Critical"},
+ {"Resolution", "Place an image or resource or file that is "
+ "recognized by the service "
+ "at the URI."}});
}
/**
@@ -465,18 +604,21 @@ nlohmann::json resourceAtUriInUnknownFormat(const std::string& arg1)
* See header file for more information
* @endinternal
*/
-nlohmann::json serviceInUnknownState()
+void serviceInUnknownState(crow::Response& res)
{
- return nlohmann::json{
- {"@odata.type", "/redfish/v1/$metadata#Message.v1_0_0.Message"},
- {"MessageId", "Base.1.2.0.ServiceInUnknownState"},
- {"Message",
- "The operation failed because the service is in an unknown state and "
- "can no longer take incoming requests."},
- {"Severity", "Critical"},
- {"Resolution",
- "Restart the service and resubmit the request if the operation "
- "failed."}};
+ res.result(boost::beast::http::status::service_unavailable);
+ addMessageToErrorJson(
+ res.jsonValue,
+ nlohmann::json{
+ {"@odata.type", "/redfish/v1/$metadata#Message.v1_0_0.Message"},
+ {"MessageId", "Base.1.2.0.ServiceInUnknownState"},
+ {"Message", "The operation failed because the service is in an "
+ "unknown state and "
+ "can no longer take incoming requests."},
+ {"Severity", "Critical"},
+ {"Resolution",
+ "Restart the service and resubmit the request if the operation "
+ "failed."}});
}
/**
@@ -486,19 +628,23 @@ nlohmann::json serviceInUnknownState()
* See header file for more information
* @endinternal
*/
-nlohmann::json eventSubscriptionLimitExceeded()
+void eventSubscriptionLimitExceeded(crow::Response& res)
{
- return nlohmann::json{
- {"@odata.type", "/redfish/v1/$metadata#Message.v1_0_0.Message"},
- {"MessageId", "Base.1.2.0.EventSubscriptionLimitExceeded"},
- {"Message",
- "The event subscription failed due to the number of simultaneous "
- "subscriptions exceeding the limit of the implementation."},
- {"Severity", "Critical"},
- {"Resolution",
- "Reduce the number of other subscriptions before trying to establish "
- "the event subscription or increase the limit of simultaneous "
- "subscriptions (if supported)."}};
+ res.result(boost::beast::http::status::forbidden);
+ addMessageToErrorJson(
+ res.jsonValue,
+ nlohmann::json{
+ {"@odata.type", "/redfish/v1/$metadata#Message.v1_0_0.Message"},
+ {"MessageId", "Base.1.2.0.EventSubscriptionLimitExceeded"},
+ {"Message",
+ "The event subscription failed due to the number of simultaneous "
+ "subscriptions exceeding the limit of the implementation."},
+ {"Severity", "Critical"},
+ {"Resolution",
+ "Reduce the number of other subscriptions before trying to "
+ "establish "
+ "the event subscription or increase the limit of simultaneous "
+ "subscriptions (if supported)."}});
}
/**
@@ -508,18 +654,22 @@ nlohmann::json eventSubscriptionLimitExceeded()
* See header file for more information
* @endinternal
*/
-nlohmann::json actionParameterMissing(const std::string& arg1,
- const std::string& arg2)
+void actionParameterMissing(crow::Response& res, const std::string& arg1,
+ const std::string& arg2)
{
- return nlohmann::json{
- {"@odata.type", "/redfish/v1/$metadata#Message.v1_0_0.Message"},
- {"MessageId", "Base.1.2.0.ActionParameterMissing"},
- {"Message", "The action " + arg1 + " requires the parameter " + arg2 +
- " to be present in the request body."},
- {"Severity", "Critical"},
- {"Resolution", "Supply the action with the required parameter in the "
- "request body when "
- "the request is resubmitted."}};
+ res.result(boost::beast::http::status::bad_request);
+ addMessageToErrorJson(
+ res.jsonValue,
+ nlohmann::json{
+ {"@odata.type", "/redfish/v1/$metadata#Message.v1_0_0.Message"},
+ {"MessageId", "Base.1.2.0.ActionParameterMissing"},
+ {"Message", "The action " + arg1 + " requires the parameter " +
+ arg2 + " to be present in the request body."},
+ {"Severity", "Critical"},
+ {"Resolution",
+ "Supply the action with the required parameter in the "
+ "request body when "
+ "the request is resubmitted."}});
}
/**
@@ -529,16 +679,20 @@ nlohmann::json actionParameterMissing(const std::string& arg1,
* See header file for more information
* @endinternal
*/
-nlohmann::json stringValueTooLong(const std::string& arg1, const int& arg2)
+void stringValueTooLong(crow::Response& res, const std::string& arg1,
+ const int& arg2)
{
- return nlohmann::json{
- {"@odata.type", "/redfish/v1/$metadata#Message.v1_0_0.Message"},
- {"MessageId", "Base.1.2.0.StringValueTooLong"},
- {"Message", "The string " + arg1 + " exceeds the length limit " +
- std::to_string(arg2) + "."},
- {"Severity", "Warning"},
- {"Resolution",
- "Resubmit the request with an appropriate string length."}};
+ res.result(boost::beast::http::status::bad_request);
+ addMessageToErrorJson(
+ res.jsonValue,
+ nlohmann::json{
+ {"@odata.type", "/redfish/v1/$metadata#Message.v1_0_0.Message"},
+ {"MessageId", "Base.1.2.0.StringValueTooLong"},
+ {"Message", "The string " + arg1 + " exceeds the length limit " +
+ std::to_string(arg2) + "."},
+ {"Severity", "Warning"},
+ {"Resolution",
+ "Resubmit the request with an appropriate string length."}});
}
/**
@@ -548,19 +702,50 @@ nlohmann::json stringValueTooLong(const std::string& arg1, const int& arg2)
* See header file for more information
* @endinternal
*/
-nlohmann::json propertyValueTypeError(const std::string& arg1,
- const std::string& arg2)
+void propertyValueTypeError(crow::Response& res, const std::string& arg1,
+ const std::string& arg2)
+{
+ res.result(boost::beast::http::status::bad_request);
+ addMessageToErrorJson(
+ res.jsonValue,
+ nlohmann::json{
+ {"@odata.type", "/redfish/v1/$metadata#Message.v1_0_0.Message"},
+ {"MessageId", "Base.1.2.0.PropertyValueTypeError"},
+ {"Message",
+ "The value " + arg1 + " for the property " + arg2 +
+ " is of a different type than the property can accept."},
+ {"Severity", "Warning"},
+ {"Resolution", "Correct the value for the property in the request "
+ "body and resubmit "
+ "the request if the operation failed."}});
+}
+
+/**
+ * @internal
+ * @brief Formats PropertyValueTypeError message into JSON for the specified
+ * property
+ *
+ * See header file for more information
+ * @endinternal
+ */
+void propertyValueTypeError(crow::Response& res, const std::string& arg1,
+ const std::string& arg2,
+ const std::string& property)
{
- return nlohmann::json{
- {"@odata.type", "/redfish/v1/$metadata#Message.v1_0_0.Message"},
- {"MessageId", "Base.1.2.0.PropertyValueTypeError"},
- {"Message",
- "The value " + arg1 + " for the property " + arg2 +
- " is of a different type than the property can accept."},
- {"Severity", "Warning"},
- {"Resolution",
- "Correct the value for the property in the request body and resubmit "
- "the request if the operation failed."}};
+ res.result(boost::beast::http::status::bad_request);
+ addMessageToJson(
+ res.jsonValue,
+ nlohmann::json{
+ {"@odata.type", "/redfish/v1/$metadata#Message.v1_0_0.Message"},
+ {"MessageId", "Base.1.2.0.PropertyValueTypeError"},
+ {"Message",
+ "The value " + arg1 + " for the property " + arg2 +
+ " is of a different type than the property can accept."},
+ {"Severity", "Warning"},
+ {"Resolution", "Correct the value for the property in the request "
+ "body and resubmit "
+ "the request if the operation failed."}},
+ property);
}
/**
@@ -570,17 +755,20 @@ nlohmann::json propertyValueTypeError(const std::string& arg1,
* See header file for more information
* @endinternal
*/
-nlohmann::json resourceNotFound(const std::string& arg1,
- const std::string& arg2)
+void resourceNotFound(crow::Response& res, const std::string& arg1,
+ const std::string& arg2)
{
- return nlohmann::json{
- {"@odata.type", "/redfish/v1/$metadata#Message.v1_0_0.Message"},
- {"MessageId", "Base.1.2.0.ResourceNotFound"},
- {"Message", "The requested resource of type " + arg1 + " named " +
- arg2 + " was not found."},
- {"Severity", "Critical"},
- {"Resolution",
- "Provide a valid resource identifier and resubmit the request."}};
+ res.result(boost::beast::http::status::not_found);
+ addMessageToErrorJson(
+ res.jsonValue,
+ nlohmann::json{
+ {"@odata.type", "/redfish/v1/$metadata#Message.v1_0_0.Message"},
+ {"MessageId", "Base.1.2.0.ResourceNotFound"},
+ {"Message", "The requested resource of type " + arg1 + " named " +
+ arg2 + " was not found."},
+ {"Severity", "Critical"},
+ {"Resolution",
+ "Provide a valid resource identifier and resubmit the request."}});
}
/**
@@ -590,18 +778,21 @@ nlohmann::json resourceNotFound(const std::string& arg1,
* See header file for more information
* @endinternal
*/
-nlohmann::json couldNotEstablishConnection(const std::string& arg1)
+void couldNotEstablishConnection(crow::Response& res, const std::string& arg1)
{
- return nlohmann::json{
- {"@odata.type", "/redfish/v1/$metadata#Message.v1_0_0.Message"},
- {"MessageId", "Base.1.2.0.CouldNotEstablishConnection"},
- {"Message",
- "The service failed to establish a Connection with the URI " + arg1 +
- "."},
- {"Severity", "Critical"},
- {"Resolution", "Ensure that the URI contains a valid and reachable "
- "node name, protocol "
- "information and other URI components."}};
+ res.result(boost::beast::http::status::not_found);
+ addMessageToErrorJson(
+ res.jsonValue,
+ nlohmann::json{
+ {"@odata.type", "/redfish/v1/$metadata#Message.v1_0_0.Message"},
+ {"MessageId", "Base.1.2.0.CouldNotEstablishConnection"},
+ {"Message",
+ "The service failed to establish a Connection with the URI " +
+ arg1 + "."},
+ {"Severity", "Critical"},
+ {"Resolution", "Ensure that the URI contains a valid and reachable "
+ "node name, protocol "
+ "information and other URI components."}});
}
/**
@@ -611,18 +802,50 @@ nlohmann::json couldNotEstablishConnection(const std::string& arg1)
* See header file for more information
* @endinternal
*/
-nlohmann::json propertyNotWritable(const std::string& arg1)
+void propertyNotWritable(crow::Response& res, const std::string& arg1)
{
- return nlohmann::json{
- {"@odata.type", "/redfish/v1/$metadata#Message.v1_0_0.Message"},
- {"MessageId", "Base.1.2.0.PropertyNotWritable"},
- {"Message",
- "The property " + arg1 +
- " is a read only property and cannot be assigned a value."},
- {"Severity", "Warning"},
- {"Resolution", "Remove the property from the request body and resubmit "
- "the request if "
- "the operation failed."}};
+ res.result(boost::beast::http::status::forbidden);
+ addMessageToErrorJson(
+ res.jsonValue,
+ nlohmann::json{
+ {"@odata.type", "/redfish/v1/$metadata#Message.v1_0_0.Message"},
+ {"MessageId", "Base.1.2.0.PropertyNotWritable"},
+ {"Message",
+ "The property " + arg1 +
+ " is a read only property and cannot be assigned a value."},
+ {"Severity", "Warning"},
+ {"Resolution",
+ "Remove the property from the request body and resubmit "
+ "the request if "
+ "the operation failed."}});
+}
+
+/**
+ * @internal
+ * @brief Formats PropertyNotWritable message into JSON for the specified
+ * property
+ *
+ * See header file for more information
+ * @endinternal
+ */
+void propertyNotWritable(crow::Response& res, const std::string& arg1,
+ const std::string& property)
+{
+ res.result(boost::beast::http::status::forbidden);
+ addMessageToJson(
+ res.jsonValue,
+ nlohmann::json{
+ {"@odata.type", "/redfish/v1/$metadata#Message.v1_0_0.Message"},
+ {"MessageId", "Base.1.2.0.PropertyNotWritable"},
+ {"Message",
+ "The property " + arg1 +
+ " is a read only property and cannot be assigned a value."},
+ {"Severity", "Warning"},
+ {"Resolution",
+ "Remove the property from the request body and resubmit "
+ "the request if "
+ "the operation failed."}},
+ property);
}
/**
@@ -632,19 +855,22 @@ nlohmann::json propertyNotWritable(const std::string& arg1)
* See header file for more information
* @endinternal
*/
-nlohmann::json queryParameterValueTypeError(const std::string& arg1,
- const std::string& arg2)
+void queryParameterValueTypeError(crow::Response& res, const std::string& arg1,
+ const std::string& arg2)
{
- return nlohmann::json{
- {"@odata.type", "/redfish/v1/$metadata#Message.v1_0_0.Message"},
- {"MessageId", "Base.1.2.0.QueryParameterValueTypeError"},
- {"Message",
- "The value " + arg1 + " for the query parameter " + arg2 +
- " is of a different type than the parameter can accept."},
- {"Severity", "Warning"},
- {"Resolution", "Correct the value for the query parameter in the "
- "request and resubmit "
- "the request if the operation failed."}};
+ res.result(boost::beast::http::status::bad_request);
+ addMessageToErrorJson(
+ res.jsonValue,
+ nlohmann::json{
+ {"@odata.type", "/redfish/v1/$metadata#Message.v1_0_0.Message"},
+ {"MessageId", "Base.1.2.0.QueryParameterValueTypeError"},
+ {"Message",
+ "The value " + arg1 + " for the query parameter " + arg2 +
+ " is of a different type than the parameter can accept."},
+ {"Severity", "Warning"},
+ {"Resolution", "Correct the value for the query parameter in the "
+ "request and resubmit "
+ "the request if the operation failed."}});
}
/**
@@ -654,18 +880,21 @@ nlohmann::json queryParameterValueTypeError(const std::string& arg1,
* See header file for more information
* @endinternal
*/
-nlohmann::json serviceShuttingDown()
+void serviceShuttingDown(crow::Response& res)
{
- return nlohmann::json{
- {"@odata.type", "/redfish/v1/$metadata#Message.v1_0_0.Message"},
- {"MessageId", "Base.1.2.0.ServiceShuttingDown"},
- {"Message",
- "The operation failed because the service is shutting down and can no "
- "longer take incoming requests."},
- {"Severity", "Critical"},
- {"Resolution",
- "When the service becomes available, resubmit the request if the "
- "operation failed."}};
+ res.result(boost::beast::http::status::service_unavailable);
+ addMessageToErrorJson(
+ res.jsonValue,
+ nlohmann::json{
+ {"@odata.type", "/redfish/v1/$metadata#Message.v1_0_0.Message"},
+ {"MessageId", "Base.1.2.0.ServiceShuttingDown"},
+ {"Message", "The operation failed because the service is shutting "
+ "down and can no "
+ "longer take incoming requests."},
+ {"Severity", "Critical"},
+ {"Resolution",
+ "When the service becomes available, resubmit the request if the "
+ "operation failed."}});
}
/**
@@ -675,20 +904,23 @@ nlohmann::json serviceShuttingDown()
* See header file for more information
* @endinternal
*/
-nlohmann::json actionParameterDuplicate(const std::string& arg1,
- const std::string& arg2)
-{
- return nlohmann::json{
- {"@odata.type", "/redfish/v1/$metadata#Message.v1_0_0.Message"},
- {"MessageId", "Base.1.2.0.ActionParameterDuplicate"},
- {"Message",
- "The action " + arg1 +
- " was submitted with more than one value for the parameter " +
- arg2 + "."},
- {"Severity", "Warning"},
- {"Resolution",
- "Resubmit the action with only one instance of the parameter in the "
- "request body if the operation failed."}};
+void actionParameterDuplicate(crow::Response& res, const std::string& arg1,
+ const std::string& arg2)
+{
+ res.result(boost::beast::http::status::bad_request);
+ addMessageToErrorJson(
+ res.jsonValue,
+ nlohmann::json{
+ {"@odata.type", "/redfish/v1/$metadata#Message.v1_0_0.Message"},
+ {"MessageId", "Base.1.2.0.ActionParameterDuplicate"},
+ {"Message",
+ "The action " + arg1 +
+ " was submitted with more than one value for the parameter " +
+ arg2 + "."},
+ {"Severity", "Warning"},
+ {"Resolution", "Resubmit the action with only one instance of the "
+ "parameter in the "
+ "request body if the operation failed."}});
}
/**
@@ -698,18 +930,21 @@ nlohmann::json actionParameterDuplicate(const std::string& arg1,
* See header file for more information
* @endinternal
*/
-nlohmann::json actionParameterNotSupported(const std::string& arg1,
- const std::string& arg2)
+void actionParameterNotSupported(crow::Response& res, const std::string& arg1,
+ const std::string& arg2)
{
- return nlohmann::json{
- {"@odata.type", "/redfish/v1/$metadata#Message.v1_0_0.Message"},
- {"MessageId", "Base.1.2.0.ActionParameterNotSupported"},
- {"Message", "The parameter " + arg1 + " for the action " + arg2 +
- " is not supported on the target resource."},
- {"Severity", "Warning"},
- {"Resolution",
- "Remove the parameter supplied and resubmit the request if the "
- "operation failed."}};
+ res.result(boost::beast::http::status::bad_request);
+ addMessageToErrorJson(
+ res.jsonValue,
+ nlohmann::json{
+ {"@odata.type", "/redfish/v1/$metadata#Message.v1_0_0.Message"},
+ {"MessageId", "Base.1.2.0.ActionParameterNotSupported"},
+ {"Message", "The parameter " + arg1 + " for the action " + arg2 +
+ " is not supported on the target resource."},
+ {"Severity", "Warning"},
+ {"Resolution",
+ "Remove the parameter supplied and resubmit the request if the "
+ "operation failed."}});
}
/**
@@ -719,17 +954,20 @@ nlohmann::json actionParameterNotSupported(const std::string& arg1,
* See header file for more information
* @endinternal
*/
-nlohmann::json sourceDoesNotSupportProtocol(const std::string& arg1,
- const std::string& arg2)
+void sourceDoesNotSupportProtocol(crow::Response& res, const std::string& arg1,
+ const std::string& arg2)
{
- return nlohmann::json{
- {"@odata.type", "/redfish/v1/$metadata#Message.v1_0_0.Message"},
- {"MessageId", "Base.1.2.0.SourceDoesNotSupportProtocol"},
- {"Message", "The other end of the Connection at " + arg1 +
- " does not support the specified protocol " + arg2 +
- "."},
- {"Severity", "Critical"},
- {"Resolution", "Change protocols or URIs. "}};
+ res.result(boost::beast::http::status::bad_request);
+ addMessageToErrorJson(
+ res.jsonValue,
+ nlohmann::json{
+ {"@odata.type", "/redfish/v1/$metadata#Message.v1_0_0.Message"},
+ {"MessageId", "Base.1.2.0.SourceDoesNotSupportProtocol"},
+ {"Message", "The other end of the Connection at " + arg1 +
+ " does not support the specified protocol " + arg2 +
+ "."},
+ {"Severity", "Critical"},
+ {"Resolution", "Change protocols or URIs. "}});
}
/**
@@ -739,14 +977,17 @@ nlohmann::json sourceDoesNotSupportProtocol(const std::string& arg1,
* See header file for more information
* @endinternal
*/
-nlohmann::json accountRemoved()
+void accountRemoved(crow::Response& res)
{
- return nlohmann::json{
- {"@odata.type", "/redfish/v1/$metadata#Message.v1_0_0.Message"},
- {"MessageId", "Base.1.2.0.AccountRemoved"},
- {"Message", "The account was successfully removed."},
- {"Severity", "OK"},
- {"Resolution", "No resolution is required."}};
+ res.result(boost::beast::http::status::ok);
+ addMessageToJsonRoot(
+ res.jsonValue,
+ nlohmann::json{
+ {"@odata.type", "/redfish/v1/$metadata#Message.v1_0_0.Message"},
+ {"MessageId", "Base.1.2.0.AccountRemoved"},
+ {"Message", "The account was successfully removed."},
+ {"Severity", "OK"},
+ {"Resolution", "No resolution is required."}});
}
/**
@@ -756,17 +997,21 @@ nlohmann::json accountRemoved()
* See header file for more information
* @endinternal
*/
-nlohmann::json accessDenied(const std::string& arg1)
+void accessDenied(crow::Response& res, const std::string& arg1)
{
- return nlohmann::json{
- {"@odata.type", "/redfish/v1/$metadata#Message.v1_0_0.Message"},
- {"MessageId", "Base.1.2.0.AccessDenied"},
- {"Message", "While attempting to establish a Connection to " + arg1 +
- ", the service denied access."},
- {"Severity", "Critical"},
- {"Resolution", "Attempt to ensure that the URI is correct and that the "
- "service has the "
- "appropriate credentials."}};
+ res.result(boost::beast::http::status::forbidden);
+ addMessageToErrorJson(
+ res.jsonValue,
+ nlohmann::json{
+ {"@odata.type", "/redfish/v1/$metadata#Message.v1_0_0.Message"},
+ {"MessageId", "Base.1.2.0.AccessDenied"},
+ {"Message", "While attempting to establish a Connection to " +
+ arg1 + ", the service denied access."},
+ {"Severity", "Critical"},
+ {"Resolution",
+ "Attempt to ensure that the URI is correct and that the "
+ "service has the "
+ "appropriate credentials."}});
}
/**
@@ -776,16 +1021,20 @@ nlohmann::json accessDenied(const std::string& arg1)
* See header file for more information
* @endinternal
*/
-nlohmann::json queryNotSupported()
+void queryNotSupported(crow::Response& res)
{
- return nlohmann::json{
- {"@odata.type", "/redfish/v1/$metadata#Message.v1_0_0.Message"},
- {"MessageId", "Base.1.2.0.QueryNotSupported"},
- {"Message", "Querying is not supported by the implementation."},
- {"Severity", "Warning"},
- {"Resolution", "Remove the query parameters and resubmit the request "
- "if the operation "
- "failed."}};
+ res.result(boost::beast::http::status::bad_request);
+ addMessageToErrorJson(
+ res.jsonValue,
+ nlohmann::json{
+ {"@odata.type", "/redfish/v1/$metadata#Message.v1_0_0.Message"},
+ {"MessageId", "Base.1.2.0.QueryNotSupported"},
+ {"Message", "Querying is not supported by the implementation."},
+ {"Severity", "Warning"},
+ {"Resolution",
+ "Remove the query parameters and resubmit the request "
+ "if the operation "
+ "failed."}});
}
/**
@@ -795,18 +1044,21 @@ nlohmann::json queryNotSupported()
* See header file for more information
* @endinternal
*/
-nlohmann::json createLimitReachedForResource()
+void createLimitReachedForResource(crow::Response& res)
{
- return nlohmann::json{
- {"@odata.type", "/redfish/v1/$metadata#Message.v1_0_0.Message"},
- {"MessageId", "Base.1.2.0.CreateLimitReachedForResource"},
- {"Message", "The create operation failed because the resource has "
- "reached the limit "
- "of possible resources."},
- {"Severity", "Critical"},
- {"Resolution",
- "Either delete resources and resubmit the request if the operation "
- "failed or do not resubmit the request."}};
+ res.result(boost::beast::http::status::bad_request);
+ addMessageToErrorJson(
+ res.jsonValue,
+ nlohmann::json{
+ {"@odata.type", "/redfish/v1/$metadata#Message.v1_0_0.Message"},
+ {"MessageId", "Base.1.2.0.CreateLimitReachedForResource"},
+ {"Message", "The create operation failed because the resource has "
+ "reached the limit "
+ "of possible resources."},
+ {"Severity", "Critical"},
+ {"Resolution", "Either delete resources and resubmit the request "
+ "if the operation "
+ "failed or do not resubmit the request."}});
}
/**
@@ -816,15 +1068,19 @@ nlohmann::json createLimitReachedForResource()
* See header file for more information
* @endinternal
*/
-nlohmann::json generalError()
+void generalError(crow::Response& res)
{
- return nlohmann::json{
- {"@odata.type", "/redfish/v1/$metadata#Message.v1_0_0.Message"},
- {"MessageId", "Base.1.2.0.GeneralError"},
- {"Message", "A general error has occurred. See ExtendedInfo for more "
- "information."},
- {"Severity", "Critical"},
- {"Resolution", "See ExtendedInfo for more information."}};
+ res.result(boost::beast::http::status::internal_server_error);
+ addMessageToErrorJson(
+ res.jsonValue,
+ nlohmann::json{
+ {"@odata.type", "/redfish/v1/$metadata#Message.v1_0_0.Message"},
+ {"MessageId", "Base.1.2.0.GeneralError"},
+ {"Message",
+ "A general error has occurred. See ExtendedInfo for more "
+ "information."},
+ {"Severity", "Critical"},
+ {"Resolution", "See ExtendedInfo for more information."}});
}
/**
@@ -834,14 +1090,38 @@ nlohmann::json generalError()
* See header file for more information
* @endinternal
*/
-nlohmann::json success()
+void success(crow::Response& res)
{
- return nlohmann::json{
- {"@odata.type", "/redfish/v1/$metadata#Message.v1_0_0.Message"},
- {"MessageId", "Base.1.2.0.Success"},
- {"Message", "Successfully Completed Request"},
- {"Severity", "OK"},
- {"Resolution", "None"}};
+ res.result(boost::beast::http::status::ok);
+ addMessageToJsonRoot(
+ res.jsonValue,
+ nlohmann::json{
+ {"@odata.type", "/redfish/v1/$metadata#Message.v1_0_0.Message"},
+ {"MessageId", "Base.1.2.0.Success"},
+ {"Message", "Successfully Completed Request"},
+ {"Severity", "OK"},
+ {"Resolution", "None"}});
+}
+
+/**
+ * @internal
+ * @brief Formats Success message into JSON for the specified field
+ *
+ * See header file for more information
+ * @endinternal
+ */
+void success(crow::Response& res, const std::string& fieldPath)
+{
+ res.result(boost::beast::http::status::ok);
+ addMessageToJson(
+ res.jsonValue,
+ nlohmann::json{
+ {"@odata.type", "/redfish/v1/$metadata#Message.v1_0_0.Message"},
+ {"MessageId", "Base.1.2.0.Success"},
+ {"Message", "Successfully Completed Request"},
+ {"Severity", "OK"},
+ {"Resolution", "None"}},
+ fieldPath);
}
/**
@@ -851,14 +1131,17 @@ nlohmann::json success()
* See header file for more information
* @endinternal
*/
-nlohmann::json created()
+void created(crow::Response& res)
{
- return nlohmann::json{
- {"@odata.type", "/redfish/v1/$metadata#Message.v1_0_0.Message"},
- {"MessageId", "Base.1.2.0.Created"},
- {"Message", "The resource has been created successfully"},
- {"Severity", "OK"},
- {"Resolution", "None"}};
+ res.result(boost::beast::http::status::created);
+ addMessageToJsonRoot(
+ res.jsonValue,
+ nlohmann::json{
+ {"@odata.type", "/redfish/v1/$metadata#Message.v1_0_0.Message"},
+ {"MessageId", "Base.1.2.0.Created"},
+ {"Message", "The resource has been created successfully"},
+ {"Severity", "OK"},
+ {"Resolution", "None"}});
}
/**
@@ -868,18 +1151,47 @@ nlohmann::json created()
* See header file for more information
* @endinternal
*/
-nlohmann::json propertyUnknown(const std::string& arg1)
+void propertyUnknown(crow::Response& res, const std::string& arg1)
{
- return nlohmann::json{
- {"@odata.type", "/redfish/v1/$metadata#Message.v1_0_0.Message"},
- {"MessageId", "Base.1.2.0.PropertyUnknown"},
- {"Message",
- "The property " + arg1 +
- " is not in the list of valid properties for the resource."},
- {"Severity", "Warning"},
- {"Resolution",
- "Remove the unknown property from the request body and resubmit the "
- "request if the operation failed."}};
+ res.result(boost::beast::http::status::bad_request);
+ addMessageToErrorJson(
+ res.jsonValue,
+ nlohmann::json{
+ {"@odata.type", "/redfish/v1/$metadata#Message.v1_0_0.Message"},
+ {"MessageId", "Base.1.2.0.PropertyUnknown"},
+ {"Message",
+ "The property " + arg1 +
+ " is not in the list of valid properties for the resource."},
+ {"Severity", "Warning"},
+ {"Resolution", "Remove the unknown property from the request body "
+ "and resubmit the "
+ "request if the operation failed."}});
+}
+
+/**
+ * @internal
+ * @brief Formats PropertyUnknown message into JSON for the specified property
+ *
+ * See header file for more information
+ * @endinternal
+ */
+void propertyUnknown(crow::Response& res, const std::string& arg1,
+ const std::string& property)
+{
+ res.result(boost::beast::http::status::bad_request);
+ addMessageToJson(
+ res.jsonValue,
+ nlohmann::json{
+ {"@odata.type", "/redfish/v1/$metadata#Message.v1_0_0.Message"},
+ {"MessageId", "Base.1.2.0.PropertyUnknown"},
+ {"Message",
+ "The property " + arg1 +
+ " is not in the list of valid properties for the resource."},
+ {"Severity", "Warning"},
+ {"Resolution", "Remove the unknown property from the request body "
+ "and resubmit the "
+ "request if the operation failed."}},
+ property);
}
/**
@@ -889,16 +1201,19 @@ nlohmann::json propertyUnknown(const std::string& arg1)
* See header file for more information
* @endinternal
*/
-nlohmann::json noValidSession()
+void noValidSession(crow::Response& res)
{
- return nlohmann::json{
- {"@odata.type", "/redfish/v1/$metadata#Message.v1_0_0.Message"},
- {"MessageId", "Base.1.2.0.NoValidSession"},
- {"Message",
- "There is no valid session established with the implementation."},
- {"Severity", "Critical"},
- {"Resolution",
- "Establish as session before attempting any operations."}};
+ res.result(boost::beast::http::status::forbidden);
+ addMessageToErrorJson(
+ res.jsonValue,
+ nlohmann::json{
+ {"@odata.type", "/redfish/v1/$metadata#Message.v1_0_0.Message"},
+ {"MessageId", "Base.1.2.0.NoValidSession"},
+ {"Message",
+ "There is no valid session established with the implementation."},
+ {"Severity", "Critical"},
+ {"Resolution",
+ "Establish as session before attempting any operations."}});
}
/**
@@ -908,16 +1223,20 @@ nlohmann::json noValidSession()
* See header file for more information
* @endinternal
*/
-nlohmann::json invalidObject(const std::string& arg1)
+void invalidObject(crow::Response& res, const std::string& arg1)
{
- return nlohmann::json{
- {"@odata.type", "/redfish/v1/$metadata#Message.v1_0_0.Message"},
- {"MessageId", "Base.1.2.0.InvalidObject"},
- {"Message", "The object at " + arg1 + " is invalid."},
- {"Severity", "Critical"},
- {"Resolution", "Either the object is malformed or the URI is not "
- "correct. Correct the "
- "condition and resubmit the request if it failed."}};
+ res.result(boost::beast::http::status::bad_request);
+ addMessageToErrorJson(
+ res.jsonValue,
+ nlohmann::json{
+ {"@odata.type", "/redfish/v1/$metadata#Message.v1_0_0.Message"},
+ {"MessageId", "Base.1.2.0.InvalidObject"},
+ {"Message", "The object at " + arg1 + " is invalid."},
+ {"Severity", "Critical"},
+ {"Resolution",
+ "Either the object is malformed or the URI is not "
+ "correct. Correct the "
+ "condition and resubmit the request if it failed."}});
}
/**
@@ -927,18 +1246,21 @@ nlohmann::json invalidObject(const std::string& arg1)
* See header file for more information
* @endinternal
*/
-nlohmann::json resourceInStandby()
+void resourceInStandby(crow::Response& res)
{
- return nlohmann::json{
- {"@odata.type", "/redfish/v1/$metadata#Message.v1_0_0.Message"},
- {"MessageId", "Base.1.2.0.ResourceInStandby"},
- {"Message",
- "The request could not be performed because the resource is in "
- "standby."},
- {"Severity", "Critical"},
- {"Resolution",
- "Ensure that the resource is in the correct power state and resubmit "
- "the request."}};
+ res.result(boost::beast::http::status::service_unavailable);
+ addMessageToErrorJson(
+ res.jsonValue,
+ nlohmann::json{
+ {"@odata.type", "/redfish/v1/$metadata#Message.v1_0_0.Message"},
+ {"MessageId", "Base.1.2.0.ResourceInStandby"},
+ {"Message",
+ "The request could not be performed because the resource is in "
+ "standby."},
+ {"Severity", "Critical"},
+ {"Resolution", "Ensure that the resource is in the correct power "
+ "state and resubmit "
+ "the request."}});
}
/**
@@ -948,21 +1270,24 @@ nlohmann::json resourceInStandby()
* See header file for more information
* @endinternal
*/
-nlohmann::json actionParameterValueTypeError(const std::string& arg1,
- const std::string& arg2,
- const std::string& arg3)
-{
- return nlohmann::json{
- {"@odata.type", "/redfish/v1/$metadata#Message.v1_0_0.Message"},
- {"MessageId", "Base.1.2.0.ActionParameterValueTypeError"},
- {"Message",
- "The value " + arg1 + " for the parameter " + arg2 +
- " in the action " + arg3 +
- " is of a different type than the parameter can accept."},
- {"Severity", "Warning"},
- {"Resolution",
- "Correct the value for the parameter in the request body and resubmit "
- "the request if the operation failed."}};
+void actionParameterValueTypeError(crow::Response& res, const std::string& arg1,
+ const std::string& arg2,
+ const std::string& arg3)
+{
+ res.result(boost::beast::http::status::bad_request);
+ addMessageToErrorJson(
+ res.jsonValue,
+ nlohmann::json{
+ {"@odata.type", "/redfish/v1/$metadata#Message.v1_0_0.Message"},
+ {"MessageId", "Base.1.2.0.ActionParameterValueTypeError"},
+ {"Message",
+ "The value " + arg1 + " for the parameter " + arg2 +
+ " in the action " + arg3 +
+ " is of a different type than the parameter can accept."},
+ {"Severity", "Warning"},
+ {"Resolution", "Correct the value for the parameter in the request "
+ "body and resubmit "
+ "the request if the operation failed."}});
}
/**
@@ -972,19 +1297,23 @@ nlohmann::json actionParameterValueTypeError(const std::string& arg1,
* See header file for more information
* @endinternal
*/
-nlohmann::json sessionLimitExceeded()
+void sessionLimitExceeded(crow::Response& res)
{
- return nlohmann::json{
- {"@odata.type", "/redfish/v1/$metadata#Message.v1_0_0.Message"},
- {"MessageId", "Base.1.2.0.SessionLimitExceeded"},
- {"Message",
- "The session establishment failed due to the number of simultaneous "
- "sessions exceeding the limit of the implementation."},
- {"Severity", "Critical"},
- {"Resolution",
- "Reduce the number of other sessions before trying to establish the "
- "session or increase the limit of simultaneous sessions (if "
- "supported)."}};
+ res.result(boost::beast::http::status::service_unavailable);
+ addMessageToErrorJson(
+ res.jsonValue,
+ nlohmann::json{
+ {"@odata.type", "/redfish/v1/$metadata#Message.v1_0_0.Message"},
+ {"MessageId", "Base.1.2.0.SessionLimitExceeded"},
+ {"Message", "The session establishment failed due to the number of "
+ "simultaneous "
+ "sessions exceeding the limit of the implementation."},
+ {"Severity", "Critical"},
+ {"Resolution",
+ "Reduce the number of other sessions before trying to establish "
+ "the "
+ "session or increase the limit of simultaneous sessions (if "
+ "supported)."}});
}
/**
@@ -994,18 +1323,23 @@ nlohmann::json sessionLimitExceeded()
* See header file for more information
* @endinternal
*/
-nlohmann::json actionNotSupported(const std::string& arg1)
+void actionNotSupported(crow::Response& res, const std::string& arg1)
{
- return nlohmann::json{
- {"@odata.type", "/redfish/v1/$metadata#Message.v1_0_0.Message"},
- {"MessageId", "Base.1.2.0.ActionNotSupported"},
- {"Message",
- "The action " + arg1 + " is not supported by the resource."},
- {"Severity", "Critical"},
- {"Resolution",
- "The action supplied cannot be resubmitted to the implementation. "
- "Perhaps the action was invalid, the wrong resource was the target or "
- "the implementation documentation may be of assistance."}};
+ res.result(boost::beast::http::status::bad_request);
+ addMessageToErrorJson(
+ res.jsonValue,
+ nlohmann::json{
+ {"@odata.type", "/redfish/v1/$metadata#Message.v1_0_0.Message"},
+ {"MessageId", "Base.1.2.0.ActionNotSupported"},
+ {"Message",
+ "The action " + arg1 + " is not supported by the resource."},
+ {"Severity", "Critical"},
+ {"Resolution",
+ "The action supplied cannot be resubmitted to the implementation. "
+ " "
+ "Perhaps the action was invalid, the wrong resource was the "
+ "target or "
+ "the implementation documentation may be of assistance."}});
}
/**
@@ -1015,16 +1349,19 @@ nlohmann::json actionNotSupported(const std::string& arg1)
* See header file for more information
* @endinternal
*/
-nlohmann::json invalidIndex(const int& arg1)
+void invalidIndex(crow::Response& res, const int& arg1)
{
- return nlohmann::json{
- {"@odata.type", "/redfish/v1/$metadata#Message.v1_0_0.Message"},
- {"MessageId", "Base.1.2.0.InvalidIndex"},
- {"Message", "The index " + std::to_string(arg1) +
- " is not a valid offset into the array."},
- {"Severity", "Warning"},
- {"Resolution",
- "Verify the index value provided is within the bounds of the array."}};
+ res.result(boost::beast::http::status::bad_request);
+ addMessageToErrorJson(
+ res.jsonValue,
+ nlohmann::json{
+ {"@odata.type", "/redfish/v1/$metadata#Message.v1_0_0.Message"},
+ {"MessageId", "Base.1.2.0.InvalidIndex"},
+ {"Message", "The index " + std::to_string(arg1) +
+ " is not a valid offset into the array."},
+ {"Severity", "Warning"},
+ {"Resolution", "Verify the index value provided is within the "
+ "bounds of the array."}});
}
/**
@@ -1034,17 +1371,20 @@ nlohmann::json invalidIndex(const int& arg1)
* See header file for more information
* @endinternal
*/
-nlohmann::json emptyJSON()
+void emptyJSON(crow::Response& res)
{
- return nlohmann::json{
- {"@odata.type", "/redfish/v1/$metadata#Message.v1_0_0.Message"},
- {"MessageId", "Base.1.2.0.EmptyJSON"},
- {"Message",
- "The request body submitted contained an empty JSON object and the "
- "service is unable to process it."},
- {"Severity", "Warning"},
- {"Resolution",
- "Add properties in the JSON object and resubmit the request."}};
+ res.result(boost::beast::http::status::bad_request);
+ addMessageToErrorJson(
+ res.jsonValue,
+ nlohmann::json{
+ {"@odata.type", "/redfish/v1/$metadata#Message.v1_0_0.Message"},
+ {"MessageId", "Base.1.2.0.EmptyJSON"},
+ {"Message", "The request body submitted contained an empty JSON "
+ "object and the "
+ "service is unable to process it."},
+ {"Severity", "Warning"},
+ {"Resolution",
+ "Add properties in the JSON object and resubmit the request."}});
}
/**
@@ -1054,16 +1394,20 @@ nlohmann::json emptyJSON()
* See header file for more information
* @endinternal
*/
-nlohmann::json queryNotSupportedOnResource()
+void queryNotSupportedOnResource(crow::Response& res)
{
- return nlohmann::json{
- {"@odata.type", "/redfish/v1/$metadata#Message.v1_0_0.Message"},
- {"MessageId", "Base.1.2.0.QueryNotSupportedOnResource"},
- {"Message", "Querying is not supported on the requested resource."},
- {"Severity", "Warning"},
- {"Resolution", "Remove the query parameters and resubmit the request "
- "if the operation "
- "failed."}};
+ res.result(boost::beast::http::status::forbidden);
+ addMessageToErrorJson(
+ res.jsonValue,
+ nlohmann::json{
+ {"@odata.type", "/redfish/v1/$metadata#Message.v1_0_0.Message"},
+ {"MessageId", "Base.1.2.0.QueryNotSupportedOnResource"},
+ {"Message", "Querying is not supported on the requested resource."},
+ {"Severity", "Warning"},
+ {"Resolution",
+ "Remove the query parameters and resubmit the request "
+ "if the operation "
+ "failed."}});
}
/**
@@ -1073,19 +1417,23 @@ nlohmann::json queryNotSupportedOnResource()
* See header file for more information
* @endinternal
*/
-nlohmann::json insufficientPrivilege()
+void insufficientPrivilege(crow::Response& res)
{
- return nlohmann::json{
- {"@odata.type", "/redfish/v1/$metadata#Message.v1_0_0.Message"},
- {"MessageId", "Base.1.2.0.InsufficientPrivilege"},
- {"Message",
- "There are insufficient privileges for the account or credentials "
- "associated with the current session to perform the requested "
- "operation."},
- {"Severity", "Critical"},
- {"Resolution",
- "Either abandon the operation or change the associated access rights "
- "and resubmit the request if the operation failed."}};
+ res.result(boost::beast::http::status::forbidden);
+ addMessageToErrorJson(
+ res.jsonValue,
+ nlohmann::json{
+ {"@odata.type", "/redfish/v1/$metadata#Message.v1_0_0.Message"},
+ {"MessageId", "Base.1.2.0.InsufficientPrivilege"},
+ {"Message",
+ "There are insufficient privileges for the account or credentials "
+ "associated with the current session to perform the requested "
+ "operation."},
+ {"Severity", "Critical"},
+ {"Resolution",
+ "Either abandon the operation or change the associated access "
+ "rights "
+ "and resubmit the request if the operation failed."}});
}
/**
@@ -1095,16 +1443,21 @@ nlohmann::json insufficientPrivilege()
* See header file for more information
* @endinternal
*/
-nlohmann::json propertyValueModified(const std::string& arg1,
- const std::string& arg2)
+void propertyValueModified(crow::Response& res, const std::string& arg1,
+ const std::string& arg2,
+ const std::string& fieldPath)
{
- return nlohmann::json{
- {"@odata.type", "/redfish/v1/$metadata#Message.v1_0_0.Message"},
- {"MessageId", "Base.1.2.0.PropertyValueModified"},
- {"Message", "The property " + arg1 + " was assigned the value " + arg2 +
- " due to modification by the service."},
- {"Severity", "Warning"},
- {"Resolution", "No resolution is required."}};
+ res.result(boost::beast::http::status::ok);
+ addMessageToJson(
+ res.jsonValue,
+ nlohmann::json{
+ {"@odata.type", "/redfish/v1/$metadata#Message.v1_0_0.Message"},
+ {"MessageId", "Base.1.2.0.PropertyValueModified"},
+ {"Message", "The property " + arg1 + " was assigned the value " +
+ arg2 + " due to modification by the service."},
+ {"Severity", "Warning"},
+ {"Resolution", "No resolution is required."}},
+ fieldPath);
}
/**
@@ -1114,16 +1467,19 @@ nlohmann::json propertyValueModified(const std::string& arg1,
* See header file for more information
* @endinternal
*/
-nlohmann::json accountNotModified()
+void accountNotModified(crow::Response& res)
{
- return nlohmann::json{
- {"@odata.type", "/redfish/v1/$metadata#Message.v1_0_0.Message"},
- {"MessageId", "Base.1.2.0.AccountNotModified"},
- {"Message", "The account modification request failed."},
- {"Severity", "Warning"},
- {"Resolution",
- "The modification may have failed due to permission issues or issues "
- "with the request body."}};
+ res.result(boost::beast::http::status::bad_request);
+ addMessageToErrorJson(
+ res.jsonValue,
+ nlohmann::json{
+ {"@odata.type", "/redfish/v1/$metadata#Message.v1_0_0.Message"},
+ {"MessageId", "Base.1.2.0.AccountNotModified"},
+ {"Message", "The account modification request failed."},
+ {"Severity", "Warning"},
+ {"Resolution", "The modification may have failed due to permission "
+ "issues or issues "
+ "with the request body."}});
}
/**
@@ -1133,19 +1489,23 @@ nlohmann::json accountNotModified()
* See header file for more information
* @endinternal
*/
-nlohmann::json queryParameterValueFormatError(const std::string& arg1,
- const std::string& arg2)
+void queryParameterValueFormatError(crow::Response& res,
+ const std::string& arg1,
+ const std::string& arg2)
{
- return nlohmann::json{
- {"@odata.type", "/redfish/v1/$metadata#Message.v1_0_0.Message"},
- {"MessageId", "Base.1.2.0.QueryParameterValueFormatError"},
- {"Message",
- "The value " + arg1 + " for the parameter " + arg2 +
- " is of a different format than the parameter can accept."},
- {"Severity", "Warning"},
- {"Resolution", "Correct the value for the query parameter in the "
- "request and resubmit "
- "the request if the operation failed."}};
+ res.result(boost::beast::http::status::bad_request);
+ addMessageToErrorJson(
+ res.jsonValue,
+ nlohmann::json{
+ {"@odata.type", "/redfish/v1/$metadata#Message.v1_0_0.Message"},
+ {"MessageId", "Base.1.2.0.QueryParameterValueFormatError"},
+ {"Message",
+ "The value " + arg1 + " for the parameter " + arg2 +
+ " is of a different format than the parameter can accept."},
+ {"Severity", "Warning"},
+ {"Resolution", "Correct the value for the query parameter in the "
+ "request and resubmit "
+ "the request if the operation failed."}});
}
/**
@@ -1155,18 +1515,49 @@ nlohmann::json queryParameterValueFormatError(const std::string& arg1,
* See header file for more information
* @endinternal
*/
-nlohmann::json propertyMissing(const std::string& arg1)
+void propertyMissing(crow::Response& res, const std::string& arg1)
+{
+ res.result(boost::beast::http::status::bad_request);
+ addMessageToErrorJson(
+ res.jsonValue,
+ nlohmann::json{
+ {"@odata.type", "/redfish/v1/$metadata#Message.v1_0_0.Message"},
+ {"MessageId", "Base.1.2.0.PropertyMissing"},
+ {"Message", "The property " + arg1 +
+ " is a required property and must be included in "
+ "the request."},
+ {"Severity", "Warning"},
+ {"Resolution",
+ "Ensure that the property is in the request body and "
+ "has a valid value "
+ "and resubmit the request if the operation failed."}});
+}
+
+/**
+ * @internal
+ * @brief Formats PropertyMissing message into JSON for the specified property
+ *
+ * See header file for more information
+ * @endinternal
+ */
+void propertyMissing(crow::Response& res, const std::string& arg1,
+ const std::string& property)
{
- return nlohmann::json{
- {"@odata.type", "/redfish/v1/$metadata#Message.v1_0_0.Message"},
- {"MessageId", "Base.1.2.0.PropertyMissing"},
- {"Message",
- "The property " + arg1 +
- " is a required property and must be included in the request."},
- {"Severity", "Warning"},
- {"Resolution", "Ensure that the property is in the request body and "
- "has a valid value "
- "and resubmit the request if the operation failed."}};
+ res.result(boost::beast::http::status::bad_request);
+ addMessageToJson(
+ res.jsonValue,
+ nlohmann::json{
+ {"@odata.type", "/redfish/v1/$metadata#Message.v1_0_0.Message"},
+ {"MessageId", "Base.1.2.0.PropertyMissing"},
+ {"Message", "The property " + arg1 +
+ " is a required property and must be included in "
+ "the request."},
+ {"Severity", "Warning"},
+ {"Resolution",
+ "Ensure that the property is in the request body and "
+ "has a valid value "
+ "and resubmit the request if the operation failed."}},
+ property);
}
/**
@@ -1176,18 +1567,21 @@ nlohmann::json propertyMissing(const std::string& arg1)
* See header file for more information
* @endinternal
*/
-nlohmann::json resourceExhaustion(const std::string& arg1)
+void resourceExhaustion(crow::Response& res, const std::string& arg1)
{
- return nlohmann::json{
- {"@odata.type", "/redfish/v1/$metadata#Message.v1_0_0.Message"},
- {"MessageId", "Base.1.2.0.ResourceExhaustion"},
- {"Message", "The resource " + arg1 +
- " was unable to satisfy the request "
- "due to unavailability of "
- "resources."},
- {"Severity", "Critical"},
- {"Resolution",
- "Ensure that the resources are available and resubmit the request."}};
+ res.result(boost::beast::http::status::service_unavailable);
+ addMessageToErrorJson(
+ res.jsonValue,
+ nlohmann::json{
+ {"@odata.type", "/redfish/v1/$metadata#Message.v1_0_0.Message"},
+ {"MessageId", "Base.1.2.0.ResourceExhaustion"},
+ {"Message", "The resource " + arg1 +
+ " was unable to satisfy the request "
+ "due to unavailability of "
+ "resources."},
+ {"Severity", "Critical"},
+ {"Resolution", "Ensure that the resources are available and "
+ "resubmit the request."}});
}
/**
@@ -1197,14 +1591,18 @@ nlohmann::json resourceExhaustion(const std::string& arg1)
* See header file for more information
* @endinternal
*/
-nlohmann::json accountModified()
+void accountModified(crow::Response& res, const std::string& fieldPath)
{
- return nlohmann::json{
- {"@odata.type", "/redfish/v1/$metadata#Message.v1_0_0.Message"},
- {"MessageId", "Base.1.2.0.AccountModified"},
- {"Message", "The account was successfully modified."},
- {"Severity", "OK"},
- {"Resolution", "No resolution is required."}};
+ res.result(boost::beast::http::status::ok);
+ addMessageToJson(
+ res.jsonValue,
+ nlohmann::json{
+ {"@odata.type", "/redfish/v1/$metadata#Message.v1_0_0.Message"},
+ {"MessageId", "Base.1.2.0.AccountModified"},
+ {"Message", "The account was successfully modified."},
+ {"Severity", "OK"},
+ {"Resolution", "No resolution is required."}},
+ fieldPath);
}
/**
@@ -1214,27 +1612,27 @@ nlohmann::json accountModified()
* See header file for more information
* @endinternal
*/
-nlohmann::json queryParameterOutOfRange(const std::string& arg1,
- const std::string& arg2,
- const std::string& arg3)
-{
- return nlohmann::json{
- {"@odata.type", "/redfish/v1/$metadata#Message.v1_0_0.Message"},
- {"MessageId", "Base.1.2.0.QueryParameterOutOfRange"},
- {"Message", "The value " + arg1 + " for the query parameter " + arg2 +
- " is out of range " + arg3 + "."},
- {"Severity", "Warning"},
- {"Resolution",
- "Reduce the value for the query parameter to a value that is within "
- "range, such as a start or count value that is within bounds of the "
- "number of resources in a collection or a page that is within the "
- "range "
- "of valid pages."}};
-}
-
-/*********************************
- * AUTOGENERATED FUNCTIONS END *
- *********************************/
+void queryParameterOutOfRange(crow::Response& res, const std::string& arg1,
+ const std::string& arg2, const std::string& arg3)
+{
+ res.result(boost::beast::http::status::bad_request);
+ addMessageToErrorJson(
+ res.jsonValue,
+ nlohmann::json{
+ {"@odata.type", "/redfish/v1/$metadata#Message.v1_0_0.Message"},
+ {"MessageId", "Base.1.2.0.QueryParameterOutOfRange"},
+ {"Message", "The value " + arg1 + " for the query parameter " +
+ arg2 + " is out of range " + arg3 + "."},
+ {"Severity", "Warning"},
+ {"Resolution",
+ "Reduce the value for the query parameter to a value that is "
+ "within "
+ "range, such as a start or count value that is within bounds of "
+ "the "
+ "number of resources in a collection or a page that is within the "
+ "range "
+ "of valid pages."}});
+}
} // namespace messages
diff --git a/redfish-core/src/utils/json_utils.cpp b/redfish-core/src/utils/json_utils.cpp
index e14131713a..a47b4d8217 100644
--- a/redfish-core/src/utils/json_utils.cpp
+++ b/redfish-core/src/utils/json_utils.cpp
@@ -21,484 +21,6 @@ namespace redfish
namespace json_util
{
-Result getString(const char* fieldName, const nlohmann::json& json,
- const std::string*& output)
-{
- // Find field
- auto fieldIt = json.find(fieldName);
-
- // Verify existence
- if (fieldIt == json.end())
- {
- return Result::NOT_EXIST;
- }
-
- output = fieldIt->get_ptr<const std::string*>();
-
- // Verify type - we know that it exists, so nullptr means wrong type
- if (output == nullptr)
- {
- return Result::WRONG_TYPE;
- }
-
- return Result::SUCCESS;
-}
-
-Result getObject(const char* fieldName, const nlohmann::json& json,
- nlohmann::json* output)
-{
- // Verify input pointer
- if (output == nullptr)
- {
- return Result::NULL_POINTER;
- }
-
- // Find field
- auto fieldIt = json.find(fieldName);
-
- // Verify existence
- if (fieldIt == json.end())
- {
- return Result::NOT_EXIST;
- }
-
- // Verify type
- if (!fieldIt->is_object())
- {
- return Result::WRONG_TYPE;
- }
-
- // Extract value
- *output = *fieldIt;
-
- return Result::SUCCESS;
-}
-
-Result getArray(const char* fieldName, const nlohmann::json& json,
- nlohmann::json* output)
-{
- // Verify input pointer
- if (output == nullptr)
- {
- return Result::NULL_POINTER;
- }
-
- // Find field
- auto fieldIt = json.find(fieldName);
-
- // Verify existence
- if (fieldIt == json.end())
- {
- return Result::NOT_EXIST;
- }
-
- // Verify type
- if (!fieldIt->is_array())
- {
- return Result::WRONG_TYPE;
- }
-
- // Extract value
- *output = *fieldIt;
-
- return Result::SUCCESS;
-}
-
-Result getInt(const char* fieldName, const nlohmann::json& json,
- int64_t& output)
-{
- // Find field
- auto fieldIt = json.find(fieldName);
-
- // Verify existence
- if (fieldIt == json.end())
- {
- return Result::NOT_EXIST;
- }
-
- const int64_t* retVal = fieldIt->get_ptr<const int64_t*>();
-
- // Verify type - we know that it exists, so nullptr means wrong type
- if (retVal == nullptr)
- {
- return Result::WRONG_TYPE;
- }
-
- // Extract value
- output = *retVal;
-
- return Result::SUCCESS;
-}
-
-Result getUnsigned(const char* fieldName, const nlohmann::json& json,
- uint64_t& output)
-{
- // Find field
- auto fieldIt = json.find(fieldName);
-
- // Verify existence
- if (fieldIt == json.end())
- {
- return Result::NOT_EXIST;
- }
-
- const uint64_t* retVal = fieldIt->get_ptr<const uint64_t*>();
-
- // Verify type - we know that it exists, so nullptr means wrong type
- if (retVal == nullptr)
- {
- return Result::WRONG_TYPE;
- }
-
- // Extract value
- output = *retVal;
-
- return Result::SUCCESS;
-}
-
-Result getBool(const char* fieldName, const nlohmann::json& json, bool& output)
-{
- // Find field
- auto fieldIt = json.find(fieldName);
-
- // Verify existence
- if (fieldIt == json.end())
- {
- return Result::NOT_EXIST;
- }
-
- const bool* retVal = fieldIt->get_ptr<const bool*>();
-
- // Verify type - we know that it exists, so nullptr means wrong type
- if (retVal == nullptr)
- {
- return Result::WRONG_TYPE;
- }
-
- // Extract value
- output = *retVal;
-
- return Result::SUCCESS;
-}
-
-Result getDouble(const char* fieldName, const nlohmann::json& json,
- double& output)
-{
- // Find field
- auto fieldIt = json.find(fieldName);
-
- // Verify existence
- if (fieldIt == json.end())
- {
- return Result::NOT_EXIST;
- }
-
- const double* retVal = fieldIt->get_ptr<const double*>();
-
- // Verify type - we know that it exists, so nullptr means wrong type
- if (retVal == nullptr)
- {
- return Result::WRONG_TYPE;
- }
-
- // Extract value
- output = *retVal;
-
- return Result::SUCCESS;
-}
-
-Result getString(const char* fieldName, const nlohmann::json& json,
- const std::string*& output, uint8_t msgCfgMap,
- nlohmann::json& msgJson, const std::string&& fieldPath)
-{
- // Find field
- auto fieldIt = json.find(fieldName);
-
- // Verify existence
- if (fieldIt == json.end())
- {
- if (msgCfgMap & static_cast<int>(MessageSetting::MISSING))
- {
- messages::addMessageToJson(
- msgJson, messages::propertyMissing(fieldName), fieldPath);
- }
-
- return Result::NOT_EXIST;
- }
-
- output = fieldIt->get_ptr<const std::string*>();
-
- // Verify type - we know that it exists, so nullptr means wrong type
- if (output == nullptr)
- {
- if (msgCfgMap & static_cast<int>(MessageSetting::TYPE_ERROR))
- {
- messages::addMessageToJson(
- msgJson,
- messages::propertyValueTypeError(fieldIt->dump(), fieldName),
- fieldPath);
- }
-
- return Result::WRONG_TYPE;
- }
-
- return Result::SUCCESS;
-}
-
-Result getObject(const char* fieldName, const nlohmann::json& json,
- nlohmann::json* output, uint8_t msgCfgMap,
- nlohmann::json& msgJson, const std::string&& fieldPath)
-{
- // Verify input pointer
- if (output == nullptr)
- {
- return Result::NULL_POINTER;
- }
-
- // Find field
- auto fieldIt = json.find(fieldName);
-
- // Verify existence
- if (fieldIt == json.end())
- {
- if (msgCfgMap & static_cast<int>(MessageSetting::MISSING))
- {
- messages::addMessageToJson(
- msgJson, messages::propertyMissing(fieldName), fieldPath);
- }
-
- return Result::NOT_EXIST;
- }
-
- // Verify type
- if (!fieldIt->is_object())
- {
- if (msgCfgMap & static_cast<int>(MessageSetting::TYPE_ERROR))
- {
- messages::addMessageToJson(
- msgJson,
- messages::propertyValueTypeError(fieldIt->dump(), fieldName),
- fieldPath);
- }
-
- return Result::WRONG_TYPE;
- }
-
- // Extract value
- *output = *fieldIt;
-
- return Result::SUCCESS;
-}
-
-Result getArray(const char* fieldName, const nlohmann::json& json,
- nlohmann::json* output, uint8_t msgCfgMap,
- nlohmann::json& msgJson, const std::string&& fieldPath)
-{
- // Verify input pointer
- if (output == nullptr)
- {
- return Result::NULL_POINTER;
- }
-
- // Find field
- auto fieldIt = json.find(fieldName);
-
- // Verify existence
- if (fieldIt == json.end())
- {
- if (msgCfgMap & static_cast<int>(MessageSetting::MISSING))
- {
- messages::addMessageToJson(
- msgJson, messages::propertyMissing(fieldName), fieldPath);
- }
-
- return Result::NOT_EXIST;
- }
-
- // Verify type
- if (!fieldIt->is_array())
- {
- if (msgCfgMap & static_cast<int>(MessageSetting::TYPE_ERROR))
- {
- messages::addMessageToJson(
- msgJson,
- messages::propertyValueTypeError(fieldIt->dump(), fieldName),
- fieldPath);
- }
-
- return Result::WRONG_TYPE;
- }
-
- // Extract value
- *output = *fieldIt;
-
- return Result::SUCCESS;
-}
-
-Result getInt(const char* fieldName, const nlohmann::json& json,
- int64_t& output, uint8_t msgCfgMap, nlohmann::json& msgJson,
- const std::string&& fieldPath)
-{
- // Find field
- auto fieldIt = json.find(fieldName);
-
- // Verify existence
- if (fieldIt == json.end())
- {
- if (msgCfgMap & static_cast<int>(MessageSetting::MISSING))
- {
- messages::addMessageToJson(
- msgJson, messages::propertyMissing(fieldName), fieldPath);
- }
-
- return Result::NOT_EXIST;
- }
-
- const int64_t* retVal = fieldIt->get_ptr<const int64_t*>();
-
- // Verify type - we know that it exists, so nullptr means wrong type
- if (retVal == nullptr)
- {
- if (msgCfgMap & static_cast<int>(MessageSetting::TYPE_ERROR))
- {
- messages::addMessageToJson(
- msgJson,
- messages::propertyValueTypeError(fieldIt->dump(), fieldName),
- fieldPath);
- }
-
- return Result::WRONG_TYPE;
- }
-
- // Extract value
- output = *retVal;
-
- return Result::SUCCESS;
-}
-
-Result getUnsigned(const char* fieldName, const nlohmann::json& json,
- uint64_t& output, uint8_t msgCfgMap, nlohmann::json& msgJson,
- const std::string&& fieldPath)
-{
- // Find field
- auto fieldIt = json.find(fieldName);
-
- // Verify existence
- if (fieldIt == json.end())
- {
- if (msgCfgMap & static_cast<int>(MessageSetting::MISSING))
- {
- messages::addMessageToJson(
- msgJson, messages::propertyMissing(fieldName), fieldPath);
- }
-
- return Result::NOT_EXIST;
- }
-
- const uint64_t* retVal = fieldIt->get_ptr<const uint64_t*>();
-
- // Verify type - we know that it exists, so nullptr means wrong type
- if (retVal == nullptr)
- {
- if (msgCfgMap & static_cast<int>(MessageSetting::TYPE_ERROR))
- {
- messages::addMessageToJson(
- msgJson,
- messages::propertyValueTypeError(fieldIt->dump(), fieldName),
- fieldPath);
- }
-
- return Result::WRONG_TYPE;
- }
-
- // Extract value
- output = *retVal;
-
- return Result::SUCCESS;
-}
-
-Result getBool(const char* fieldName, const nlohmann::json& json, bool& output,
- uint8_t msgCfgMap, nlohmann::json& msgJson,
- const std::string&& fieldPath)
-{
- // Find field
- auto fieldIt = json.find(fieldName);
-
- // Verify existence
- if (fieldIt == json.end())
- {
- if (msgCfgMap & static_cast<int>(MessageSetting::MISSING))
- {
- messages::addMessageToJson(
- msgJson, messages::propertyMissing(fieldName), fieldPath);
- }
-
- return Result::NOT_EXIST;
- }
-
- const bool* retVal = fieldIt->get_ptr<const bool*>();
-
- // Verify type - we know that it exists, so nullptr means wrong type
- if (retVal == nullptr)
- {
- if (msgCfgMap & static_cast<int>(MessageSetting::TYPE_ERROR))
- {
- messages::addMessageToJson(
- msgJson,
- messages::propertyValueTypeError(fieldIt->dump(), fieldName),
- fieldPath);
- }
-
- return Result::WRONG_TYPE;
- }
-
- // Extract value
- output = *retVal;
-
- return Result::SUCCESS;
-}
-
-Result getDouble(const char* fieldName, const nlohmann::json& json,
- double& output, uint8_t msgCfgMap, nlohmann::json& msgJson,
- const std::string&& fieldPath)
-{
- // Find field
- auto fieldIt = json.find(fieldName);
-
- // Verify existence
- if (fieldIt == json.end())
- {
- if (msgCfgMap & static_cast<int>(MessageSetting::MISSING))
- {
- messages::addMessageToJson(
- msgJson, messages::propertyMissing(fieldName), fieldPath);
- }
-
- return Result::NOT_EXIST;
- }
-
- const double* retVal = fieldIt->get_ptr<const double*>();
-
- // Verify type - we know that it exists, so nullptr means wrong type
- if (retVal == nullptr)
- {
- if (msgCfgMap & static_cast<int>(MessageSetting::TYPE_ERROR))
- {
- messages::addMessageToJson(
- msgJson,
- messages::propertyValueTypeError(fieldIt->dump(), fieldName),
- fieldPath);
- }
-
- return Result::WRONG_TYPE;
- }
-
- // Extract value
- output = *retVal;
-
- return Result::SUCCESS;
-}
-
bool processJsonFromRequest(crow::Response& res, const crow::Request& req,
nlohmann::json& reqJson)
{
@@ -506,10 +28,8 @@ bool processJsonFromRequest(crow::Response& res, const crow::Request& req,
if (reqJson.is_discarded())
{
- messages::addMessageToErrorJson(res.jsonValue,
- messages::malformedJSON());
+ messages::malformedJSON(res);
- res.result(boost::beast::http::status::bad_request);
res.end();
return false;