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