1 /* 2 // Copyright (c) 2018 Intel Corporation 3 // 4 // Licensed under the Apache License, Version 2.0 (the "License"); 5 // you may not use this file except in compliance with the License. 6 // You may obtain a copy of the License at 7 // 8 // http://www.apache.org/licenses/LICENSE-2.0 9 // 10 // Unless required by applicable law or agreed to in writing, software 11 // distributed under the License is distributed on an "AS IS" BASIS, 12 // WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. 13 // See the License for the specific language governing permissions and 14 // limitations under the License. 15 */ 16 #include "http_response.hpp" 17 #include "registries/base_message_registry.hpp" 18 19 #include <boost/beast/http/status.hpp> 20 #include <boost/url/url.hpp> 21 #include <error_messages.hpp> 22 #include <logging.hpp> 23 #include <nlohmann/json.hpp> 24 25 #include <array> 26 27 namespace redfish 28 { 29 30 namespace messages 31 { 32 33 static void addMessageToErrorJson(nlohmann::json& target, 34 const nlohmann::json& message) 35 { 36 auto& error = target["error"]; 37 38 // If this is the first error message, fill in the information from the 39 // first error message to the top level struct 40 if (!error.is_object()) 41 { 42 auto messageIdIterator = message.find("MessageId"); 43 if (messageIdIterator == message.end()) 44 { 45 BMCWEB_LOG_CRITICAL 46 << "Attempt to add error message without MessageId"; 47 return; 48 } 49 50 auto messageFieldIterator = message.find("Message"); 51 if (messageFieldIterator == message.end()) 52 { 53 BMCWEB_LOG_CRITICAL 54 << "Attempt to add error message without Message"; 55 return; 56 } 57 error = {{"code", *messageIdIterator}, 58 {"message", *messageFieldIterator}}; 59 } 60 else 61 { 62 // More than 1 error occurred, so the message has to be generic 63 error["code"] = std::string(messageVersionPrefix) + "GeneralError"; 64 error["message"] = "A general error has occurred. See Resolution for " 65 "information on how to resolve the error."; 66 } 67 68 // This check could technically be done in in the default construction 69 // branch above, but because we need the pointer to the extended info field 70 // anyway, it's more efficient to do it here. 71 auto& extendedInfo = error[messages::messageAnnotation]; 72 if (!extendedInfo.is_array()) 73 { 74 extendedInfo = nlohmann::json::array(); 75 } 76 77 extendedInfo.push_back(message); 78 } 79 80 static void addMessageToJsonRoot(nlohmann::json& target, 81 const nlohmann::json& message) 82 { 83 if (!target[messages::messageAnnotation].is_array()) 84 { 85 // Force object to be an array 86 target[messages::messageAnnotation] = nlohmann::json::array(); 87 } 88 89 target[messages::messageAnnotation].push_back(message); 90 } 91 92 static void addMessageToJson(nlohmann::json& target, 93 const nlohmann::json& message, 94 std::string_view fieldPath) 95 { 96 std::string extendedInfo(fieldPath); 97 extendedInfo += messages::messageAnnotation; 98 99 nlohmann::json& field = target[extendedInfo]; 100 if (!field.is_array()) 101 { 102 // Force object to be an array 103 field = nlohmann::json::array(); 104 } 105 106 // Object exists and it is an array so we can just push in the message 107 field.push_back(message); 108 } 109 110 static nlohmann::json getLog(redfish::registries::base::Index name, 111 std::span<const std::string_view> args) 112 { 113 size_t index = static_cast<size_t>(name); 114 if (index >= redfish::registries::base::registry.size()) 115 { 116 return {}; 117 } 118 const redfish::registries::MessageEntry& entry = 119 redfish::registries::base::registry[index]; 120 // Intentionally make a copy of the string, so we can append in the 121 // parameters. 122 std::string msg = entry.second.message; 123 redfish::registries::fillMessageArgs(args, msg); 124 nlohmann::json jArgs = nlohmann::json::array(); 125 for (const std::string_view arg : args) 126 { 127 jArgs.push_back(arg); 128 } 129 std::string msgId = redfish::registries::base::header.id; 130 msgId += "."; 131 msgId += entry.first; 132 return {{"@odata.type", "#Message.v1_1_1.Message"}, 133 {"MessageId", std::move(msgId)}, 134 {"Message", std::move(msg)}, 135 {"MessageArgs", std::move(jArgs)}, 136 {"MessageSeverity", entry.second.messageSeverity}, 137 {"Resolution", entry.second.resolution}}; 138 } 139 140 /** 141 * @internal 142 * @brief Formats ResourceInUse message into JSON 143 * 144 * See header file for more information 145 * @endinternal 146 */ 147 nlohmann::json resourceInUse(void) 148 { 149 return getLog(redfish::registries::base::Index::resourceInUse, {}); 150 } 151 152 void resourceInUse(crow::Response& res) 153 { 154 res.result(boost::beast::http::status::service_unavailable); 155 addMessageToErrorJson(res.jsonValue, resourceInUse()); 156 } 157 158 /** 159 * @internal 160 * @brief Formats MalformedJSON message into JSON 161 * 162 * See header file for more information 163 * @endinternal 164 */ 165 nlohmann::json malformedJSON(void) 166 { 167 return getLog(redfish::registries::base::Index::malformedJSON, {}); 168 } 169 170 void malformedJSON(crow::Response& res) 171 { 172 res.result(boost::beast::http::status::bad_request); 173 addMessageToErrorJson(res.jsonValue, malformedJSON()); 174 } 175 176 /** 177 * @internal 178 * @brief Formats ResourceMissingAtURI message into JSON 179 * 180 * See header file for more information 181 * @endinternal 182 */ 183 nlohmann::json resourceMissingAtURI(const boost::urls::url_view& arg1) 184 { 185 std::array<std::string_view, 1> args{ 186 std::string_view{arg1.data(), arg1.size()}}; 187 return getLog(redfish::registries::base::Index::resourceMissingAtURI, args); 188 } 189 190 void resourceMissingAtURI(crow::Response& res, 191 const boost::urls::url_view& arg1) 192 { 193 res.result(boost::beast::http::status::bad_request); 194 addMessageToErrorJson(res.jsonValue, resourceMissingAtURI(arg1)); 195 } 196 197 /** 198 * @internal 199 * @brief Formats ActionParameterValueFormatError message into JSON 200 * 201 * See header file for more information 202 * @endinternal 203 */ 204 nlohmann::json actionParameterValueFormatError(std::string_view arg1, 205 std::string_view arg2, 206 std::string_view arg3) 207 { 208 return getLog( 209 redfish::registries::base::Index::actionParameterValueFormatError, 210 std::to_array({arg1, arg2, arg3})); 211 } 212 213 void actionParameterValueFormatError(crow::Response& res, std::string_view arg1, 214 std::string_view arg2, 215 std::string_view arg3) 216 { 217 res.result(boost::beast::http::status::bad_request); 218 addMessageToErrorJson(res.jsonValue, 219 actionParameterValueFormatError(arg1, arg2, arg3)); 220 } 221 222 /** 223 * @internal 224 * @brief Formats InternalError message into JSON 225 * 226 * See header file for more information 227 * @endinternal 228 */ 229 nlohmann::json internalError(void) 230 { 231 return getLog(redfish::registries::base::Index::internalError, {}); 232 } 233 234 void internalError(crow::Response& res, const bmcweb::source_location location) 235 { 236 BMCWEB_LOG_CRITICAL << "Internal Error " << location.file_name() << "(" 237 << location.line() << ":" << location.column() << ") `" 238 << location.function_name() << "`: "; 239 res.result(boost::beast::http::status::internal_server_error); 240 addMessageToErrorJson(res.jsonValue, internalError()); 241 } 242 243 /** 244 * @internal 245 * @brief Formats UnrecognizedRequestBody message into JSON 246 * 247 * See header file for more information 248 * @endinternal 249 */ 250 nlohmann::json unrecognizedRequestBody(void) 251 { 252 return getLog(redfish::registries::base::Index::unrecognizedRequestBody, 253 {}); 254 } 255 256 void unrecognizedRequestBody(crow::Response& res) 257 { 258 res.result(boost::beast::http::status::bad_request); 259 addMessageToErrorJson(res.jsonValue, unrecognizedRequestBody()); 260 } 261 262 /** 263 * @internal 264 * @brief Formats ResourceAtUriUnauthorized message into JSON 265 * 266 * See header file for more information 267 * @endinternal 268 */ 269 nlohmann::json resourceAtUriUnauthorized(const boost::urls::url_view& arg1, 270 std::string_view arg2) 271 { 272 return getLog( 273 redfish::registries::base::Index::resourceAtUriUnauthorized, 274 std::to_array({std::string_view{arg1.data(), arg1.size()}, arg2})); 275 } 276 277 void resourceAtUriUnauthorized(crow::Response& res, 278 const boost::urls::url_view& arg1, 279 std::string_view arg2) 280 { 281 res.result(boost::beast::http::status::unauthorized); 282 addMessageToErrorJson(res.jsonValue, resourceAtUriUnauthorized(arg1, arg2)); 283 } 284 285 /** 286 * @internal 287 * @brief Formats ActionParameterUnknown message into JSON 288 * 289 * See header file for more information 290 * @endinternal 291 */ 292 nlohmann::json actionParameterUnknown(std::string_view arg1, 293 std::string_view arg2) 294 { 295 return getLog(redfish::registries::base::Index::actionParameterUnknown, 296 std::to_array({arg1, arg2})); 297 } 298 299 void actionParameterUnknown(crow::Response& res, std::string_view arg1, 300 std::string_view arg2) 301 { 302 res.result(boost::beast::http::status::bad_request); 303 addMessageToErrorJson(res.jsonValue, actionParameterUnknown(arg1, arg2)); 304 } 305 306 /** 307 * @internal 308 * @brief Formats ResourceCannotBeDeleted message into JSON 309 * 310 * See header file for more information 311 * @endinternal 312 */ 313 nlohmann::json resourceCannotBeDeleted(void) 314 { 315 return getLog(redfish::registries::base::Index::resourceCannotBeDeleted, 316 {}); 317 } 318 319 void resourceCannotBeDeleted(crow::Response& res) 320 { 321 res.result(boost::beast::http::status::forbidden); 322 addMessageToErrorJson(res.jsonValue, resourceCannotBeDeleted()); 323 } 324 325 /** 326 * @internal 327 * @brief Formats PropertyDuplicate message into JSON 328 * 329 * See header file for more information 330 * @endinternal 331 */ 332 nlohmann::json propertyDuplicate(std::string_view arg1) 333 { 334 return getLog(redfish::registries::base::Index::propertyDuplicate, 335 std::to_array({arg1})); 336 } 337 338 void propertyDuplicate(crow::Response& res, std::string_view arg1) 339 { 340 res.result(boost::beast::http::status::bad_request); 341 addMessageToJson(res.jsonValue, propertyDuplicate(arg1), arg1); 342 } 343 344 /** 345 * @internal 346 * @brief Formats ServiceTemporarilyUnavailable message into JSON 347 * 348 * See header file for more information 349 * @endinternal 350 */ 351 nlohmann::json serviceTemporarilyUnavailable(std::string_view arg1) 352 { 353 return getLog( 354 redfish::registries::base::Index::serviceTemporarilyUnavailable, 355 std::to_array({arg1})); 356 } 357 358 void serviceTemporarilyUnavailable(crow::Response& res, std::string_view arg1) 359 { 360 res.addHeader("Retry-After", arg1); 361 res.result(boost::beast::http::status::service_unavailable); 362 addMessageToErrorJson(res.jsonValue, serviceTemporarilyUnavailable(arg1)); 363 } 364 365 /** 366 * @internal 367 * @brief Formats ResourceAlreadyExists message into JSON 368 * 369 * See header file for more information 370 * @endinternal 371 */ 372 nlohmann::json resourceAlreadyExists(std::string_view arg1, 373 std::string_view arg2, 374 std::string_view arg3) 375 { 376 return getLog(redfish::registries::base::Index::resourceAlreadyExists, 377 std::to_array({arg1, arg2, arg3})); 378 } 379 380 void resourceAlreadyExists(crow::Response& res, std::string_view arg1, 381 std::string_view arg2, std::string_view arg3) 382 { 383 res.result(boost::beast::http::status::bad_request); 384 addMessageToJson(res.jsonValue, resourceAlreadyExists(arg1, arg2, arg3), 385 arg2); 386 } 387 388 /** 389 * @internal 390 * @brief Formats AccountForSessionNoLongerExists message into JSON 391 * 392 * See header file for more information 393 * @endinternal 394 */ 395 nlohmann::json accountForSessionNoLongerExists(void) 396 { 397 return getLog( 398 redfish::registries::base::Index::accountForSessionNoLongerExists, {}); 399 } 400 401 void accountForSessionNoLongerExists(crow::Response& res) 402 { 403 res.result(boost::beast::http::status::forbidden); 404 addMessageToErrorJson(res.jsonValue, accountForSessionNoLongerExists()); 405 } 406 407 /** 408 * @internal 409 * @brief Formats CreateFailedMissingReqProperties message into JSON 410 * 411 * See header file for more information 412 * @endinternal 413 */ 414 nlohmann::json createFailedMissingReqProperties(std::string_view arg1) 415 { 416 return getLog( 417 redfish::registries::base::Index::createFailedMissingReqProperties, 418 std::to_array({arg1})); 419 } 420 421 void createFailedMissingReqProperties(crow::Response& res, 422 std::string_view arg1) 423 { 424 res.result(boost::beast::http::status::bad_request); 425 addMessageToJson(res.jsonValue, createFailedMissingReqProperties(arg1), 426 arg1); 427 } 428 429 /** 430 * @internal 431 * @brief Formats PropertyValueFormatError message into JSON for the specified 432 * property 433 * 434 * See header file for more information 435 * @endinternal 436 */ 437 nlohmann::json propertyValueFormatError(std::string_view arg1, 438 std::string_view arg2) 439 { 440 return getLog(redfish::registries::base::Index::propertyValueFormatError, 441 std::to_array({arg1, arg2})); 442 } 443 444 void propertyValueFormatError(crow::Response& res, std::string_view arg1, 445 std::string_view arg2) 446 { 447 res.result(boost::beast::http::status::bad_request); 448 addMessageToJson(res.jsonValue, propertyValueFormatError(arg1, arg2), arg2); 449 } 450 451 /** 452 * @internal 453 * @brief Formats PropertyValueNotInList message into JSON for the specified 454 * property 455 * 456 * See header file for more information 457 * @endinternal 458 */ 459 nlohmann::json propertyValueNotInList(std::string_view arg1, 460 std::string_view arg2) 461 { 462 return getLog(redfish::registries::base::Index::propertyValueNotInList, 463 std::to_array({arg1, arg2})); 464 } 465 466 void propertyValueNotInList(crow::Response& res, std::string_view arg1, 467 std::string_view arg2) 468 { 469 res.result(boost::beast::http::status::bad_request); 470 addMessageToJson(res.jsonValue, propertyValueNotInList(arg1, arg2), arg2); 471 } 472 473 /** 474 * @internal 475 * @brief Formats ResourceAtUriInUnknownFormat message into JSON 476 * 477 * See header file for more information 478 * @endinternal 479 */ 480 nlohmann::json resourceAtUriInUnknownFormat(const boost::urls::url_view& arg1) 481 { 482 std::string_view arg1str{arg1.data(), arg1.size()}; 483 return getLog( 484 redfish::registries::base::Index::resourceAtUriInUnknownFormat, 485 std::to_array({arg1str})); 486 } 487 488 void resourceAtUriInUnknownFormat(crow::Response& res, 489 const boost::urls::url_view& arg1) 490 { 491 res.result(boost::beast::http::status::bad_request); 492 addMessageToErrorJson(res.jsonValue, resourceAtUriInUnknownFormat(arg1)); 493 } 494 495 /** 496 * @internal 497 * @brief Formats ServiceDisabled message into JSON 498 * 499 * See header file for more information 500 * @endinternal 501 */ 502 nlohmann::json serviceDisabled(std::string_view arg1) 503 { 504 return getLog(redfish::registries::base::Index::serviceDisabled, 505 std::to_array({arg1})); 506 } 507 508 void serviceDisabled(crow::Response& res, std::string_view arg1) 509 { 510 res.result(boost::beast::http::status::service_unavailable); 511 addMessageToErrorJson(res.jsonValue, serviceDisabled(arg1)); 512 } 513 514 /** 515 * @internal 516 * @brief Formats ServiceInUnknownState message into JSON 517 * 518 * See header file for more information 519 * @endinternal 520 */ 521 nlohmann::json serviceInUnknownState(void) 522 { 523 return getLog(redfish::registries::base::Index::serviceInUnknownState, {}); 524 } 525 526 void serviceInUnknownState(crow::Response& res) 527 { 528 res.result(boost::beast::http::status::service_unavailable); 529 addMessageToErrorJson(res.jsonValue, serviceInUnknownState()); 530 } 531 532 /** 533 * @internal 534 * @brief Formats EventSubscriptionLimitExceeded message into JSON 535 * 536 * See header file for more information 537 * @endinternal 538 */ 539 nlohmann::json eventSubscriptionLimitExceeded(void) 540 { 541 return getLog( 542 redfish::registries::base::Index::eventSubscriptionLimitExceeded, {}); 543 } 544 545 void eventSubscriptionLimitExceeded(crow::Response& res) 546 { 547 res.result(boost::beast::http::status::service_unavailable); 548 addMessageToErrorJson(res.jsonValue, eventSubscriptionLimitExceeded()); 549 } 550 551 /** 552 * @internal 553 * @brief Formats ActionParameterMissing message into JSON 554 * 555 * See header file for more information 556 * @endinternal 557 */ 558 nlohmann::json actionParameterMissing(std::string_view arg1, 559 std::string_view arg2) 560 { 561 return getLog(redfish::registries::base::Index::actionParameterMissing, 562 std::to_array({arg1, arg2})); 563 } 564 565 void actionParameterMissing(crow::Response& res, std::string_view arg1, 566 std::string_view arg2) 567 { 568 res.result(boost::beast::http::status::bad_request); 569 addMessageToErrorJson(res.jsonValue, actionParameterMissing(arg1, arg2)); 570 } 571 572 /** 573 * @internal 574 * @brief Formats StringValueTooLong message into JSON 575 * 576 * See header file for more information 577 * @endinternal 578 */ 579 nlohmann::json stringValueTooLong(std::string_view arg1, int arg2) 580 { 581 std::string arg2String = std::to_string(arg2); 582 return getLog(redfish::registries::base::Index::stringValueTooLong, 583 std::to_array({arg1, std::string_view(arg2String)})); 584 } 585 586 void stringValueTooLong(crow::Response& res, std::string_view arg1, int arg2) 587 { 588 res.result(boost::beast::http::status::bad_request); 589 addMessageToErrorJson(res.jsonValue, stringValueTooLong(arg1, arg2)); 590 } 591 592 /** 593 * @internal 594 * @brief Formats SessionTerminated message into JSON 595 * 596 * See header file for more information 597 * @endinternal 598 */ 599 nlohmann::json sessionTerminated(void) 600 { 601 return getLog(redfish::registries::base::Index::sessionTerminated, {}); 602 } 603 604 void sessionTerminated(crow::Response& res) 605 { 606 res.result(boost::beast::http::status::ok); 607 addMessageToJsonRoot(res.jsonValue, sessionTerminated()); 608 } 609 610 /** 611 * @internal 612 * @brief Formats SubscriptionTerminated message into JSON 613 * 614 * See header file for more information 615 * @endinternal 616 */ 617 nlohmann::json subscriptionTerminated(void) 618 { 619 return getLog(redfish::registries::base::Index::subscriptionTerminated, {}); 620 } 621 622 void subscriptionTerminated(crow::Response& res) 623 { 624 res.result(boost::beast::http::status::ok); 625 addMessageToJsonRoot(res.jsonValue, subscriptionTerminated()); 626 } 627 628 /** 629 * @internal 630 * @brief Formats ResourceTypeIncompatible message into JSON 631 * 632 * See header file for more information 633 * @endinternal 634 */ 635 nlohmann::json resourceTypeIncompatible(std::string_view arg1, 636 std::string_view arg2) 637 { 638 return getLog(redfish::registries::base::Index::resourceTypeIncompatible, 639 std::to_array({arg1, arg2})); 640 } 641 642 void resourceTypeIncompatible(crow::Response& res, std::string_view arg1, 643 std::string_view arg2) 644 { 645 res.result(boost::beast::http::status::bad_request); 646 addMessageToErrorJson(res.jsonValue, resourceTypeIncompatible(arg1, arg2)); 647 } 648 649 /** 650 * @internal 651 * @brief Formats ResetRequired message into JSON 652 * 653 * See header file for more information 654 * @endinternal 655 */ 656 nlohmann::json resetRequired(const boost::urls::url_view& arg1, 657 std::string_view arg2) 658 { 659 std::string_view arg1str(arg1.data(), arg1.size()); 660 return getLog(redfish::registries::base::Index::resetRequired, 661 std::to_array({arg1str, arg2})); 662 } 663 664 void resetRequired(crow::Response& res, const boost::urls::url_view& arg1, 665 std::string_view arg2) 666 { 667 res.result(boost::beast::http::status::bad_request); 668 addMessageToErrorJson(res.jsonValue, resetRequired(arg1, arg2)); 669 } 670 671 /** 672 * @internal 673 * @brief Formats ChassisPowerStateOnRequired message into JSON 674 * 675 * See header file for more information 676 * @endinternal 677 */ 678 nlohmann::json chassisPowerStateOnRequired(std::string_view arg1) 679 { 680 return getLog(redfish::registries::base::Index::resetRequired, 681 std::to_array({arg1})); 682 } 683 684 void chassisPowerStateOnRequired(crow::Response& res, std::string_view arg1) 685 { 686 res.result(boost::beast::http::status::bad_request); 687 addMessageToErrorJson(res.jsonValue, chassisPowerStateOnRequired(arg1)); 688 } 689 690 /** 691 * @internal 692 * @brief Formats ChassisPowerStateOffRequired message into JSON 693 * 694 * See header file for more information 695 * @endinternal 696 */ 697 nlohmann::json chassisPowerStateOffRequired(std::string_view arg1) 698 { 699 return getLog( 700 redfish::registries::base::Index::chassisPowerStateOffRequired, 701 std::to_array({arg1})); 702 } 703 704 void chassisPowerStateOffRequired(crow::Response& res, std::string_view arg1) 705 { 706 res.result(boost::beast::http::status::bad_request); 707 addMessageToErrorJson(res.jsonValue, chassisPowerStateOffRequired(arg1)); 708 } 709 710 /** 711 * @internal 712 * @brief Formats PropertyValueConflict message into JSON 713 * 714 * See header file for more information 715 * @endinternal 716 */ 717 nlohmann::json propertyValueConflict(std::string_view arg1, 718 std::string_view arg2) 719 { 720 return getLog(redfish::registries::base::Index::propertyValueConflict, 721 std::to_array({arg1, arg2})); 722 } 723 724 void propertyValueConflict(crow::Response& res, std::string_view arg1, 725 std::string_view arg2) 726 { 727 res.result(boost::beast::http::status::bad_request); 728 addMessageToErrorJson(res.jsonValue, propertyValueConflict(arg1, arg2)); 729 } 730 731 /** 732 * @internal 733 * @brief Formats PropertyValueResourceConflict message into JSON 734 * 735 * See header file for more information 736 * @endinternal 737 */ 738 nlohmann::json propertyValueResourceConflict(std::string_view arg1, 739 std::string_view arg2, 740 const boost::urls::url_view& arg3) 741 { 742 return getLog( 743 redfish::registries::base::Index::propertyValueResourceConflict, 744 std::to_array( 745 {arg1, arg2, std::string_view{arg3.data(), arg3.size()}})); 746 } 747 748 void propertyValueResourceConflict(crow::Response& res, std::string_view arg1, 749 std::string_view arg2, 750 const boost::urls::url_view& arg3) 751 { 752 res.result(boost::beast::http::status::conflict); 753 addMessageToErrorJson(res.jsonValue, 754 propertyValueResourceConflict(arg1, arg2, arg3)); 755 } 756 757 /** 758 * @internal 759 * @brief Formats PropertyValueExternalConflict message into JSON 760 * 761 * See header file for more information 762 * @endinternal 763 */ 764 nlohmann::json propertyValueExternalConflict(std::string_view arg1, 765 std::string_view arg2) 766 { 767 return getLog( 768 redfish::registries::base::Index::propertyValueExternalConflict, 769 std::to_array({arg1, arg2})); 770 } 771 772 void propertyValueExternalConflict(crow::Response& res, std::string_view arg1, 773 std::string_view arg2) 774 { 775 res.result(boost::beast::http::status::conflict); 776 addMessageToErrorJson(res.jsonValue, 777 propertyValueExternalConflict(arg1, arg2)); 778 } 779 780 /** 781 * @internal 782 * @brief Formats PropertyValueIncorrect message into JSON 783 * 784 * See header file for more information 785 * @endinternal 786 */ 787 nlohmann::json propertyValueIncorrect(std::string_view arg1, 788 std::string_view arg2) 789 { 790 return getLog(redfish::registries::base::Index::propertyValueIncorrect, 791 std::to_array({arg1, arg2})); 792 } 793 794 void propertyValueIncorrect(crow::Response& res, std::string_view arg1, 795 std::string_view arg2) 796 { 797 res.result(boost::beast::http::status::bad_request); 798 addMessageToErrorJson(res.jsonValue, propertyValueIncorrect(arg1, arg2)); 799 } 800 801 /** 802 * @internal 803 * @brief Formats ResourceCreationConflict message into JSON 804 * 805 * See header file for more information 806 * @endinternal 807 */ 808 nlohmann::json resourceCreationConflict(const boost::urls::url_view& arg1) 809 { 810 std::string_view arg1str(arg1.data(), arg1.size()); 811 return getLog(redfish::registries::base::Index::resourceCreationConflict, 812 std::to_array({arg1str})); 813 } 814 815 void resourceCreationConflict(crow::Response& res, 816 const boost::urls::url_view& arg1) 817 { 818 res.result(boost::beast::http::status::bad_request); 819 addMessageToErrorJson(res.jsonValue, resourceCreationConflict(arg1)); 820 } 821 822 /** 823 * @internal 824 * @brief Formats MaximumErrorsExceeded message into JSON 825 * 826 * See header file for more information 827 * @endinternal 828 */ 829 nlohmann::json maximumErrorsExceeded(void) 830 { 831 return getLog(redfish::registries::base::Index::maximumErrorsExceeded, {}); 832 } 833 834 void maximumErrorsExceeded(crow::Response& res) 835 { 836 res.result(boost::beast::http::status::internal_server_error); 837 addMessageToErrorJson(res.jsonValue, maximumErrorsExceeded()); 838 } 839 840 /** 841 * @internal 842 * @brief Formats PreconditionFailed message into JSON 843 * 844 * See header file for more information 845 * @endinternal 846 */ 847 nlohmann::json preconditionFailed(void) 848 { 849 return getLog(redfish::registries::base::Index::preconditionFailed, {}); 850 } 851 852 void preconditionFailed(crow::Response& res) 853 { 854 res.result(boost::beast::http::status::precondition_failed); 855 addMessageToErrorJson(res.jsonValue, preconditionFailed()); 856 } 857 858 /** 859 * @internal 860 * @brief Formats PreconditionRequired message into JSON 861 * 862 * See header file for more information 863 * @endinternal 864 */ 865 nlohmann::json preconditionRequired(void) 866 { 867 return getLog(redfish::registries::base::Index::preconditionRequired, {}); 868 } 869 870 void preconditionRequired(crow::Response& res) 871 { 872 res.result(boost::beast::http::status::bad_request); 873 addMessageToErrorJson(res.jsonValue, preconditionRequired()); 874 } 875 876 /** 877 * @internal 878 * @brief Formats OperationFailed message into JSON 879 * 880 * See header file for more information 881 * @endinternal 882 */ 883 nlohmann::json operationFailed(void) 884 { 885 return getLog(redfish::registries::base::Index::operationFailed, {}); 886 } 887 888 void operationFailed(crow::Response& res) 889 { 890 res.result(boost::beast::http::status::internal_server_error); 891 addMessageToErrorJson(res.jsonValue, operationFailed()); 892 } 893 894 /** 895 * @internal 896 * @brief Formats OperationTimeout message into JSON 897 * 898 * See header file for more information 899 * @endinternal 900 */ 901 nlohmann::json operationTimeout(void) 902 { 903 return getLog(redfish::registries::base::Index::operationTimeout, {}); 904 } 905 906 void operationTimeout(crow::Response& res) 907 { 908 res.result(boost::beast::http::status::internal_server_error); 909 addMessageToErrorJson(res.jsonValue, operationTimeout()); 910 } 911 912 /** 913 * @internal 914 * @brief Formats PropertyValueTypeError message into JSON for the specified 915 * property 916 * 917 * See header file for more information 918 * @endinternal 919 */ 920 nlohmann::json propertyValueTypeError(std::string_view arg1, 921 std::string_view arg2) 922 { 923 return getLog(redfish::registries::base::Index::propertyValueTypeError, 924 std::to_array({arg1, arg2})); 925 } 926 927 void propertyValueTypeError(crow::Response& res, std::string_view arg1, 928 std::string_view arg2) 929 { 930 res.result(boost::beast::http::status::bad_request); 931 addMessageToJson(res.jsonValue, propertyValueTypeError(arg1, arg2), arg2); 932 } 933 934 /** 935 * @internal 936 * @brief Formats ResourceNotFound message into JSONd 937 * 938 * See header file for more information 939 * @endinternal 940 */ 941 nlohmann::json resourceNotFound(std::string_view arg1, std::string_view arg2) 942 { 943 return getLog(redfish::registries::base::Index::resourceNotFound, 944 std::to_array({arg1, arg2})); 945 } 946 947 void resourceNotFound(crow::Response& res, std::string_view arg1, 948 std::string_view arg2) 949 { 950 res.result(boost::beast::http::status::not_found); 951 addMessageToErrorJson(res.jsonValue, resourceNotFound(arg1, arg2)); 952 } 953 954 /** 955 * @internal 956 * @brief Formats CouldNotEstablishConnection message into JSON 957 * 958 * See header file for more information 959 * @endinternal 960 */ 961 nlohmann::json couldNotEstablishConnection(const boost::urls::url_view& arg1) 962 { 963 std::string_view arg1str(arg1.data(), arg1.size()); 964 return getLog(redfish::registries::base::Index::couldNotEstablishConnection, 965 std::to_array({arg1str})); 966 } 967 968 void couldNotEstablishConnection(crow::Response& res, 969 const boost::urls::url_view& arg1) 970 { 971 res.result(boost::beast::http::status::not_found); 972 addMessageToErrorJson(res.jsonValue, couldNotEstablishConnection(arg1)); 973 } 974 975 /** 976 * @internal 977 * @brief Formats PropertyNotWritable message into JSON for the specified 978 * property 979 * 980 * See header file for more information 981 * @endinternal 982 */ 983 nlohmann::json propertyNotWritable(std::string_view arg1) 984 { 985 return getLog(redfish::registries::base::Index::propertyNotWritable, 986 std::to_array({arg1})); 987 } 988 989 void propertyNotWritable(crow::Response& res, std::string_view arg1) 990 { 991 res.result(boost::beast::http::status::forbidden); 992 addMessageToJson(res.jsonValue, propertyNotWritable(arg1), arg1); 993 } 994 995 /** 996 * @internal 997 * @brief Formats QueryParameterValueTypeError message into JSON 998 * 999 * See header file for more information 1000 * @endinternal 1001 */ 1002 nlohmann::json queryParameterValueTypeError(std::string_view arg1, 1003 std::string_view arg2) 1004 { 1005 return getLog( 1006 redfish::registries::base::Index::queryParameterValueTypeError, 1007 std::to_array({arg1, arg2})); 1008 } 1009 1010 void queryParameterValueTypeError(crow::Response& res, std::string_view arg1, 1011 std::string_view arg2) 1012 { 1013 res.result(boost::beast::http::status::bad_request); 1014 addMessageToErrorJson(res.jsonValue, 1015 queryParameterValueTypeError(arg1, arg2)); 1016 } 1017 1018 /** 1019 * @internal 1020 * @brief Formats ServiceShuttingDown message into JSON 1021 * 1022 * See header file for more information 1023 * @endinternal 1024 */ 1025 nlohmann::json serviceShuttingDown(void) 1026 { 1027 return getLog(redfish::registries::base::Index::serviceShuttingDown, {}); 1028 } 1029 1030 void serviceShuttingDown(crow::Response& res) 1031 { 1032 res.result(boost::beast::http::status::service_unavailable); 1033 addMessageToErrorJson(res.jsonValue, serviceShuttingDown()); 1034 } 1035 1036 /** 1037 * @internal 1038 * @brief Formats ActionParameterDuplicate message into JSON 1039 * 1040 * See header file for more information 1041 * @endinternal 1042 */ 1043 nlohmann::json actionParameterDuplicate(std::string_view arg1, 1044 std::string_view arg2) 1045 { 1046 return getLog(redfish::registries::base::Index::actionParameterDuplicate, 1047 std::to_array({arg1, arg2})); 1048 } 1049 1050 void actionParameterDuplicate(crow::Response& res, std::string_view arg1, 1051 std::string_view arg2) 1052 { 1053 res.result(boost::beast::http::status::bad_request); 1054 addMessageToErrorJson(res.jsonValue, actionParameterDuplicate(arg1, arg2)); 1055 } 1056 1057 /** 1058 * @internal 1059 * @brief Formats ActionParameterNotSupported message into JSON 1060 * 1061 * See header file for more information 1062 * @endinternal 1063 */ 1064 nlohmann::json actionParameterNotSupported(std::string_view arg1, 1065 std::string_view arg2) 1066 { 1067 return getLog(redfish::registries::base::Index::actionParameterNotSupported, 1068 std::to_array({arg1, arg2})); 1069 } 1070 1071 void actionParameterNotSupported(crow::Response& res, std::string_view arg1, 1072 std::string_view arg2) 1073 { 1074 res.result(boost::beast::http::status::bad_request); 1075 addMessageToErrorJson(res.jsonValue, 1076 actionParameterNotSupported(arg1, arg2)); 1077 } 1078 1079 /** 1080 * @internal 1081 * @brief Formats SourceDoesNotSupportProtocol message into JSON 1082 * 1083 * See header file for more information 1084 * @endinternal 1085 */ 1086 nlohmann::json sourceDoesNotSupportProtocol(const boost::urls::url_view& arg1, 1087 std::string_view arg2) 1088 { 1089 std::string_view arg1str(arg1.data(), arg1.size()); 1090 return getLog( 1091 redfish::registries::base::Index::sourceDoesNotSupportProtocol, 1092 std::to_array({arg1str, arg2})); 1093 } 1094 1095 void sourceDoesNotSupportProtocol(crow::Response& res, 1096 const boost::urls::url_view& arg1, 1097 std::string_view arg2) 1098 { 1099 res.result(boost::beast::http::status::bad_request); 1100 addMessageToErrorJson(res.jsonValue, 1101 sourceDoesNotSupportProtocol(arg1, arg2)); 1102 } 1103 1104 /** 1105 * @internal 1106 * @brief Formats AccountRemoved message into JSON 1107 * 1108 * See header file for more information 1109 * @endinternal 1110 */ 1111 nlohmann::json accountRemoved(void) 1112 { 1113 return getLog(redfish::registries::base::Index::accountRemoved, {}); 1114 } 1115 1116 void accountRemoved(crow::Response& res) 1117 { 1118 res.result(boost::beast::http::status::ok); 1119 addMessageToJsonRoot(res.jsonValue, accountRemoved()); 1120 } 1121 1122 /** 1123 * @internal 1124 * @brief Formats AccessDenied message into JSON 1125 * 1126 * See header file for more information 1127 * @endinternal 1128 */ 1129 nlohmann::json accessDenied(const boost::urls::url_view& arg1) 1130 { 1131 std::string_view arg1str(arg1.data(), arg1.size()); 1132 return getLog(redfish::registries::base::Index::accessDenied, 1133 std::to_array({arg1str})); 1134 } 1135 1136 void accessDenied(crow::Response& res, const boost::urls::url_view& arg1) 1137 { 1138 res.result(boost::beast::http::status::forbidden); 1139 addMessageToErrorJson(res.jsonValue, accessDenied(arg1)); 1140 } 1141 1142 /** 1143 * @internal 1144 * @brief Formats QueryNotSupported message into JSON 1145 * 1146 * See header file for more information 1147 * @endinternal 1148 */ 1149 nlohmann::json queryNotSupported(void) 1150 { 1151 return getLog(redfish::registries::base::Index::queryNotSupported, {}); 1152 } 1153 1154 void queryNotSupported(crow::Response& res) 1155 { 1156 res.result(boost::beast::http::status::bad_request); 1157 addMessageToErrorJson(res.jsonValue, queryNotSupported()); 1158 } 1159 1160 /** 1161 * @internal 1162 * @brief Formats CreateLimitReachedForResource message into JSON 1163 * 1164 * See header file for more information 1165 * @endinternal 1166 */ 1167 nlohmann::json createLimitReachedForResource(void) 1168 { 1169 return getLog( 1170 redfish::registries::base::Index::createLimitReachedForResource, {}); 1171 } 1172 1173 void createLimitReachedForResource(crow::Response& res) 1174 { 1175 res.result(boost::beast::http::status::bad_request); 1176 addMessageToErrorJson(res.jsonValue, createLimitReachedForResource()); 1177 } 1178 1179 /** 1180 * @internal 1181 * @brief Formats GeneralError message into JSON 1182 * 1183 * See header file for more information 1184 * @endinternal 1185 */ 1186 nlohmann::json generalError(void) 1187 { 1188 return getLog(redfish::registries::base::Index::generalError, {}); 1189 } 1190 1191 void generalError(crow::Response& res) 1192 { 1193 res.result(boost::beast::http::status::internal_server_error); 1194 addMessageToErrorJson(res.jsonValue, generalError()); 1195 } 1196 1197 /** 1198 * @internal 1199 * @brief Formats Success message into JSON 1200 * 1201 * See header file for more information 1202 * @endinternal 1203 */ 1204 nlohmann::json success(void) 1205 { 1206 return getLog(redfish::registries::base::Index::success, {}); 1207 } 1208 1209 void success(crow::Response& res) 1210 { 1211 // don't set res.result here because success is the default and any 1212 // error should overwrite the default 1213 addMessageToJsonRoot(res.jsonValue, success()); 1214 } 1215 1216 /** 1217 * @internal 1218 * @brief Formats Created message into JSON 1219 * 1220 * See header file for more information 1221 * @endinternal 1222 */ 1223 nlohmann::json created(void) 1224 { 1225 return getLog(redfish::registries::base::Index::created, {}); 1226 } 1227 1228 void created(crow::Response& res) 1229 { 1230 res.result(boost::beast::http::status::created); 1231 addMessageToJsonRoot(res.jsonValue, created()); 1232 } 1233 1234 /** 1235 * @internal 1236 * @brief Formats NoOperation message into JSON 1237 * 1238 * See header file for more information 1239 * @endinternal 1240 */ 1241 nlohmann::json noOperation(void) 1242 { 1243 return getLog(redfish::registries::base::Index::noOperation, {}); 1244 } 1245 1246 void noOperation(crow::Response& res) 1247 { 1248 res.result(boost::beast::http::status::bad_request); 1249 addMessageToErrorJson(res.jsonValue, noOperation()); 1250 } 1251 1252 /** 1253 * @internal 1254 * @brief Formats PropertyUnknown message into JSON for the specified 1255 * property 1256 * 1257 * See header file for more information 1258 * @endinternal 1259 */ 1260 nlohmann::json propertyUnknown(std::string_view arg1) 1261 { 1262 return getLog(redfish::registries::base::Index::propertyUnknown, 1263 std::to_array({arg1})); 1264 } 1265 1266 void propertyUnknown(crow::Response& res, std::string_view arg1) 1267 { 1268 res.result(boost::beast::http::status::bad_request); 1269 addMessageToJson(res.jsonValue, propertyUnknown(arg1), arg1); 1270 } 1271 1272 /** 1273 * @internal 1274 * @brief Formats NoValidSession message into JSON 1275 * 1276 * See header file for more information 1277 * @endinternal 1278 */ 1279 nlohmann::json noValidSession(void) 1280 { 1281 return getLog(redfish::registries::base::Index::noValidSession, {}); 1282 } 1283 1284 void noValidSession(crow::Response& res) 1285 { 1286 res.result(boost::beast::http::status::forbidden); 1287 addMessageToErrorJson(res.jsonValue, noValidSession()); 1288 } 1289 1290 /** 1291 * @internal 1292 * @brief Formats InvalidObject message into JSON 1293 * 1294 * See header file for more information 1295 * @endinternal 1296 */ 1297 nlohmann::json invalidObject(const boost::urls::url_view& arg1) 1298 { 1299 std::string_view arg1str(arg1.data(), arg1.size()); 1300 return getLog(redfish::registries::base::Index::invalidObject, 1301 std::to_array({arg1str})); 1302 } 1303 1304 void invalidObject(crow::Response& res, const boost::urls::url_view& arg1) 1305 { 1306 res.result(boost::beast::http::status::bad_request); 1307 addMessageToErrorJson(res.jsonValue, invalidObject(arg1)); 1308 } 1309 1310 /** 1311 * @internal 1312 * @brief Formats ResourceInStandby message into JSON 1313 * 1314 * See header file for more information 1315 * @endinternal 1316 */ 1317 nlohmann::json resourceInStandby(void) 1318 { 1319 return getLog(redfish::registries::base::Index::resourceInStandby, {}); 1320 } 1321 1322 void resourceInStandby(crow::Response& res) 1323 { 1324 res.result(boost::beast::http::status::service_unavailable); 1325 addMessageToErrorJson(res.jsonValue, resourceInStandby()); 1326 } 1327 1328 /** 1329 * @internal 1330 * @brief Formats ActionParameterValueTypeError message into JSON 1331 * 1332 * See header file for more information 1333 * @endinternal 1334 */ 1335 nlohmann::json actionParameterValueTypeError(std::string_view arg1, 1336 std::string_view arg2, 1337 std::string_view arg3) 1338 { 1339 return getLog( 1340 redfish::registries::base::Index::actionParameterValueTypeError, 1341 std::to_array({arg1, arg2, arg3})); 1342 } 1343 1344 void actionParameterValueTypeError(crow::Response& res, std::string_view arg1, 1345 std::string_view arg2, std::string_view arg3) 1346 { 1347 res.result(boost::beast::http::status::bad_request); 1348 addMessageToErrorJson(res.jsonValue, 1349 actionParameterValueTypeError(arg1, arg2, arg3)); 1350 } 1351 1352 /** 1353 * @internal 1354 * @brief Formats SessionLimitExceeded message into JSON 1355 * 1356 * See header file for more information 1357 * @endinternal 1358 */ 1359 nlohmann::json sessionLimitExceeded(void) 1360 { 1361 return getLog(redfish::registries::base::Index::sessionLimitExceeded, {}); 1362 } 1363 1364 void sessionLimitExceeded(crow::Response& res) 1365 { 1366 res.result(boost::beast::http::status::service_unavailable); 1367 addMessageToErrorJson(res.jsonValue, sessionLimitExceeded()); 1368 } 1369 1370 /** 1371 * @internal 1372 * @brief Formats ActionNotSupported message into JSON 1373 * 1374 * See header file for more information 1375 * @endinternal 1376 */ 1377 nlohmann::json actionNotSupported(std::string_view arg1) 1378 { 1379 return getLog(redfish::registries::base::Index::actionNotSupported, 1380 std::to_array({arg1})); 1381 } 1382 1383 void actionNotSupported(crow::Response& res, std::string_view arg1) 1384 { 1385 res.result(boost::beast::http::status::bad_request); 1386 addMessageToErrorJson(res.jsonValue, actionNotSupported(arg1)); 1387 } 1388 1389 /** 1390 * @internal 1391 * @brief Formats InvalidIndex message into JSON 1392 * 1393 * See header file for more information 1394 * @endinternal 1395 */ 1396 nlohmann::json invalidIndex(int64_t arg1) 1397 { 1398 std::string arg1Str = std::to_string(arg1); 1399 return getLog(redfish::registries::base::Index::invalidIndex, 1400 std::to_array<std::string_view>({arg1Str})); 1401 } 1402 1403 void invalidIndex(crow::Response& res, int64_t arg1) 1404 { 1405 res.result(boost::beast::http::status::bad_request); 1406 addMessageToErrorJson(res.jsonValue, invalidIndex(arg1)); 1407 } 1408 1409 /** 1410 * @internal 1411 * @brief Formats EmptyJSON message into JSON 1412 * 1413 * See header file for more information 1414 * @endinternal 1415 */ 1416 nlohmann::json emptyJSON(void) 1417 { 1418 return getLog(redfish::registries::base::Index::emptyJSON, {}); 1419 } 1420 1421 void emptyJSON(crow::Response& res) 1422 { 1423 res.result(boost::beast::http::status::bad_request); 1424 addMessageToErrorJson(res.jsonValue, emptyJSON()); 1425 } 1426 1427 /** 1428 * @internal 1429 * @brief Formats QueryNotSupportedOnResource message into JSON 1430 * 1431 * See header file for more information 1432 * @endinternal 1433 */ 1434 nlohmann::json queryNotSupportedOnResource(void) 1435 { 1436 return getLog(redfish::registries::base::Index::queryNotSupportedOnResource, 1437 {}); 1438 } 1439 1440 void queryNotSupportedOnResource(crow::Response& res) 1441 { 1442 res.result(boost::beast::http::status::forbidden); 1443 addMessageToErrorJson(res.jsonValue, queryNotSupportedOnResource()); 1444 } 1445 1446 /** 1447 * @internal 1448 * @brief Formats QueryNotSupportedOnOperation message into JSON 1449 * 1450 * See header file for more information 1451 * @endinternal 1452 */ 1453 nlohmann::json queryNotSupportedOnOperation(void) 1454 { 1455 return getLog( 1456 redfish::registries::base::Index::queryNotSupportedOnOperation, {}); 1457 } 1458 1459 void queryNotSupportedOnOperation(crow::Response& res) 1460 { 1461 res.result(boost::beast::http::status::forbidden); 1462 addMessageToErrorJson(res.jsonValue, queryNotSupportedOnOperation()); 1463 } 1464 1465 /** 1466 * @internal 1467 * @brief Formats QueryCombinationInvalid message into JSON 1468 * 1469 * See header file for more information 1470 * @endinternal 1471 */ 1472 nlohmann::json queryCombinationInvalid(void) 1473 { 1474 return getLog(redfish::registries::base::Index::queryCombinationInvalid, 1475 {}); 1476 } 1477 1478 void queryCombinationInvalid(crow::Response& res) 1479 { 1480 res.result(boost::beast::http::status::bad_request); 1481 addMessageToErrorJson(res.jsonValue, queryCombinationInvalid()); 1482 } 1483 1484 /** 1485 * @internal 1486 * @brief Formats InsufficientPrivilege message into JSON 1487 * 1488 * See header file for more information 1489 * @endinternal 1490 */ 1491 nlohmann::json insufficientPrivilege(void) 1492 { 1493 return getLog(redfish::registries::base::Index::insufficientPrivilege, {}); 1494 } 1495 1496 void insufficientPrivilege(crow::Response& res) 1497 { 1498 res.result(boost::beast::http::status::forbidden); 1499 addMessageToErrorJson(res.jsonValue, insufficientPrivilege()); 1500 } 1501 1502 /** 1503 * @internal 1504 * @brief Formats PropertyValueModified message into JSON 1505 * 1506 * See header file for more information 1507 * @endinternal 1508 */ 1509 nlohmann::json propertyValueModified(std::string_view arg1, 1510 std::string_view arg2) 1511 { 1512 return getLog(redfish::registries::base::Index::propertyValueModified, 1513 std::to_array({arg1, arg2})); 1514 } 1515 1516 void propertyValueModified(crow::Response& res, std::string_view arg1, 1517 std::string_view arg2) 1518 { 1519 res.result(boost::beast::http::status::ok); 1520 addMessageToJson(res.jsonValue, propertyValueModified(arg1, arg2), arg1); 1521 } 1522 1523 /** 1524 * @internal 1525 * @brief Formats AccountNotModified message into JSON 1526 * 1527 * See header file for more information 1528 * @endinternal 1529 */ 1530 nlohmann::json accountNotModified(void) 1531 { 1532 return getLog(redfish::registries::base::Index::accountNotModified, {}); 1533 } 1534 1535 void accountNotModified(crow::Response& res) 1536 { 1537 res.result(boost::beast::http::status::bad_request); 1538 addMessageToErrorJson(res.jsonValue, accountNotModified()); 1539 } 1540 1541 /** 1542 * @internal 1543 * @brief Formats QueryParameterValueFormatError message into JSON 1544 * 1545 * See header file for more information 1546 * @endinternal 1547 */ 1548 nlohmann::json queryParameterValueFormatError(std::string_view arg1, 1549 std::string_view arg2) 1550 { 1551 return getLog( 1552 redfish::registries::base::Index::queryParameterValueFormatError, 1553 std::to_array({arg1, arg2})); 1554 } 1555 1556 void queryParameterValueFormatError(crow::Response& res, std::string_view arg1, 1557 std::string_view arg2) 1558 { 1559 res.result(boost::beast::http::status::bad_request); 1560 addMessageToErrorJson(res.jsonValue, 1561 queryParameterValueFormatError(arg1, arg2)); 1562 } 1563 1564 /** 1565 * @internal 1566 * @brief Formats PropertyMissing message into JSON for the specified 1567 * property 1568 * 1569 * See header file for more information 1570 * @endinternal 1571 */ 1572 nlohmann::json propertyMissing(std::string_view arg1) 1573 { 1574 return getLog(redfish::registries::base::Index::propertyMissing, 1575 std::to_array({arg1})); 1576 } 1577 1578 void propertyMissing(crow::Response& res, std::string_view arg1) 1579 { 1580 res.result(boost::beast::http::status::bad_request); 1581 addMessageToJson(res.jsonValue, propertyMissing(arg1), arg1); 1582 } 1583 1584 /** 1585 * @internal 1586 * @brief Formats ResourceExhaustion message into JSON 1587 * 1588 * See header file for more information 1589 * @endinternal 1590 */ 1591 nlohmann::json resourceExhaustion(std::string_view arg1) 1592 { 1593 return getLog(redfish::registries::base::Index::resourceExhaustion, 1594 std::to_array({arg1})); 1595 } 1596 1597 void resourceExhaustion(crow::Response& res, std::string_view arg1) 1598 { 1599 res.result(boost::beast::http::status::service_unavailable); 1600 addMessageToErrorJson(res.jsonValue, resourceExhaustion(arg1)); 1601 } 1602 1603 /** 1604 * @internal 1605 * @brief Formats AccountModified message into JSON 1606 * 1607 * See header file for more information 1608 * @endinternal 1609 */ 1610 nlohmann::json accountModified(void) 1611 { 1612 return getLog(redfish::registries::base::Index::accountModified, {}); 1613 } 1614 1615 void accountModified(crow::Response& res) 1616 { 1617 res.result(boost::beast::http::status::ok); 1618 addMessageToErrorJson(res.jsonValue, accountModified()); 1619 } 1620 1621 /** 1622 * @internal 1623 * @brief Formats QueryParameterOutOfRange message into JSON 1624 * 1625 * See header file for more information 1626 * @endinternal 1627 */ 1628 nlohmann::json queryParameterOutOfRange(std::string_view arg1, 1629 std::string_view arg2, 1630 std::string_view arg3) 1631 { 1632 return getLog(redfish::registries::base::Index::queryParameterOutOfRange, 1633 std::to_array({arg1, arg2, arg3})); 1634 } 1635 1636 void queryParameterOutOfRange(crow::Response& res, std::string_view arg1, 1637 std::string_view arg2, std::string_view arg3) 1638 { 1639 res.result(boost::beast::http::status::bad_request); 1640 addMessageToErrorJson(res.jsonValue, 1641 queryParameterOutOfRange(arg1, arg2, arg3)); 1642 } 1643 1644 nlohmann::json passwordChangeRequired(const boost::urls::url_view& arg1) 1645 { 1646 std::string_view arg1str(arg1.data(), arg1.size()); 1647 return getLog(redfish::registries::base::Index::passwordChangeRequired, 1648 std::to_array({arg1str})); 1649 } 1650 1651 /** 1652 * @internal 1653 * @brief Formats PasswordChangeRequired message into JSON 1654 * 1655 * See header file for more information 1656 * @endinternal 1657 */ 1658 void passwordChangeRequired(crow::Response& res, 1659 const boost::urls::url_view& arg1) 1660 { 1661 messages::addMessageToJsonRoot(res.jsonValue, passwordChangeRequired(arg1)); 1662 } 1663 1664 void invalidUpload(crow::Response& res, std::string_view arg1, 1665 std::string_view arg2) 1666 { 1667 res.result(boost::beast::http::status::bad_request); 1668 addMessageToErrorJson(res.jsonValue, invalidUpload(arg1, arg2)); 1669 } 1670 1671 /** 1672 * @internal 1673 * @brief Formats Invalid File message into JSON 1674 * 1675 * See header file for more information 1676 * @endinternal 1677 */ 1678 nlohmann::json invalidUpload(std::string_view arg1, std::string_view arg2) 1679 { 1680 std::string msg = "Invalid file uploaded to "; 1681 msg += arg1; 1682 msg += ": "; 1683 msg += arg2; 1684 msg += "."; 1685 return nlohmann::json{ 1686 {"@odata.type", "/redfish/v1/$metadata#Message.v1_1_1.Message"}, 1687 {"MessageId", "OpenBMC.0.2.InvalidUpload"}, 1688 {"Message", std::move(msg)}, 1689 {"MessageArgs", {arg1, arg2}}, 1690 {"MessageSeverity", "Warning"}, 1691 {"Resolution", "None."}}; 1692 } 1693 } // namespace messages 1694 1695 } // namespace redfish 1696