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