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