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