| #ifndef THIRD_PARTY_MILOTIC_EXTERNAL_CC_TLBMC_REDFISH_QUERY_PARAMETERS_H_ |
| #define THIRD_PARTY_MILOTIC_EXTERNAL_CC_TLBMC_REDFISH_QUERY_PARAMETERS_H_ |
| |
| #include <cstdint> |
| #include <string> |
| #include <vector> |
| |
| #include "absl/status/statusor.h" |
| #include "absl/strings/str_cat.h" |
| #include "boost/url/params_view.hpp" |
| #include "nlohmann/json.hpp" |
| |
| namespace milotic_tlbmc { |
| |
| struct ExpandNode { |
| nlohmann::json::json_pointer json_pointer; |
| std::string url; |
| |
| std::string DebugString() const { |
| return absl::StrCat(json_pointer.to_string(), ":", url); |
| } |
| |
| bool operator==(const ExpandNode& other) const { |
| return json_pointer == other.json_pointer && url == other.url; |
| } |
| }; |
| |
| enum class ExpandType : std::uint8_t { |
| kNone = 0, |
| kNoLinks, |
| kLinksOnly, |
| kAll, |
| }; |
| |
| struct ExpandInfo { |
| int expand_level = 0; |
| ExpandType expand_type = ExpandType::kNone; |
| }; |
| |
| std::string ExpandTypeToUrlParam(ExpandType expand_type); |
| |
| class QueryParameters { |
| public: |
| QueryParameters() = default; |
| |
| static absl::StatusOr<QueryParameters> Create( |
| boost::urls::params_view query_parameters); |
| |
| void SetExpandLevel(int expand_level) { |
| expand_info_.expand_level = expand_level; |
| } |
| |
| void SetExpandType(ExpandType expand_type) { |
| expand_info_.expand_type = expand_type; |
| } |
| |
| int GetExpandLevel() const { return expand_info_.expand_level; } |
| ExpandType GetExpandType() const { return expand_info_.expand_type; } |
| |
| private: |
| ExpandInfo expand_info_; |
| }; |
| |
| // Helper method to extract all unexpanded URLs from a RedfishResponse Json. |
| std::vector<ExpandNode> GetUnexpandedUrls(const nlohmann::json& resp, |
| ExpandType expand_type); |
| |
| } // namespace milotic_tlbmc |
| |
| #endif // THIRD_PARTY_MILOTIC_EXTERNAL_CC_TLBMC_REDFISH_QUERY_PARAMETERS_H_ |