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