blob: d838cc95129326d7221cf6178f59680936225a61 [file] [log] [blame]
#ifndef PLATFORMS_SYSHEALTH_COLLECTION_FEED_FORWARD_CLIENT_LIB_FEED_CLIENT_GRPC_H_
#define PLATFORMS_SYSHEALTH_COLLECTION_FEED_FORWARD_CLIENT_LIB_FEED_CLIENT_GRPC_H_
#include <memory>
#include <utility>
#include "tlbmc/feed_client.pb.h"
#include "tlbmc/feed_client_interface.h"
#include "agent_config_service.grpc.pb.h"
#include "data_sink_service.grpc.pb.h"
#include "absl/status/statusor.h"
#include "absl/strings/string_view.h"
#include "grpcpp/security/credentials.h"
namespace platforms_syshealth::collection::feed {
// If its bazel build then use
// platforms_syshealth::collection::feed::grpc::DataSinkService::StubInterface
// else use grpc::DataSinkService::StubInterface;
#if defined(BAZEL_BUILD)
using DataSinkService = grpc::DataSinkService;
using AgentConfigService = grpc::AgentConfigService;
#else
using DataSinkService = platforms_syshealth::collection::feed::DataSinkService;
using AgentConfigService =
platforms_syshealth::collection::feed::AgentConfigService;
#endif
class FeedClientGrpc : public FeedClientInterface {
public:
FeedClientGrpc(
const FeedClientConfig& config,
const std::shared_ptr<::grpc::ChannelCredentials>& credentials);
// For testing only.
FeedClientGrpc(
std::unique_ptr<DataSinkService::StubInterface> stub,
std::unique_ptr<AgentConfigService::StubInterface> agent_config_stub)
: stub_(std::move(stub)),
agent_config_stub_(std::move(agent_config_stub)),
dry_run_(false) {}
absl::StatusOr<WriteMetricsResponse> WriteMetrics(
const WriteMetricsRequest& request) override;
absl::StatusOr<GetPoliciesResponse> GetPolicies(
const GetPoliciesRequest& request) override;
void SetTargetAddress(absl::string_view target_address) override;
bool IsDryRun() const override { return dry_run_; };
private:
void InitStubs();
FeedClientConfig config_;
std::shared_ptr<::grpc::ChannelCredentials> credentials_;
std::unique_ptr<DataSinkService::StubInterface> stub_;
std::unique_ptr<AgentConfigService::StubInterface> agent_config_stub_;
bool dry_run_ = true;
};
} // namespace platforms_syshealth::collection::feed
#endif // PLATFORMS_SYSHEALTH_COLLECTION_FEED_FORWARD_CLIENT_LIB_FEED_CLIENT_GRPC_H_