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