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