| #pragma once |
| |
| #include <memory> |
| |
| #include "absl/status/status.h" |
| #include "absl/status/statusor.h" |
| #include "redfish_query_engine/http/client.h" |
| #include "http_client_pool.h" |
| #include "proxy_config.pb.h" |
| #include "redfish_plugin.h" |
| #include "request_response.h" |
| |
| namespace milotic { |
| |
| // Implements backend of RedfishPlugin, sending requests as http. |
| // HandleRequest runs synchronously, but can be called by multiple threads |
| // simultaneously after initialization. |
| // Example: |
| // RedfishPlugin *redfish_plugin = new RedfishPassthroughPlugin(); |
| // redfish_plugin->Initialize("localhost:8889"); |
| // absl::Status status = redfish_plugin->HandleRequest( |
| // RedfishPlugin::RequestVerb::Get, |
| // request, |
| // response); |
| // return status; |
| class RedfishPassthroughPluginBase : public RedfishPlugin { |
| protected: |
| RedfishPassthroughPluginBase(ecclesia::HttpClient* http_client, |
| ecclesia::HttpClient* subscribe_http_client) |
| : http_client_(*http_client), |
| subscribe_http_client_(*subscribe_http_client) {} |
| |
| public: |
| virtual ~RedfishPassthroughPluginBase() = default; |
| |
| RequestAction PreprocessRequest(RedfishPlugin::RequestVerb verb, |
| ProxyRequest& /*request*/) override { |
| if (verb == RedfishPlugin::RequestVerb::kInternal) { |
| return RequestAction::kDrop; |
| } |
| return RequestAction::kHandle; |
| } |
| |
| absl::StatusOr<ProxyResponse> HandleRequest( |
| RedfishPlugin::RequestVerb verb, |
| std::unique_ptr<ProxyRequest> request) override; |
| |
| absl::Status Subscribe(std::unique_ptr<ProxyRequest> /*request*/, |
| EventHandler* handler) override; |
| |
| absl::Status Initialize(Proxy* /*proxy*/) override; |
| |
| RedfishPassthroughPluginBase(const RedfishPassthroughPluginBase&) = delete; |
| RedfishPassthroughPluginBase& operator=(const RedfishPassthroughPluginBase&) = |
| delete; |
| |
| private: |
| ecclesia::HttpClient& http_client_; |
| ecclesia::HttpClient& subscribe_http_client_; |
| }; |
| |
| class RedfishPassthroughPlugin : public RedfishPassthroughPluginBase { |
| public: |
| explicit RedfishPassthroughPlugin( |
| const milotic_grpc_proxy::Plugin::RedfishPassthrough& config); |
| |
| private: |
| HttpClientPool curl_http_client_; |
| HttpClientPool subscribe_curl_http_client_; |
| }; |
| |
| } // namespace milotic |