diff options
author | Ed Tanous <edtanous@google.com> | 2022-02-08 10:44:31 +0300 |
---|---|---|
committer | Ed Tanous <ed@tanous.net> | 2022-02-28 21:48:12 +0300 |
commit | 1668ce6d0d427088b7bb8ab7c2927763fb57c8c3 (patch) | |
tree | 97bcd7431ab3cb882edfe2378814c84d84d29526 /redfish-core/src/error_messages.cpp | |
parent | b6cd31e162b25779a68344d3c0bde7c6cfb1af7f (diff) | |
download | bmcweb-1668ce6d0d427088b7bb8ab7c2927763fb57c8c3.tar.xz |
Move error messages to string_view
using std::string_view on these lets us call them in more contexts, and
allows us to inline some previously more complex code. In general, for
APIs like this, std::string_view should be preferred as it gives more
flexibility in calling conventions.
Tested:
curl --insecure "https://localhost:18080/redfish/v1/AccountService/Roles/foobar" ✔
{
"error": {
"@Message.ExtendedInfo": [
{
"@odata.type": "#Message.v1_1_1.Message",
"Message": "The requested resource of type Role named 'foobar' was not found.",
"MessageArgs": [
"Role",
"foobar"
],
"MessageId": "Base.1.11.0.ResourceNotFound",
"MessageSeverity": "Critical",
"Resolution": "Provide a valid resource identifier and resubmit the request."
}
],
"code": "Base.1.11.0.ResourceNotFound",
"message": "The requested resource of type Role named 'foobar' was not found."
}
}
This is the same response as previously.
Signed-off-by: Ed Tanous <edtanous@google.com>
Change-Id: I8ee17120c42d2a13677648c3395aa4f9ec2bd51a
Diffstat (limited to 'redfish-core/src/error_messages.cpp')
-rw-r--r-- | redfish-core/src/error_messages.cpp | 394 |
1 files changed, 183 insertions, 211 deletions
diff --git a/redfish-core/src/error_messages.cpp b/redfish-core/src/error_messages.cpp index fafbf211d6..1897f2977b 100644 --- a/redfish-core/src/error_messages.cpp +++ b/redfish-core/src/error_messages.cpp @@ -22,6 +22,8 @@ #include <logging.hpp> #include <nlohmann/json.hpp> +#include <array> + namespace redfish { @@ -89,18 +91,20 @@ static void addMessageToJsonRoot(nlohmann::json& target, static void addMessageToJson(nlohmann::json& target, const nlohmann::json& message, - const std::string& fieldPath) + std::string_view fieldPath) { - std::string extendedInfo(fieldPath + messages::messageAnnotation); + std::string extendedInfo(fieldPath); + extendedInfo += messages::messageAnnotation; - if (!target[extendedInfo].is_array()) + nlohmann::json& field = target[extendedInfo]; + if (!field.is_array()) { // Force object to be an array - target[extendedInfo] = nlohmann::json::array(); + field = nlohmann::json::array(); } // Object exists and it is an array so we can just push in the message - target[extendedInfo].push_back(message); + field.push_back(message); } nlohmann::json getLog(redfish::message_registries::base::Index name, @@ -198,20 +202,18 @@ void resourceMissingAtURI(crow::Response& res, * See header file for more information * @endinternal */ -nlohmann::json actionParameterValueFormatError(const std::string& arg1, - const std::string& arg2, - const std::string& arg3) +nlohmann::json actionParameterValueFormatError(std::string_view arg1, + std::string_view arg2, + std::string_view arg3) { - std::array<std::string_view, 3> args{arg1, arg2, arg3}; return getLog(redfish::message_registries::base::Index:: actionParameterValueFormatError, - args); + std::to_array({arg1, arg2, arg3})); } -void actionParameterValueFormatError(crow::Response& res, - const std::string& arg1, - const std::string& arg2, - const std::string& arg3) +void actionParameterValueFormatError(crow::Response& res, std::string_view arg1, + std::string_view arg2, + std::string_view arg3) { res.result(boost::beast::http::status::bad_request); addMessageToErrorJson(res.jsonValue, @@ -266,18 +268,16 @@ void unrecognizedRequestBody(crow::Response& res) * @endinternal */ nlohmann::json resourceAtUriUnauthorized(const boost::urls::url_view& arg1, - const std::string& arg2) + std::string_view arg2) { - std::array<std::string_view, 2> args{ - std::string_view{arg1.data(), arg1.size()}, arg2}; return getLog( redfish::message_registries::base::Index::resourceAtUriUnauthorized, - args); + std::to_array({std::string_view{arg1.data(), arg1.size()}, arg2})); } void resourceAtUriUnauthorized(crow::Response& res, const boost::urls::url_view& arg1, - const std::string& arg2) + std::string_view arg2) { res.result(boost::beast::http::status::unauthorized); addMessageToErrorJson(res.jsonValue, resourceAtUriUnauthorized(arg1, arg2)); @@ -290,16 +290,16 @@ void resourceAtUriUnauthorized(crow::Response& res, * See header file for more information * @endinternal */ -nlohmann::json actionParameterUnknown(const std::string& arg1, - const std::string& arg2) +nlohmann::json actionParameterUnknown(std::string_view arg1, + std::string_view arg2) { - std::array<std::string_view, 3> args{arg1, arg2}; return getLog( - redfish::message_registries::base::Index::actionParameterUnknown, args); + redfish::message_registries::base::Index::actionParameterUnknown, + std::to_array({arg1, arg2})); } -void actionParameterUnknown(crow::Response& res, const std::string& arg1, - const std::string& arg2) +void actionParameterUnknown(crow::Response& res, std::string_view arg1, + std::string_view arg2) { res.result(boost::beast::http::status::bad_request); addMessageToErrorJson(res.jsonValue, actionParameterUnknown(arg1, arg2)); @@ -331,14 +331,13 @@ void resourceCannotBeDeleted(crow::Response& res) * See header file for more information * @endinternal */ -nlohmann::json propertyDuplicate(const std::string& arg1) +nlohmann::json propertyDuplicate(std::string_view arg1) { - std::array<std::string_view, 1> args{arg1}; return getLog(redfish::message_registries::base::Index::propertyDuplicate, - args); + std::to_array({arg1})); } -void propertyDuplicate(crow::Response& res, const std::string& arg1) +void propertyDuplicate(crow::Response& res, std::string_view arg1) { res.result(boost::beast::http::status::bad_request); addMessageToJson(res.jsonValue, propertyDuplicate(arg1), arg1); @@ -351,15 +350,14 @@ void propertyDuplicate(crow::Response& res, const std::string& arg1) * See header file for more information * @endinternal */ -nlohmann::json serviceTemporarilyUnavailable(const std::string& arg1) +nlohmann::json serviceTemporarilyUnavailable(std::string_view arg1) { - std::array<std::string_view, 1> args{arg1}; return getLog( redfish::message_registries::base::Index::serviceTemporarilyUnavailable, - args); + std::to_array({arg1})); } -void serviceTemporarilyUnavailable(crow::Response& res, const std::string& arg1) +void serviceTemporarilyUnavailable(crow::Response& res, std::string_view arg1) { res.addHeader("Retry-After", arg1); res.result(boost::beast::http::status::service_unavailable); @@ -373,17 +371,17 @@ void serviceTemporarilyUnavailable(crow::Response& res, 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) +nlohmann::json resourceAlreadyExists(std::string_view arg1, + std::string_view arg2, + std::string_view arg3) { - std::array<std::string_view, 3> args{arg1, arg2, arg3}; return getLog( - redfish::message_registries::base::Index::resourceAlreadyExists, args); + redfish::message_registries::base::Index::resourceAlreadyExists, + std::to_array({arg1, arg2, arg3})); } -void resourceAlreadyExists(crow::Response& res, const std::string& arg1, - const std::string& arg2, const std::string& arg3) +void resourceAlreadyExists(crow::Response& res, std::string_view arg1, + std::string_view arg2, std::string_view arg3) { res.result(boost::beast::http::status::bad_request); addMessageToJson(res.jsonValue, resourceAlreadyExists(arg1, arg2, arg3), @@ -417,16 +415,15 @@ void accountForSessionNoLongerExists(crow::Response& res) * See header file for more information * @endinternal */ -nlohmann::json createFailedMissingReqProperties(const std::string& arg1) +nlohmann::json createFailedMissingReqProperties(std::string_view arg1) { - std::array<std::string_view, 2> args{arg1}; return getLog(redfish::message_registries::base::Index:: createFailedMissingReqProperties, - args); + std::to_array({arg1})); } void createFailedMissingReqProperties(crow::Response& res, - const std::string& arg1) + std::string_view arg1) { res.result(boost::beast::http::status::bad_request); addMessageToJson(res.jsonValue, createFailedMissingReqProperties(arg1), @@ -441,17 +438,16 @@ void createFailedMissingReqProperties(crow::Response& res, * See header file for more information * @endinternal */ -nlohmann::json propertyValueFormatError(const std::string& arg1, - const std::string& arg2) +nlohmann::json propertyValueFormatError(std::string_view arg1, + std::string_view arg2) { - std::array<std::string_view, 2> args{arg1, arg2}; return getLog( redfish::message_registries::base::Index::propertyValueFormatError, - args); + std::to_array({arg1, arg2})); } -void propertyValueFormatError(crow::Response& res, const std::string& arg1, - const std::string& arg2) +void propertyValueFormatError(crow::Response& res, std::string_view arg1, + std::string_view arg2) { res.result(boost::beast::http::status::bad_request); addMessageToJson(res.jsonValue, propertyValueFormatError(arg1, arg2), arg2); @@ -465,16 +461,16 @@ void propertyValueFormatError(crow::Response& res, const std::string& arg1, * See header file for more information * @endinternal */ -nlohmann::json propertyValueNotInList(const std::string& arg1, - const std::string& arg2) +nlohmann::json propertyValueNotInList(std::string_view arg1, + std::string_view arg2) { - std::array<std::string_view, 2> args{arg1, arg2}; return getLog( - redfish::message_registries::base::Index::propertyValueNotInList, args); + redfish::message_registries::base::Index::propertyValueNotInList, + std::to_array({arg1, arg2})); } -void propertyValueNotInList(crow::Response& res, const std::string& arg1, - const std::string& arg2) +void propertyValueNotInList(crow::Response& res, std::string_view arg1, + std::string_view arg2) { res.result(boost::beast::http::status::bad_request); addMessageToJson(res.jsonValue, propertyValueNotInList(arg1, arg2), arg2); @@ -489,11 +485,10 @@ void propertyValueNotInList(crow::Response& res, const std::string& arg1, */ nlohmann::json resourceAtUriInUnknownFormat(const boost::urls::url_view& arg1) { - std::array<std::string_view, 1> args{ - std::string_view{arg1.data(), arg1.size()}}; + std::string_view arg1str{arg1.data(), arg1.size()}; return getLog( redfish::message_registries::base::Index::resourceAtUriInUnknownFormat, - args); + std::to_array({arg1str})); } void resourceAtUriInUnknownFormat(crow::Response& res, @@ -510,14 +505,13 @@ void resourceAtUriInUnknownFormat(crow::Response& res, * See header file for more information * @endinternal */ -nlohmann::json serviceDisabled(const std::string& arg1) +nlohmann::json serviceDisabled(std::string_view arg1) { - std::array<std::string_view, 1> args{arg1}; return getLog(redfish::message_registries::base::Index::serviceDisabled, - args); + std::to_array({arg1})); } -void serviceDisabled(crow::Response& res, const std::string& arg1) +void serviceDisabled(crow::Response& res, std::string_view arg1) { res.result(boost::beast::http::status::service_unavailable); addMessageToErrorJson(res.jsonValue, serviceDisabled(arg1)); @@ -569,16 +563,16 @@ void eventSubscriptionLimitExceeded(crow::Response& res) * See header file for more information * @endinternal */ -nlohmann::json actionParameterMissing(const std::string& arg1, - const std::string& arg2) +nlohmann::json actionParameterMissing(std::string_view arg1, + std::string_view arg2) { - std::array<std::string_view, 2> args{arg1, arg2}; return getLog( - redfish::message_registries::base::Index::actionParameterMissing, args); + redfish::message_registries::base::Index::actionParameterMissing, + std::to_array({arg1, arg2})); } -void actionParameterMissing(crow::Response& res, const std::string& arg1, - const std::string& arg2) +void actionParameterMissing(crow::Response& res, std::string_view arg1, + std::string_view arg2) { res.result(boost::beast::http::status::bad_request); addMessageToErrorJson(res.jsonValue, actionParameterMissing(arg1, arg2)); @@ -591,15 +585,14 @@ void actionParameterMissing(crow::Response& res, const std::string& arg1, * See header file for more information * @endinternal */ -nlohmann::json stringValueTooLong(const std::string& arg1, int arg2) +nlohmann::json stringValueTooLong(std::string_view arg1, int arg2) { std::string arg2String = std::to_string(arg2); - std::array<std::string_view, 2> args{arg1, arg2String}; return getLog(redfish::message_registries::base::Index::stringValueTooLong, - args); + std::to_array({arg1, std::string_view(arg2String)})); } -void stringValueTooLong(crow::Response& res, const std::string& arg1, int arg2) +void stringValueTooLong(crow::Response& res, std::string_view arg1, int arg2) { res.result(boost::beast::http::status::bad_request); addMessageToErrorJson(res.jsonValue, stringValueTooLong(arg1, arg2)); @@ -650,17 +643,16 @@ void subscriptionTerminated(crow::Response& res) * See header file for more information * @endinternal */ -nlohmann::json resourceTypeIncompatible(const std::string& arg1, - const std::string& arg2) +nlohmann::json resourceTypeIncompatible(std::string_view arg1, + std::string_view arg2) { - std::array<std::string_view, 2> args{arg1, arg2}; return getLog( redfish::message_registries::base::Index::resourceTypeIncompatible, - args); + std::to_array({arg1, arg2})); } -void resourceTypeIncompatible(crow::Response& res, const std::string& arg1, - const std::string& arg2) +void resourceTypeIncompatible(crow::Response& res, std::string_view arg1, + std::string_view arg2) { res.result(boost::beast::http::status::bad_request); addMessageToErrorJson(res.jsonValue, resourceTypeIncompatible(arg1, arg2)); @@ -674,16 +666,15 @@ void resourceTypeIncompatible(crow::Response& res, const std::string& arg1, * @endinternal */ nlohmann::json resetRequired(const boost::urls::url_view& arg1, - const std::string& arg2) + std::string_view arg2) { - std::array<std::string_view, 2> args{ - std::string_view(arg1.data(), arg1.size()), arg2}; + std::string_view arg1str(arg1.data(), arg1.size()); return getLog(redfish::message_registries::base::Index::resetRequired, - args); + std::to_array({arg1str, arg2})); } void resetRequired(crow::Response& res, const boost::urls::url_view& arg1, - const std::string& arg2) + std::string_view arg2) { res.result(boost::beast::http::status::bad_request); addMessageToErrorJson(res.jsonValue, resetRequired(arg1, arg2)); @@ -696,14 +687,13 @@ void resetRequired(crow::Response& res, const boost::urls::url_view& arg1, * See header file for more information * @endinternal */ -nlohmann::json chassisPowerStateOnRequired(const std::string& arg1) +nlohmann::json chassisPowerStateOnRequired(std::string_view arg1) { - std::array<std::string_view, 1> args{arg1}; return getLog(redfish::message_registries::base::Index::resetRequired, - args); + std::to_array({arg1})); } -void chassisPowerStateOnRequired(crow::Response& res, const std::string& arg1) +void chassisPowerStateOnRequired(crow::Response& res, std::string_view arg1) { res.result(boost::beast::http::status::bad_request); addMessageToErrorJson(res.jsonValue, chassisPowerStateOnRequired(arg1)); @@ -716,15 +706,14 @@ void chassisPowerStateOnRequired(crow::Response& res, const std::string& arg1) * See header file for more information * @endinternal */ -nlohmann::json chassisPowerStateOffRequired(const std::string& arg1) +nlohmann::json chassisPowerStateOffRequired(std::string_view arg1) { - std::array<std::string_view, 1> args{arg1}; return getLog( redfish::message_registries::base::Index::chassisPowerStateOffRequired, - args); + std::to_array({arg1})); } -void chassisPowerStateOffRequired(crow::Response& res, const std::string& arg1) +void chassisPowerStateOffRequired(crow::Response& res, std::string_view arg1) { res.result(boost::beast::http::status::bad_request); addMessageToErrorJson(res.jsonValue, chassisPowerStateOffRequired(arg1)); @@ -737,16 +726,16 @@ void chassisPowerStateOffRequired(crow::Response& res, const std::string& arg1) * See header file for more information * @endinternal */ -nlohmann::json propertyValueConflict(const std::string& arg1, - const std::string& arg2) +nlohmann::json propertyValueConflict(std::string_view arg1, + std::string_view arg2) { - std::array<std::string_view, 2> args{arg1, arg2}; return getLog( - redfish::message_registries::base::Index::propertyValueConflict, args); + redfish::message_registries::base::Index::propertyValueConflict, + std::to_array({arg1, arg2})); } -void propertyValueConflict(crow::Response& res, const std::string& arg1, - const std::string& arg2) +void propertyValueConflict(crow::Response& res, std::string_view arg1, + std::string_view arg2) { res.result(boost::beast::http::status::bad_request); addMessageToErrorJson(res.jsonValue, propertyValueConflict(arg1, arg2)); @@ -759,16 +748,16 @@ void propertyValueConflict(crow::Response& res, const std::string& arg1, * See header file for more information * @endinternal */ -nlohmann::json propertyValueIncorrect(const std::string& arg1, - const std::string& arg2) +nlohmann::json propertyValueIncorrect(std::string_view arg1, + std::string_view arg2) { - std::array<std::string_view, 2> args{arg1, arg2}; return getLog( - redfish::message_registries::base::Index::propertyValueIncorrect, args); + redfish::message_registries::base::Index::propertyValueIncorrect, + std::to_array({arg1, arg2})); } -void propertyValueIncorrect(crow::Response& res, const std::string& arg1, - const std::string& arg2) +void propertyValueIncorrect(crow::Response& res, std::string_view arg1, + std::string_view arg2) { res.result(boost::beast::http::status::bad_request); addMessageToErrorJson(res.jsonValue, propertyValueIncorrect(arg1, arg2)); @@ -783,12 +772,10 @@ void propertyValueIncorrect(crow::Response& res, const std::string& arg1, */ nlohmann::json resourceCreationConflict(const boost::urls::url_view& arg1) { - - std::array<std::string_view, 1> args{ - std::string_view(arg1.data(), arg1.size())}; + std::string_view arg1str(arg1.data(), arg1.size()); return getLog( redfish::message_registries::base::Index::resourceCreationConflict, - args); + std::to_array({arg1str})); } void resourceCreationConflict(crow::Response& res, @@ -901,16 +888,16 @@ void operationTimeout(crow::Response& res) * See header file for more information * @endinternal */ -nlohmann::json propertyValueTypeError(const std::string& arg1, - const std::string& arg2) +nlohmann::json propertyValueTypeError(std::string_view arg1, + std::string_view arg2) { - std::array<std::string_view, 2> args{arg1, arg2}; return getLog( - redfish::message_registries::base::Index::propertyValueTypeError, args); + redfish::message_registries::base::Index::propertyValueTypeError, + std::to_array({arg1, arg2})); } -void propertyValueTypeError(crow::Response& res, const std::string& arg1, - const std::string& arg2) +void propertyValueTypeError(crow::Response& res, std::string_view arg1, + std::string_view arg2) { res.result(boost::beast::http::status::bad_request); addMessageToJson(res.jsonValue, propertyValueTypeError(arg1, arg2), arg2); @@ -923,16 +910,14 @@ void propertyValueTypeError(crow::Response& res, const std::string& arg1, * See header file for more information * @endinternal */ -nlohmann::json resourceNotFound(const std::string& arg1, - const std::string& arg2) +nlohmann::json resourceNotFound(std::string_view arg1, std::string_view arg2) { - std::array<std::string_view, 2> args{arg1, arg2}; return getLog(redfish::message_registries::base::Index::resourceNotFound, - args); + std::to_array({arg1, arg2})); } -void resourceNotFound(crow::Response& res, const std::string& arg1, - const std::string& arg2) +void resourceNotFound(crow::Response& res, std::string_view arg1, + std::string_view arg2) { res.result(boost::beast::http::status::not_found); addMessageToErrorJson(res.jsonValue, resourceNotFound(arg1, arg2)); @@ -947,12 +932,10 @@ void resourceNotFound(crow::Response& res, const std::string& arg1, */ nlohmann::json couldNotEstablishConnection(const boost::urls::url_view& arg1) { - - std::array<std::string_view, 1> args{ - std::string_view(arg1.data(), arg1.size())}; + std::string_view arg1str(arg1.data(), arg1.size()); return getLog( redfish::message_registries::base::Index::couldNotEstablishConnection, - args); + std::to_array({arg1str})); } void couldNotEstablishConnection(crow::Response& res, @@ -970,14 +953,13 @@ void couldNotEstablishConnection(crow::Response& res, * See header file for more information * @endinternal */ -nlohmann::json propertyNotWritable(const std::string& arg1) +nlohmann::json propertyNotWritable(std::string_view arg1) { - std::array<std::string_view, 1> args{arg1}; return getLog(redfish::message_registries::base::Index::propertyNotWritable, - args); + std::to_array({arg1})); } -void propertyNotWritable(crow::Response& res, const std::string& arg1) +void propertyNotWritable(crow::Response& res, std::string_view arg1) { res.result(boost::beast::http::status::forbidden); addMessageToJson(res.jsonValue, propertyNotWritable(arg1), arg1); @@ -990,17 +972,16 @@ void propertyNotWritable(crow::Response& res, const std::string& arg1) * See header file for more information * @endinternal */ -nlohmann::json queryParameterValueTypeError(const std::string& arg1, - const std::string& arg2) +nlohmann::json queryParameterValueTypeError(std::string_view arg1, + std::string_view arg2) { - std::array<std::string_view, 2> args{arg1, arg2}; return getLog( redfish::message_registries::base::Index::queryParameterValueTypeError, - args); + std::to_array({arg1, arg2})); } -void queryParameterValueTypeError(crow::Response& res, const std::string& arg1, - const std::string& arg2) +void queryParameterValueTypeError(crow::Response& res, std::string_view arg1, + std::string_view arg2) { res.result(boost::beast::http::status::bad_request); addMessageToErrorJson(res.jsonValue, @@ -1033,17 +1014,16 @@ void serviceShuttingDown(crow::Response& res) * See header file for more information * @endinternal */ -nlohmann::json actionParameterDuplicate(const std::string& arg1, - const std::string& arg2) +nlohmann::json actionParameterDuplicate(std::string_view arg1, + std::string_view arg2) { - std::array<std::string_view, 2> args{arg1, arg2}; return getLog( redfish::message_registries::base::Index::actionParameterDuplicate, - args); + std::to_array({arg1, arg2})); } -void actionParameterDuplicate(crow::Response& res, const std::string& arg1, - const std::string& arg2) +void actionParameterDuplicate(crow::Response& res, std::string_view arg1, + std::string_view arg2) { res.result(boost::beast::http::status::bad_request); addMessageToErrorJson(res.jsonValue, actionParameterDuplicate(arg1, arg2)); @@ -1056,17 +1036,16 @@ void actionParameterDuplicate(crow::Response& res, const std::string& arg1, * See header file for more information * @endinternal */ -nlohmann::json actionParameterNotSupported(const std::string& arg1, - const std::string& arg2) +nlohmann::json actionParameterNotSupported(std::string_view arg1, + std::string_view arg2) { - std::array<std::string_view, 2> args{arg1, arg2}; return getLog( redfish::message_registries::base::Index::actionParameterNotSupported, - args); + std::to_array({arg1, arg2})); } -void actionParameterNotSupported(crow::Response& res, const std::string& arg1, - const std::string& arg2) +void actionParameterNotSupported(crow::Response& res, std::string_view arg1, + std::string_view arg2) { res.result(boost::beast::http::status::bad_request); addMessageToErrorJson(res.jsonValue, @@ -1081,18 +1060,17 @@ void actionParameterNotSupported(crow::Response& res, const std::string& arg1, * @endinternal */ nlohmann::json sourceDoesNotSupportProtocol(const boost::urls::url_view& arg1, - const std::string& arg2) + std::string_view arg2) { - std::array<std::string_view, 2> args{ - std::string_view(arg1.data(), arg1.size()), arg2}; + std::string_view arg1str(arg1.data(), arg1.size()); return getLog( redfish::message_registries::base::Index::sourceDoesNotSupportProtocol, - args); + std::to_array({arg1str, arg2})); } void sourceDoesNotSupportProtocol(crow::Response& res, const boost::urls::url_view& arg1, - const std::string& arg2) + std::string_view arg2) { res.result(boost::beast::http::status::bad_request); addMessageToErrorJson(res.jsonValue, @@ -1126,9 +1104,9 @@ void accountRemoved(crow::Response& res) */ nlohmann::json accessDenied(const boost::urls::url_view& arg1) { - std::array<std::string_view, 1> args{ - std::string_view(arg1.data(), arg1.size())}; - return getLog(redfish::message_registries::base::Index::accessDenied, args); + std::string_view arg1str(arg1.data(), arg1.size()); + return getLog(redfish::message_registries::base::Index::accessDenied, + std::to_array({arg1str})); } void accessDenied(crow::Response& res, const boost::urls::url_view& arg1) @@ -1257,14 +1235,13 @@ void noOperation(crow::Response& res) * See header file for more information * @endinternal */ -nlohmann::json propertyUnknown(const std::string& arg1) +nlohmann::json propertyUnknown(std::string_view arg1) { - std::array<std::string_view, 1> args{arg1}; return getLog(redfish::message_registries::base::Index::propertyUnknown, - args); + std::to_array({arg1})); } -void propertyUnknown(crow::Response& res, const std::string& arg1) +void propertyUnknown(crow::Response& res, std::string_view arg1) { res.result(boost::beast::http::status::bad_request); addMessageToJson(res.jsonValue, propertyUnknown(arg1), arg1); @@ -1297,10 +1274,9 @@ void noValidSession(crow::Response& res) */ nlohmann::json invalidObject(const boost::urls::url_view& arg1) { - std::array<std::string_view, 1> args{ - std::string_view(arg1.data(), arg1.size())}; + std::string_view arg1str(arg1.data(), arg1.size()); return getLog(redfish::message_registries::base::Index::invalidObject, - args); + std::to_array({arg1str})); } void invalidObject(crow::Response& res, const boost::urls::url_view& arg1) @@ -1335,19 +1311,17 @@ void resourceInStandby(crow::Response& res) * See header file for more information * @endinternal */ -nlohmann::json actionParameterValueTypeError(const std::string& arg1, - const std::string& arg2, - const std::string& arg3) +nlohmann::json actionParameterValueTypeError(std::string_view arg1, + std::string_view arg2, + std::string_view arg3) { - std::array<std::string_view, 3> args{arg1, arg2, arg3}; return getLog( redfish::message_registries::base::Index::actionParameterValueTypeError, - args); + std::to_array({arg1, arg2, arg3})); } -void actionParameterValueTypeError(crow::Response& res, const std::string& arg1, - const std::string& arg2, - const std::string& arg3) +void actionParameterValueTypeError(crow::Response& res, std::string_view arg1, + std::string_view arg2, std::string_view arg3) { res.result(boost::beast::http::status::bad_request); addMessageToErrorJson(res.jsonValue, @@ -1380,14 +1354,13 @@ void sessionLimitExceeded(crow::Response& res) * See header file for more information * @endinternal */ -nlohmann::json actionNotSupported(const std::string& arg1) +nlohmann::json actionNotSupported(std::string_view arg1) { - std::array<std::string_view, 1> args{arg1}; return getLog(redfish::message_registries::base::Index::actionNotSupported, - args); + std::to_array({arg1})); } -void actionNotSupported(crow::Response& res, const std::string& arg1) +void actionNotSupported(crow::Response& res, std::string_view arg1) { res.result(boost::beast::http::status::bad_request); addMessageToErrorJson(res.jsonValue, actionNotSupported(arg1)); @@ -1403,8 +1376,8 @@ void actionNotSupported(crow::Response& res, const std::string& arg1) nlohmann::json invalidIndex(int64_t arg1) { std::string arg1Str = std::to_string(arg1); - std::array<std::string_view, 1> args{arg1Str}; - return getLog(redfish::message_registries::base::Index::invalidIndex, args); + return getLog(redfish::message_registries::base::Index::invalidIndex, + std::to_array<std::string_view>({arg1Str})); } void invalidIndex(crow::Response& res, int64_t arg1) @@ -1516,16 +1489,16 @@ void insufficientPrivilege(crow::Response& res) * See header file for more information * @endinternal */ -nlohmann::json propertyValueModified(const std::string& arg1, - const std::string& arg2) +nlohmann::json propertyValueModified(std::string_view arg1, + std::string_view arg2) { - std::array<std::string_view, 2> args{arg1, arg2}; return getLog( - redfish::message_registries::base::Index::propertyValueModified, args); + redfish::message_registries::base::Index::propertyValueModified, + std::to_array({arg1, arg2})); } -void propertyValueModified(crow::Response& res, const std::string& arg1, - const std::string& arg2) +void propertyValueModified(crow::Response& res, std::string_view arg1, + std::string_view arg2) { res.result(boost::beast::http::status::ok); addMessageToJson(res.jsonValue, propertyValueModified(arg1, arg2), arg1); @@ -1557,18 +1530,16 @@ void accountNotModified(crow::Response& res) * See header file for more information * @endinternal */ -nlohmann::json queryParameterValueFormatError(const std::string& arg1, - const std::string& arg2) +nlohmann::json queryParameterValueFormatError(std::string_view arg1, + std::string_view arg2) { - std::array<std::string_view, 2> args{arg1, arg2}; return getLog(redfish::message_registries::base::Index:: queryParameterValueFormatError, - args); + std::to_array({arg1, arg2})); } -void queryParameterValueFormatError(crow::Response& res, - const std::string& arg1, - const std::string& arg2) +void queryParameterValueFormatError(crow::Response& res, std::string_view arg1, + std::string_view arg2) { res.result(boost::beast::http::status::bad_request); addMessageToErrorJson(res.jsonValue, @@ -1583,14 +1554,13 @@ void queryParameterValueFormatError(crow::Response& res, * See header file for more information * @endinternal */ -nlohmann::json propertyMissing(const std::string& arg1) +nlohmann::json propertyMissing(std::string_view arg1) { - std::array<std::string_view, 1> args{arg1}; return getLog(redfish::message_registries::base::Index::propertyMissing, - args); + std::to_array({arg1})); } -void propertyMissing(crow::Response& res, const std::string& arg1) +void propertyMissing(crow::Response& res, std::string_view arg1) { res.result(boost::beast::http::status::bad_request); addMessageToJson(res.jsonValue, propertyMissing(arg1), arg1); @@ -1603,14 +1573,13 @@ void propertyMissing(crow::Response& res, const std::string& arg1) * See header file for more information * @endinternal */ -nlohmann::json resourceExhaustion(const std::string& arg1) +nlohmann::json resourceExhaustion(std::string_view arg1) { - std::array<std::string_view, 1> args{arg1}; return getLog(redfish::message_registries::base::Index::resourceExhaustion, - args); + std::to_array({arg1})); } -void resourceExhaustion(crow::Response& res, const std::string& arg1) +void resourceExhaustion(crow::Response& res, std::string_view arg1) { res.result(boost::beast::http::status::service_unavailable); addMessageToErrorJson(res.jsonValue, resourceExhaustion(arg1)); @@ -1642,18 +1611,17 @@ void accountModified(crow::Response& res) * See header file for more information * @endinternal */ -nlohmann::json queryParameterOutOfRange(const std::string& arg1, - const std::string& arg2, - const std::string& arg3) +nlohmann::json queryParameterOutOfRange(std::string_view arg1, + std::string_view arg2, + std::string_view arg3) { - std::array<std::string_view, 3> args{arg1, arg2, arg3}; return getLog( redfish::message_registries::base::Index::queryParameterOutOfRange, - args); + std::to_array({arg1, arg2, arg3})); } -void queryParameterOutOfRange(crow::Response& res, const std::string& arg1, - const std::string& arg2, const std::string& arg3) +void queryParameterOutOfRange(crow::Response& res, std::string_view arg1, + std::string_view arg2, std::string_view arg3) { res.result(boost::beast::http::status::bad_request); addMessageToErrorJson(res.jsonValue, @@ -1662,11 +1630,10 @@ void queryParameterOutOfRange(crow::Response& res, const std::string& arg1, nlohmann::json passwordChangeRequired(const boost::urls::url_view& arg1) { - std::array<std::string_view, 1> args{ - std::string_view(arg1.data(), arg1.size())}; - + std::string_view arg1str(arg1.data(), arg1.size()); return getLog( - redfish::message_registries::base::Index::passwordChangeRequired, args); + redfish::message_registries::base::Index::passwordChangeRequired, + std::to_array({arg1str})); } /** @@ -1682,8 +1649,8 @@ void passwordChangeRequired(crow::Response& res, messages::addMessageToJsonRoot(res.jsonValue, passwordChangeRequired(arg1)); } -void invalidUpload(crow::Response& res, const std::string& arg1, - const std::string& arg2) +void invalidUpload(crow::Response& res, std::string_view arg1, + std::string_view arg2) { res.result(boost::beast::http::status::bad_request); addMessageToErrorJson(res.jsonValue, invalidUpload(arg1, arg2)); @@ -1696,12 +1663,17 @@ void invalidUpload(crow::Response& res, const std::string& arg1, * See header file for more information * @endinternal */ -nlohmann::json invalidUpload(const std::string& arg1, const std::string& arg2) +nlohmann::json invalidUpload(std::string_view arg1, std::string_view arg2) { + std::string msg = "Invalid file uploaded to "; + msg += arg1; + msg += ": "; + msg += arg2; + msg += "."; return nlohmann::json{ {"@odata.type", "/redfish/v1/$metadata#Message.v1_1_1.Message"}, {"MessageId", "OpenBMC.0.2.InvalidUpload"}, - {"Message", "Invalid file uploaded to " + arg1 + ": " + arg2 + "."}, + {"Message", std::move(msg)}, {"MessageArgs", {arg1, arg2}}, {"MessageSeverity", "Warning"}, {"Resolution", "None."}}; |