blob: adfec9417eecbc09075a9d34cb57be45d88608e7 [file]
#pragma once
#include <memory>
#include "absl/status/status.h"
#include "absl/status/statusor.h"
#include "redfish_query_engine/http/client.h"
#include "redfish_query_engine/http/curl_client.h"
#include "proxy_config.pb.h"
#include "redfish_plugin.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,
ecclesia::HttpClient::HttpRequest&) override {
if (verb == RedfishPlugin::RequestVerb::kInternal) {
return RequestAction::kDrop;
}
return RequestAction::kHandle;
}
absl::StatusOr<ecclesia::HttpClient::HttpResponse> HandleRequest(
RedfishPlugin::RequestVerb verb,
std::unique_ptr<ecclesia::HttpClient::HttpRequest> request) override;
absl::Status Subscribe(std::unique_ptr<ecclesia::HttpClient::HttpRequest>,
EventHandler* handler) override;
absl::Status Initialize(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:
RedfishPassthroughPlugin(
const milotic_grpc_proxy::Plugin::RedfishPassthrough& config);
private:
ecclesia::CurlHttpClient curl_http_client_;
ecclesia::CurlHttpClient subscribe_curl_http_client_;
};
} // namespace milotic