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