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