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