blob: 84670c683b92750b058c28c15b2914ce84d6a91e [file] [log] [blame]
#ifndef THIRD_PARTY_MILOTIC_EXTERNAL_CC_TLBMC_REDFISH_EXPAND_QUERY_AGGREGATOR_H_
#define THIRD_PARTY_MILOTIC_EXTERNAL_CC_TLBMC_REDFISH_EXPAND_QUERY_AGGREGATOR_H_
#include <memory>
#include <string>
#include <utility>
#include "absl/strings/str_cat.h"
#include "absl/strings/string_view.h"
#include "nlohmann/json_fwd.hpp"
#include "tlbmc/redfish/query_parameters.h"
#include "dbus_utility.hpp" // NOLINT
#include "async_resp.hpp" // NOLINT
#include "http_request.hpp" // NOLINT
#include "router_interface.h"
namespace milotic_tlbmc {
constexpr absl::string_view kDefaultErrorMessage =
"A general error has occurred. See Resolution for information on how to "
"resolve the error.";
constexpr absl::string_view kDefaultErrorCode = "Base.1.11.0.GeneralError";
struct ErrorInformation {
std::string error_message = std::string(kDefaultErrorMessage);
std::string error_code = std::string(kDefaultErrorCode);
nlohmann::json::array_t extended_info;
};
// This class will be in charge of aggregating the responses from the expand
// query.
// This class references the implmentation in openbmc gbmcweb.
// https://gbmc.googlesource.com/gbmcweb/+/refs/heads/master/redfish-core/include/query.cpp#742
class ExpandQueryAggregator
: public std::enable_shared_from_this<ExpandQueryAggregator> {
public:
ExpandQueryAggregator() = default;
ExpandQueryAggregator(std::shared_ptr<bmcweb::AsyncResp> final_async_resp,
::crow::RouterInterface* router,
const QueryParameters& query_parameters)
: final_async_resp_(std::move(final_async_resp)),
smart_router_(router),
query_parameters_(query_parameters) {}
void StartQuery();
protected:
static ErrorInformation GetErrorInformation(
const nlohmann::json& response_json);
void PropagateErrorMessage(nlohmann::json& sub_response_json);
std::string CreateExpandQueryUrl(absl::string_view url,
const ExpandNode& expand_node);
void AddResponseToFinalResponse(const ExpandNode& expand_node,
::crow::Response& sub_response);
unsigned DetermineFinalErrorCode(unsigned sub_response_code);
std::shared_ptr<bmcweb::AsyncResp> final_async_resp_;
::crow::RouterInterface* smart_router_;
const QueryParameters query_parameters_;
};
} // namespace milotic_tlbmc
#endif // THIRD_PARTY_MILOTIC_EXTERNAL_CC_TLBMC_REDFISH_EXPAND_QUERY_AGGREGATOR_H_