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