Jan_31_2024-Dev

This commit is contained in:
Ned Wright
2024-01-31 17:34:53 +00:00
parent 752a5785f0
commit 6d67818a94
376 changed files with 8101 additions and 7064 deletions

View File

@@ -12,7 +12,7 @@ add_subdirectory(rest)
add_subdirectory(report)
add_subdirectory(logging)
add_subdirectory(connkey)
add_subdirectory(message)
add_subdirectory(messaging)
add_subdirectory(config)
add_subdirectory(agent_details)
add_subdirectory(event_is)
@@ -25,7 +25,6 @@ add_subdirectory(shm_pkt_queue)
add_subdirectory(instance_awareness)
add_subdirectory(socket_is)
add_subdirectory(agent_details_reporter)
add_subdirectory(messaging_buffer)
add_subdirectory(metric)
add_subdirectory(version)
add_subdirectory(tenant_manager)
@@ -36,9 +35,9 @@ add_library(ngen_core SHARED ".")
target_link_libraries(
ngen_core
-Wl,-whole-archive
"table;debug_is;shell_cmd;metric;tenant_manager;message;encryptor;time_proxy;singleton;mainloop;environment;logging;report;rest"
"table;debug_is;shell_cmd;metric;tenant_manager;messaging;encryptor;time_proxy;singleton;mainloop;environment;logging;report;rest"
"config;intelligence_is_v2;event_is;memory_consumption;connkey"
"instance_awareness;socket_is;messaging_buffer;agent_details;agent_details_reporter;buffers;cpu;agent_core_utilities"
"instance_awareness;socket_is;agent_details;agent_details_reporter;buffers;cpu;agent_core_utilities"
-Wl,-no-whole-archive
)

0
core/agent_core_utilities/agent_core_utilities.cc Executable file → Normal file
View File

View File

@@ -3,5 +3,5 @@ include_directories(${CMAKE_SOURCE_DIR}/cptest/include)
add_unit_test(
agent_core_utilities_ut
"agent_core_utilities_ut.cc"
"agent_core_utilities;shell_cmd;config;time_proxy;-lboost_regex"
"agent_core_utilities;shell_cmd;messaging;config;time_proxy;-lboost_regex"
)

4
core/agent_details/agent_details.cc Executable file → Normal file
View File

@@ -27,6 +27,7 @@ using namespace std;
USE_DEBUG_FLAG(D_ORCHESTRATOR);
const map<string, I_AgentDetails::MachineType> AgentDetails::machineTypes({
{ "Amazon EC2", I_AgentDetails::MachineType::AWS },
{ "Xen", I_AgentDetails::MachineType::AWS },
@@ -466,6 +467,7 @@ AgentDetails::loadProxyType(const string &proxy_type)
Maybe<void>
AgentDetails::loadProxyType(ProxyProtocol protocol)
{
dbgFlow(D_ORCHESTRATOR) << "Loading proxy type: " << convertProxyProtocolToString(protocol);
dbgAssert(protocol == ProxyProtocol::HTTP || protocol == ProxyProtocol::HTTPS)
<< "Unsupported Proxy Protocol " << static_cast<int>(protocol);
@@ -537,7 +539,7 @@ AgentDetails::getProxyDomain(ProxyProtocol protocol) const
}
Maybe<string>
AgentDetails::getProxyCredentials(ProxyProtocol protocol) const
AgentDetails::getProxyAuthentication(ProxyProtocol protocol) const
{
if (proxies.find(protocol) == proxies.end()) {
return genError("Proxy type is not loaded in map, type: " + convertProxyProtocolToString(protocol));

View File

@@ -228,35 +228,37 @@ AgentDetailsReporter::Impl::sendAttributes()
if (is_server) {
AttrSerializer<ofstream, cereal::JSONOutputArchive>(attributes, "save");
messaging->sendObjectWithPersistence(attr_to_send, I_Messaging::Method::PATCH, "/agents");
messaging->sendAsyncMessage(HTTPMethod::PATCH, "/agents", attr_to_send);
dbgDebug(D_AGENT_DETAILS) << "Triggered persistent message request with attributes to the Fog";
new_attributes.clear();
return true;
}
for (uint retry = 3; retry > 0; retry--) {
::Flags<MessageConnConfig> conn_flags;
conn_flags.setFlag(MessageConnConfig::ONE_TIME_CONN);
bool is_success = messaging->sendObject(
MessageMetadata add_agent_details_req_md("127.0.0.1", 7777);
add_agent_details_req_md.setConnectioFlag(MessageConnectionConfig::ONE_TIME_CONN);
add_agent_details_req_md.setConnectioFlag(MessageConnectionConfig::UNSECURE_CONN);
auto add_agent_details_status = messaging->sendSyncMessage(
HTTPMethod::POST,
"add-agent-details-attr",
attr_to_send,
I_Messaging::Method::POST,
"127.0.0.1",
7777, // primary Orchestrator's port
conn_flags,
"add-agent-details-attr"
MessageCategory::GENERIC,
add_agent_details_req_md
);
if (!is_success) {
is_success = messaging->sendObject(
if (!add_agent_details_status.ok()) {
MessageMetadata secondary_port_req_md("127.0.0.1", 7778);
secondary_port_req_md.setConnectioFlag(MessageConnectionConfig::ONE_TIME_CONN);
secondary_port_req_md.setConnectioFlag(MessageConnectionConfig::UNSECURE_CONN);
add_agent_details_status = messaging->sendSyncMessage(
HTTPMethod::POST,
"add-agent-details-attr",
attr_to_send,
I_Messaging::Method::POST,
"127.0.0.1",
7778, // secondary Orchestrator's port
conn_flags,
"add-agent-details-attr"
MessageCategory::GENERIC,
secondary_port_req_md
);
}
if (is_success) {
if (add_agent_details_status.ok()) {
dbgDebug(D_AGENT_DETAILS) << "Successfully sent attributes to the Orchestrator";
new_attributes.clear();
return true;
@@ -390,7 +392,7 @@ AgentDetailsReporter::Impl::sendReport(
additional_metadata.setAdditionalAttributes(attributes);
}
messaging->sendObjectWithPersistence(additional_metadata, I_Messaging::Method::PATCH, "/agents");
messaging->sendAsyncMessage(HTTPMethod::PATCH, "/agents", additional_metadata);
}
AgentDetailsReporter::AgentDetailsReporter()

View File

@@ -3,5 +3,5 @@ link_directories(${BOOST_ROOT}/lib)
add_unit_test(
agent_details_reporter_ut
"agent_details_reporter_ut.cc"
"environment;config;rest;event_is;metric;agent_details_reporter;-lboost_regex"
"environment;messaging;config;rest;event_is;metric;agent_details_reporter;-lboost_regex"
)

View File

@@ -86,44 +86,34 @@ public:
TEST_F(AgentReporterTest, dataReport)
{
string custom_data = "Linux version 24.00.15F";
EXPECT_CALL(
mock_messaging,
mockSendPersistentMessage(
_,
"{\n"
" \"additionalMetaData\": {\n"
" \"custom_data\": \"Linux version 24.00.15F\"\n"
" }"
"\n}",
I_Messaging::Method::PATCH,
"/agents",
_,
_,
MessageTypeTag::GENERIC
)
).WillOnce(Return(string()));
EXPECT_CALL(mock_messaging, sendAsyncMessage(
HTTPMethod::PATCH,
"/agents",
"{\n"
" \"additionalMetaData\": {\n"
" \"custom_data\": \"Linux version 24.00.15F\"\n"
" }"
"\n}",
MessageCategory::GENERIC,
_
)).Times(1);
AgentDataReport() << AgentReportField(custom_data);;
}
TEST_F(AgentReporterTest, labeledDataReport)
{
string data = "Linux version 24.00.15F";
EXPECT_CALL(
mock_messaging,
mockSendPersistentMessage(
_,
"{\n"
" \"additionalMetaData\": {\n"
" \"this_is_custom_label\": \"Linux version 24.00.15F\"\n"
" }"
"\n}",
I_Messaging::Method::PATCH,
"/agents",
_,
_,
MessageTypeTag::GENERIC
)
).WillOnce(Return(string()));
EXPECT_CALL(mock_messaging, sendAsyncMessage(
HTTPMethod::PATCH,
"/agents",
"{\n"
" \"additionalMetaData\": {\n"
" \"this_is_custom_label\": \"Linux version 24.00.15F\"\n"
" }"
"\n}",
MessageCategory::GENERIC,
_
)).Times(1);
AgentDataReport() << AgentReportFieldWithLabel("this_is_custom_label", data);
}
@@ -131,24 +121,18 @@ TEST_F(AgentReporterTest, multiDataReport)
{
string custom_data = "Linux version 24.00.15F";
string data_to_report = "Agent Version 95.95.95.00A";
EXPECT_CALL(
mock_messaging,
mockSendPersistentMessage(
_,
"{\n"
" \"additionalMetaData\": {\n"
" \"custom_data\": \"Linux version 24.00.15F\",\n"
" \"this_is_custom_label\": \"Agent Version 95.95.95.00A\"\n"
" }"
"\n}",
I_Messaging::Method::PATCH,
"/agents",
_,
_,
MessageTypeTag::GENERIC
)
).WillOnce(Return(string()));
EXPECT_CALL(mock_messaging, sendAsyncMessage(
HTTPMethod::PATCH,
"/agents",
"{\n"
" \"additionalMetaData\": {\n"
" \"custom_data\": \"Linux version 24.00.15F\",\n"
" \"this_is_custom_label\": \"Agent Version 95.95.95.00A\"\n"
" }"
"\n}",
MessageCategory::GENERIC,
_
)).Times(1);
AgentDataReport()
<< AgentReportField(custom_data)
@@ -160,27 +144,22 @@ TEST_F(AgentReporterTest, multiDataReportWithRegistrationData)
string custom_data = "Linux version 24.00.15F";
string data_to_report = "Agent Version 95.95.95.00A";
EXPECT_CALL(
mock_messaging,
mockSendPersistentMessage(
_,
"{\n"
" \"additionalMetaData\": {\n"
" \"custom_data\": \"Linux version 24.00.15F\",\n"
" \"this_is_custom_label\": \"Agent Version 95.95.95.00A\"\n"
" },\n"
" \"agentVersion\": \"1.15.9\",\n"
" \"policyVersion\": \"ccc\",\n"
" \"platform\": \"bbb\",\n"
" \"architecture\": \"aaa\"\n"
"}",
I_Messaging::Method::PATCH,
"/agents",
_,
_,
MessageTypeTag::GENERIC
)
).WillOnce(Return(string()));
EXPECT_CALL(mock_messaging, sendAsyncMessage(
HTTPMethod::PATCH,
"/agents",
"{\n"
" \"additionalMetaData\": {\n"
" \"custom_data\": \"Linux version 24.00.15F\",\n"
" \"this_is_custom_label\": \"Agent Version 95.95.95.00A\"\n"
" },\n"
" \"agentVersion\": \"1.15.9\",\n"
" \"policyVersion\": \"ccc\",\n"
" \"platform\": \"bbb\",\n"
" \"architecture\": \"aaa\"\n"
"}",
MessageCategory::GENERIC,
_
)).Times(1);
AgentDataReport agent_data;
agent_data
@@ -195,44 +174,34 @@ TEST_F(AgentReporterTest, multiDataReportWithRegistrationData)
TEST_F(AgentReporterTest, basicAttrTest)
{
EXPECT_CALL(
mock_messaging,
mockSendPersistentMessage(
_,
"{\n"
" \"additionalMetaData\": {}\n"
"}",
I_Messaging::Method::PATCH,
"/agents",
_,
_,
MessageTypeTag::GENERIC
)
).WillOnce(Return(string()));
EXPECT_CALL(mock_messaging, sendAsyncMessage(
HTTPMethod::PATCH,
"/agents",
"{\n"
" \"additionalMetaData\": {}\n"
"}",
MessageCategory::GENERIC,
_
)).Times(1);
{
AgentDataReport agent_data;
}
EXPECT_CALL(
mock_messaging,
mockSendPersistentMessage(
_,
"{\n"
" \"additionalMetaData\": {},\n"
" \"attributes\": {\n"
" \"1\": \"2\",\n"
" \"a\": \"1\",\n"
" \"c\": \"d\"\n"
" }\n"
"}",
I_Messaging::Method::PATCH,
"/agents",
_,
_,
MessageTypeTag::GENERIC
)
).WillOnce(Return(string()));
EXPECT_CALL(mock_messaging, sendAsyncMessage(
HTTPMethod::PATCH,
"/agents",
"{\n"
" \"additionalMetaData\": {},\n"
" \"attributes\": {\n"
" \"1\": \"2\",\n"
" \"a\": \"1\",\n"
" \"c\": \"d\"\n"
" }\n"
"}",
MessageCategory::GENERIC,
_
)).Times(1);
EXPECT_TRUE(report->addAttr("a", "b"));
EXPECT_TRUE(report->addAttr({{"c", "d"}, {"1", "2"}, {"delete", "me"}}));
@@ -243,20 +212,15 @@ TEST_F(AgentReporterTest, basicAttrTest)
AgentDataReport agent_data;
}
EXPECT_CALL(
mock_messaging,
mockSendPersistentMessage(
_,
"{\n"
" \"additionalMetaData\": {}\n"
"}",
I_Messaging::Method::PATCH,
"/agents",
_,
_,
MessageTypeTag::GENERIC
)
).WillOnce(Return(string()));
EXPECT_CALL(mock_messaging, sendAsyncMessage(
HTTPMethod::PATCH,
"/agents",
"{\n"
" \"additionalMetaData\": {}\n"
"}",
MessageCategory::GENERIC,
_
)).Times(1);
{
AgentDataReport agent_data;
@@ -271,25 +235,20 @@ TEST_F(AgentReporterTest, advancedAttrTest)
EXPECT_TRUE(report->addAttr({{"c", "d"}, {"1", "2"}, {"send", "me"}}));
EXPECT_TRUE(report->addAttr("a", "b"));
EXPECT_CALL(
mock_messaging,
mockSendPersistentMessage(
_,
"{\n"
" \"attributes\": {\n"
" \"1\": \"2\",\n"
" \"a\": \"b\",\n"
" \"c\": \"d\",\n"
" \"send\": \"me\"\n"
" }\n"
"}",
I_Messaging::Method::PATCH,
"/agents",
_,
_,
MessageTypeTag::GENERIC
)
).WillOnce(Return(string()));
EXPECT_CALL(mock_messaging, sendAsyncMessage(
HTTPMethod::PATCH,
"/agents",
"{\n"
" \"attributes\": {\n"
" \"1\": \"2\",\n"
" \"a\": \"b\",\n"
" \"c\": \"d\",\n"
" \"send\": \"me\"\n"
" }\n"
"}",
MessageCategory::GENERIC,
_
)).Times(1);
periodic_report();
@@ -300,26 +259,21 @@ TEST_F(AgentReporterTest, advancedAttrTest)
EXPECT_TRUE(report->addAttr("new", "key val"));
EXPECT_TRUE(report->addAttr("a", "key val override", true));
EXPECT_CALL(
mock_messaging,
mockSendPersistentMessage(
_,
"{\n"
" \"attributes\": {\n"
" \"1\": \"2\",\n"
" \"a\": \"key val override\",\n"
" \"c\": \"d\",\n"
" \"new\": \"key val\",\n"
" \"send\": \"me\"\n"
" }\n"
"}",
I_Messaging::Method::PATCH,
"/agents",
_,
_,
MessageTypeTag::GENERIC
)
).WillOnce(Return(string()));
EXPECT_CALL(mock_messaging, sendAsyncMessage(
HTTPMethod::PATCH,
"/agents",
"{\n"
" \"attributes\": {\n"
" \"1\": \"2\",\n"
" \"a\": \"key val override\",\n"
" \"c\": \"d\",\n"
" \"new\": \"key val\",\n"
" \"send\": \"me\"\n"
" }\n"
"}",
MessageCategory::GENERIC,
_
)).Times(1);
periodic_report();
}
@@ -338,35 +292,29 @@ TEST_F(AgentReporterTest, RestDetailsTest)
<< "}";
add_details_rest_cb->performRestCall(rest_call_parameters);
EXPECT_CALL(
mock_messaging,
mockSendPersistentMessage(
_,
rest_call_parameters.str(),
I_Messaging::Method::PATCH,
"/agents",
_,
_,
MessageTypeTag::GENERIC
)
).WillOnce(Return(string()));
EXPECT_CALL(mock_messaging, sendAsyncMessage(
HTTPMethod::PATCH,
"/agents",
rest_call_parameters.str(),
MessageCategory::GENERIC,
_
)).Times(1);
EXPECT_TRUE(report->sendAttributes());
is_server_mode = false;
EXPECT_CALL(mock_mainloop, addRecurringRoutine(_, _, _, "Report agent details attributes", _)).WillOnce(Return(2));
EXPECT_CALL(
mock_mainloop,
addRecurringRoutine(_, _, _, "Report agent details attributes", _)
).WillOnce(Return(2));
EXPECT_CALL(mock_rest, mockRestCall(RestAction::ADD, "agent-details-attr", _)).Times(0);
agent_details_reporter_comp.init();
EXPECT_TRUE(report->addAttr("new", "key val"));
::Flags<MessageConnConfig> conn_flags;
conn_flags.setFlag(MessageConnConfig::ONE_TIME_CONN);
EXPECT_CALL(
mock_messaging,
sendMessage(
true,
EXPECT_CALL(mock_messaging,
sendSyncMessage(
HTTPMethod::POST,
"add-agent-details-attr",
"{\n"
" \"attributes\": {\n"
" \"1\": \"2\",\n"
@@ -376,16 +324,13 @@ TEST_F(AgentReporterTest, RestDetailsTest)
" \"send\": \"me\"\n"
" }\n"
"}",
I_Messaging::Method::POST,
string("127.0.0.1"),
7777,
conn_flags,
string("add-agent-details-attr"),
string(),
_,
MessageTypeTag::GENERIC
_
)
).WillOnce(Return(Maybe<string>(string("{\"status\":true}"))));
).WillOnce(Return(HTTPResponse(HTTPStatusCode::HTTP_OK, "{\"status\":true}")));
agent_details_reporter_comp.init();
EXPECT_TRUE(report->addAttr("new", "key val"));
periodic_report();
}
@@ -416,19 +361,13 @@ TEST_F(AgentReporterTest, PersistenceAttrTest)
EXPECT_CALL(mock_rest, mockRestCall(RestAction::ADD, "agent-details-attr", _)).WillOnce(Return(true));
agent_details_reporter_comp.init();
EXPECT_CALL(
mock_messaging,
mockSendPersistentMessage(
_,
expected_attributes,
I_Messaging::Method::PATCH,
"/agents",
_,
_,
MessageTypeTag::GENERIC
)
).WillOnce(Return(string()));
EXPECT_CALL(mock_messaging, sendAsyncMessage(
HTTPMethod::PATCH,
"/agents",
expected_attributes,
MessageCategory::GENERIC,
_
)).Times(1);
EXPECT_TRUE(report->sendAttributes());
EXPECT_TRUE(report->addAttr("new attr", "to add before fini"));

0
core/buffers/buffer.cc Executable file → Normal file
View File

View File

@@ -3,5 +3,5 @@ link_directories(${BOOST_ROOT}/lib)
add_unit_test(
buffers_ut
"buffers_ut.cc;buffer_eval_ut.cc"
"buffers;event_is;metric;-lboost_regex"
"buffers;messaging;event_is;metric;-lboost_regex"
)

0
core/buffers/char_iterator.cc Executable file → Normal file
View File

0
core/buffers/data_container.cc Executable file → Normal file
View File

0
core/buffers/segment.cc Executable file → Normal file
View File

2
core/compression/compression_utils.cc Executable file → Normal file
View File

@@ -167,7 +167,7 @@ struct CompressionStream
basic_string<unsigned char> res;
int retries = 0;
while (stream.avail_in != 0) {
while (stream.avail_in != 0 || is_last_chunk) {
stream.avail_out = work_space.capacity();
stream.next_out = work_space.data();

View File

View File

@@ -199,27 +199,30 @@ private:
config_updates.expected_configurations = move(files);
I_Messaging *messaging = Singleton::Consume<I_Messaging>::by<ConfigComponent>();
::Flags<MessageConnConfig> conn_flags;
conn_flags.setFlag(MessageConnConfig::ONE_TIME_CONN);
bool is_success = messaging->sendObject(
MessageMetadata service_config_req_md("127.0.0.1", 7777);
service_config_req_md.setConnectioFlag(MessageConnectionConfig::ONE_TIME_CONN);
service_config_req_md.setConnectioFlag(MessageConnectionConfig::UNSECURE_CONN);
auto service_config_status = messaging->sendSyncMessage(
HTTPMethod::POST,
"/set-nano-service-config",
config_updates,
I_Messaging::Method::POST,
"127.0.0.1",
7777, // primary Orchestrator's port
conn_flags,
"/set-nano-service-config"
MessageCategory::GENERIC,
service_config_req_md
);
if (!is_success) {
is_success = messaging->sendObject(
if (!service_config_status.ok()) {
MessageMetadata secondary_port_req_md("127.0.0.1", 7778);
secondary_port_req_md.setConnectioFlag(MessageConnectionConfig::ONE_TIME_CONN);
secondary_port_req_md.setConnectioFlag(MessageConnectionConfig::UNSECURE_CONN);
service_config_status = messaging->sendSyncMessage(
HTTPMethod::POST,
"/set-nano-service-config",
config_updates,
I_Messaging::Method::POST,
"127.0.0.1",
7778, // secondary Orchestrator's port
conn_flags,
"/set-nano-service-config"
MessageCategory::GENERIC,
secondary_port_req_md
);
}
return is_success && config_updates.status.get();
return service_config_status.ok() && config_updates.status.get();
}
void
@@ -244,24 +247,26 @@ private:
sendOrchestatorReloadStatusMsg(const LoadNewConfigurationStatus &status)
{
I_Messaging *messaging = Singleton::Consume<I_Messaging>::by<ConfigComponent>();
::Flags<MessageConnConfig> conn_flags;
conn_flags.setFlag(MessageConnConfig::ONE_TIME_CONN);
bool is_success = messaging->sendNoReplyObject(
MessageMetadata service_config_req_md("127.0.0.1", 7777);
service_config_req_md.setConnectioFlag(MessageConnectionConfig::ONE_TIME_CONN);
service_config_req_md.setConnectioFlag(MessageConnectionConfig::UNSECURE_CONN);
bool service_config_status = messaging->sendSyncMessageWithoutResponse(
HTTPMethod::POST,
"/set-reconf-status",
status,
I_Messaging::Method::POST,
"127.0.0.1",
7777, // primary Orchestrator's port
conn_flags,
"/set-reconf-status"
MessageCategory::GENERIC,
service_config_req_md
);
if (!is_success) {
messaging->sendNoReplyObject(
if (!service_config_status) {
MessageMetadata secondary_port_req_md("127.0.0.1", 7778);
secondary_port_req_md.setConnectioFlag(MessageConnectionConfig::ONE_TIME_CONN);
secondary_port_req_md.setConnectioFlag(MessageConnectionConfig::UNSECURE_CONN);
messaging->sendSyncMessageWithoutResponse(
HTTPMethod::POST,
"/set-reconf-status",
status,
I_Messaging::Method::POST,
"127.0.0.1",
7778, // secondary Orchestrator's port
conn_flags,
"/set-reconf-status"
MessageCategory::GENERIC,
secondary_port_req_md
);
}
}

0
core/config/include/profile_settings.h Executable file → Normal file
View File

0
core/connkey/connkey.cc Executable file → Normal file
View File

9
core/core_ut/maybe_res_ut.cc Executable file → Normal file
View File

@@ -359,6 +359,15 @@ TEST(Maybe, maybe_void_error_passing)
EXPECT_EQ("error", err2.getErr());
}
TEST(Maybe, maybe_void_error_passing2)
{
Maybe<void> err1 = genError("error");
Maybe<void> err2 = err1.passErr();
EXPECT_FALSE(err2.ok());
EXPECT_EQ("error", err2.getErr());
}
TEST(Maybe, printing)
{
ostringstream os;

0
core/cptest/cptest.cc Executable file → Normal file
View File

0
core/cptest/cptest_data_buf.cc Executable file → Normal file
View File

0
core/cptest/cptest_tcppacket.cc Executable file → Normal file
View File

0
core/cptest/cptest_ut/cptest_packet_ut.cc Executable file → Normal file
View File

0
core/cpu/cpu.cc Executable file → Normal file
View File

View File

@@ -1,5 +1,5 @@
add_unit_test(
cpu_ut
"cpu_ut.cc"
"cpu;event_is;metric;-lboost_regex"
add_unit_test(
cpu_ut
"cpu_ut.cc"
"cpu;messaging;event_is;metric;-lboost_regex"
)

0
core/cpu/cpu_ut/cpu_ut.cc Executable file → Normal file
View File

8
core/debug_is/debug.cc Executable file → Normal file
View File

@@ -754,7 +754,13 @@ Debug::startStreams(
void
Debug::isCommunicationFlag(const DebugFlags &flag)
{
is_communication |= (flag == D_HTTP_REQUEST || flag == D_COMMUNICATION);
is_communication |= (
flag == D_MESSAGING ||
flag == D_COMMUNICATION ||
flag == D_CONNECTION ||
flag == D_MESSAGING_BUFFER ||
flag == D_HTTP_REQUEST
);
}
Debug::DebugLevel Debug::lowest_global_level = default_level;

View File

@@ -3,4 +3,4 @@ include_directories(${CMAKE_SOURCE_DIR}/cptest/include)
include_directories(${Boost_INCLUDE_DIRS})
link_directories(${BOOST_ROOT}/lib)
add_unit_test(debug_is_ut "debug_ut.cc" "agent_details;metric;event_is;-lboost_regex")
add_unit_test(debug_is_ut "debug_ut.cc" "agent_details;metric;messaging;event_is;-lboost_regex")

26
core/debug_is/debug_is_ut/debug_ut.cc Executable file → Normal file
View File

@@ -802,7 +802,11 @@ TEST(DebugFogTest, fog_stream)
StrictMock<MockMainLoop> mock_mainloop;
StrictMock<MockTimeGet> mock_time;
StrictMock<MockAgentDetails> mock_agent_details;
NiceMock<MockAgentDetails> mock_agent_details;
ON_CALL(mock_agent_details, getFogDomain()).WillByDefault(Return(Maybe<string>(string("fog_domain.com"))));
ON_CALL(mock_agent_details, getFogPort()).WillByDefault(Return(Maybe<uint16_t>(443)));
EXPECT_CALL(mock_agent_details, getAgentId()).WillRepeatedly(Return("Unknown"));
EXPECT_CALL(mock_agent_details, getOrchestrationMode()).WillRepeatedly(Return(OrchestrationMode::ONLINE));
@@ -814,15 +818,14 @@ TEST(DebugFogTest, fog_stream)
StrictMock<MockMessaging> messaging_mock;
string message_body;
EXPECT_CALL(messaging_mock, mockSendPersistentMessage(
false,
_,
EXPECT_CALL(messaging_mock, sendAsyncMessage(
_,
"/api/v1/agents/events/bulk",
_,
_,
MessageTypeTag::DEBUG
)).WillRepeatedly(DoAll(SaveArg<1>(&message_body), Return(Maybe<string>(string("")))));
_
)).WillRepeatedly(SaveArg<2>(&message_body));
Singleton::Consume<Config::I_Config>::from(conf)->loadConfiguration(
vector<string>{"--orchestration-mode=online_mode"}
@@ -953,7 +956,7 @@ TEST(DebugFogTest, fog_stream)
" \"agentId\": \"Unknown\",\n"
" \"issuingFunction\": \"handleThresholdReach\",\n"
" \"issuingFile\": \"debug_streams.cc\",\n"
" \"issuingLine\": 345,\n"
" \"issuingLine\": 344,\n"
" \"eventTraceId\": \"\",\n"
" \"eventSpanId\": \"\",\n"
" \"issuingEngineVersion\": \"\",\n"
@@ -977,12 +980,9 @@ TEST(DebugFogTest, fog_stream)
.WillOnce(DoAll(InvokeMainLoopCB(), Return(0)));
string message_body_1, message_body_2;
EXPECT_CALL(
messaging_mock,
mockSendPersistentMessage(false, _, _, "/api/v1/agents/events", _, _, MessageTypeTag::DEBUG)
).WillOnce(DoAll(SaveArg<1>(&message_body_1), Return(Maybe<string>(string(""))))).WillOnce(
DoAll(SaveArg<1>(&message_body_2), Return(Maybe<string>(string(""))))
);
EXPECT_CALL(messaging_mock, sendAsyncMessage(_, "/api/v1/agents/events", _, MessageCategory::DEBUG, _))
.WillOnce(SaveArg<2>(&message_body_1))
.WillOnce(SaveArg<2>(&message_body_2));
doFWError();
line1 = line;

View File

@@ -296,8 +296,7 @@ DebugFogStream::sendBufferedMessages()
while (!reports.empty()) {
auto rest = reports.pop();
using Method = I_Messaging::Method;
i_msg->sendObjectWithPersistence(rest, Method::POST, fog_debug_uri, "", true, MessageTypeTag::DEBUG);
i_msg->sendAsyncMessage(HTTPMethod::POST, fog_debug_uri, rest, MessageCategory::DEBUG);
}
}
void
@@ -310,7 +309,7 @@ DebugFogStream::sendSingleMessage(const LogRest &rest)
);
auto i_msg = Singleton::Consume<I_Messaging>::by<Debug>();
i_msg->sendObjectWithPersistence(rest, I_Messaging::Method::POST, fog_debug_uri, "", true, MessageTypeTag::DEBUG);
i_msg->sendAsyncMessage(HTTPMethod::POST, fog_debug_uri, rest, MessageCategory::DEBUG);
}
void

0
core/encryptor/cpnano_base64/base64.cc Executable file → Normal file
View File

0
core/encryptor/cpnano_base64/base64.h Executable file → Normal file
View File

0
core/encryptor/cpnano_base64/cpnano_base64.cc Executable file → Normal file
View File

View File

@@ -3,5 +3,5 @@ link_directories(${BOOST_ROOT}/lib)
add_unit_test(
encryptor_ut
"encryptor_ut.cc"
"encryptor;config;singleton;metric;event_is;-lboost_context;-lboost_regex;-lresolv;-lcrypto"
"encryptor;messaging;config;singleton;metric;event_is;-lboost_context;-lboost_regex;-lresolv;-lcrypto"
)

View File

@@ -59,6 +59,7 @@ public:
string getCurrentTrace() const override;
string getCurrentSpan() const override;
string getCurrentHeaders() override;
map<string, string> getCurrentHeadersMap() override;
void startNewTrace(bool new_span, const string &_trace_id) override;
void startNewSpan(Span::ContextType _type, const string &prev_span, const string &trace) override;
@@ -266,6 +267,34 @@ Environment::Impl::getCurrentHeaders()
return tracing_headers;
}
map<string, string>
Environment::Impl::getCurrentHeadersMap()
{
map<string, string> tracing_headers;
auto trace_id = getCurrentTrace();
if (!trace_id.empty()) {
tracing_headers["X-Trace-Id"] = trace_id;
} else {
string correlation_id_string = "00000000-0000-0000-0000-000000000000";
try {
boost::uuids::random_generator uuid_random_gen;
correlation_id_string = boost::uuids::to_string(uuid_random_gen());
} catch (const boost::uuids::entropy_error &e) {
dbgTrace(D_ENVIRONMENT)
<< "Failed to generate random correlation id - entropy exception. Exception: "
<< e.what();
tracing_status = TracingStatus::DISABLED;
}
tracing_headers["X-Trace-Id"] = correlation_id_string;
}
auto span_id = getCurrentSpan();
if (!span_id.empty()) {
tracing_headers["X-Span-Id"] = span_id;
}
return tracing_headers;
}
void
Environment::Impl::startNewTrace(bool new_span, const string &_trace_id)
{

View File

@@ -1,5 +1,5 @@
add_unit_test(
environment_ut
"context_ut.cc;parsing_ut.cc;base_evaluators_ut.cc;environment_rest_ut.cc;span_ut.cc;trace_ut.cc;tracing_ut.cc;environment_ut.cc"
"environment;singleton;rest;mainloop;metric;-lboost_context;event_is;-lboost_regex"
"environment;messaging;singleton;rest;mainloop;metric;-lboost_context;event_is;-lboost_regex"
)

0
core/environment/environment_ut/base_evaluators_ut.cc Executable file → Normal file
View File

0
core/environment/environment_ut/context_ut.cc Executable file → Normal file
View File

0
core/environment/environment_ut/parsing_ut.cc Executable file → Normal file
View File

0
core/environment/environment_ut/span_ut.cc Executable file → Normal file
View File

0
core/environment/environment_ut/trace_ut.cc Executable file → Normal file
View File

2
core/environment/environment_ut/tracing_ut.cc Executable file → Normal file
View File

@@ -344,8 +344,6 @@ public:
TEST_F(TracingCompRoutinesTest, 2SpansDifFlow)
{
ON_CALL(mock_messaging, mockSendPersistentMessage(_, _, _, _, _, _, _)).WillByDefault(Return(string()));
I_MainLoop::Routine routine = [&] () {
i_env->startNewTrace(true, "a687b388-1108-4083-9852-07c33b1074e9");
trace_id = i_env->getCurrentTrace();

0
core/environment/span.cc Executable file → Normal file
View File

0
core/environment/trace.cc Executable file → Normal file
View File

0
core/include/attachments/compression_utils.h Executable file → Normal file
View File

0
core/include/attachments/nginx_attachment_common.h Executable file → Normal file
View File

0
core/include/attachments/shmem_ipc.h Executable file → Normal file
View File

0
core/include/general/buffer.h Executable file → Normal file
View File

0
core/include/general/buffer/char_iterator.h Executable file → Normal file
View File

0
core/include/general/buffer/data_container.h Executable file → Normal file
View File

0
core/include/general/buffer/helper_functions.h Executable file → Normal file
View File

0
core/include/general/buffer/internal_ptr.h Executable file → Normal file
View File

0
core/include/general/buffer/segment.h Executable file → Normal file
View File

0
core/include/general/c_common/network_defs.h Executable file → Normal file
View File

0
core/include/general/c_common/networking_headers.h Executable file → Normal file
View File

0
core/include/general/cptest.h Executable file → Normal file
View File

0
core/include/general/cptest/cptest_tcppacket.h Executable file → Normal file
View File

0
core/include/general/debug.h Executable file → Normal file
View File

0
core/include/general/intelligence_comp_v2.h Executable file → Normal file
View File

View File

@@ -29,7 +29,7 @@
// Code taken from N4189 pending standard - www.open-std.org/jtc1/sc22/wg21/docs/papers/2014/n4189.pdf
// (with some minor adaptations for C++11)
#include <type_traits> // For ::std::remove_reference
#include <utility>
namespace std
{
@@ -56,7 +56,6 @@ public:
if (execute_on_destruction) this->exit_function();
}
// LCOV_EXCL_START Reason: coverage upgrade
// move
scope_exit(scope_exit &&rhs) noexcept
:
@@ -65,7 +64,6 @@ public:
{
rhs.release();
}
// LCOV_EXCL_STOP
void
release() noexcept

0
core/include/general/time_proxy.h Executable file → Normal file
View File

View File

@@ -1,95 +0,0 @@
// Copyright (C) 2022 Check Point Software Technologies Ltd. All rights reserved.
// Licensed under the Apache License, Version 2.0 (the "License");
// You may obtain a copy of the License at
//
// http://www.apache.org/licenses/LICENSE-2.0
//
// Unless required by applicable law or agreed to in writing, software
// distributed under the License is distributed on an "AS IS" BASIS,
// WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
// See the License for the specific language governing permissions and
// limitations under the License.
#ifndef __HTTP_ENCODER_H__
#define __HTTP_ENCODER_H__
#include <string>
#include "messaging/http_core.h"
class HTTPRequest
{
public:
HTTPRequest() = default;
HTTPRequest(const std::string &_method_statement);
HTTPRequest(const std::string &_method_statement, const std::string &_host, const bool to_proxy);
HTTPRequest & insertHeader(const std::string &header_key, const std::string &header_val);
HTTPRequest & insertHeader(const std::string &header);
HTTPRequest & insertHeaders(const std::string &rec_headers);
HTTPRequest & insertBody(const std::string &body);
std::string toString() const;
private:
std::string method_statement;
HTTPHeaders headers;
std::string body;
};
class ConnectRequest: public HTTPRequest
{
public:
ConnectRequest(const std::string &_host, const std::string &_port);
};
class PostRequest: public HTTPRequest
{
public:
PostRequest(const std::string &_post_path, const std::string &_host, bool to_proxy);
};
class PutRequest : public HTTPRequest
{
public:
PutRequest(const std::string &_put_path, const std::string &_host, bool to_proxy);
};
class GetRequest: public HTTPRequest
{
public:
GetRequest(const std::string &_get_path, const std::string &_host, bool to_proxy);
};
class PatchRequest: public HTTPRequest
{
public:
PatchRequest(const std::string &_patch_path, const std::string &_host, bool to_proxy);
};
class HTTPEncoder
{
public:
HTTPEncoder(const std::string &_host, const std::string &_port);
HTTPRequest & Connect();
HTTPRequest & Post(const std::string &post_path);
HTTPRequest & Put(const std::string &put_path);
HTTPRequest & Patch(const std::string &patch_path);
HTTPRequest & Get(const std::string &get_path);
HTTPEncoder & isOverProxy();
HTTPEncoder & isOverSSL();
std::string build() const { return request.toString(); }
private:
HTTPRequest request;
std::string host;
std::string port;
bool over_ssl = false;
bool over_proxy = false;
};
#endif // __HTTP_ENCODER_H__

0
core/include/internal/ioctl_is.h Executable file → Normal file
View File

0
core/include/internal/mainloop/mainloop_metric.h Executable file → Normal file
View File

View File

@@ -11,44 +11,43 @@
// See the License for the specific language governing permissions and
// limitations under the License.
#ifndef __PROTO_MESSAGE_COMP_H__
#define __PROTO_MESSAGE_COMP_H__
#ifndef __MESSAGING_H__
#define __MESSAGING_H__
#include <memory>
#include <string>
#include "singleton.h"
#include "i_mainloop.h"
#include "i_encryptor.h"
#include "i_messaging.h"
#include "i_agent_details.h"
#include "i_environment.h"
#include "i_rest_api.h"
#include "i_messaging_buffer.h"
#include "i_shell_cmd.h"
#include "i_proxy_configuration.h"
#include "component.h"
class ProtoMessageComp
#include "component.h"
#include "singleton.h"
#include "i_environment.h"
#include "i_proxy_configuration.h"
#include "i_agent_details.h"
#include "i_mainloop.h"
#include "i_time_get.h"
#include "i_encryptor.h"
#include "i_shell_cmd.h"
#include "i_instance_awareness.h"
#include "config.h"
class Messaging
:
public Component,
Singleton::Provide<I_Messaging>,
Singleton::Consume<I_MainLoop>,
Singleton::Consume<I_TimeGet>,
Singleton::Consume<I_AgentDetails>,
Singleton::Consume<I_Encryptor>,
Singleton::Consume<I_ProxyConfiguration>,
Singleton::Consume<I_Environment>,
Singleton::Consume<I_MessagingBuffer>,
Singleton::Consume<I_Encryptor>,
Singleton::Consume<I_AgentDetails>,
Singleton::Consume<I_TimeGet>,
Singleton::Consume<I_ShellCmd>,
Singleton::Consume<I_ProxyConfiguration>
Singleton::Consume<I_MainLoop>,
Singleton::Consume<I_InstanceAwareness>
{
public:
ProtoMessageComp();
~ProtoMessageComp();
Messaging();
~Messaging();
void init();
void fini();
void preload();
private:
@@ -56,4 +55,4 @@ private:
std::unique_ptr<Impl> pimpl;
};
#endif // __PROTO_MESSAGE_COMP_H__
#endif // __MESSAGING_H__

View File

@@ -1,58 +0,0 @@
// Copyright (C) 2022 Check Point Software Technologies Ltd. All rights reserved.
// Licensed under the Apache License, Version 2.0 (the "License");
// You may obtain a copy of the License at
//
// http://www.apache.org/licenses/LICENSE-2.0
//
// Unless required by applicable law or agreed to in writing, software
// distributed under the License is distributed on an "AS IS" BASIS,
// WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
// See the License for the specific language governing permissions and
// limitations under the License.
#ifndef __BUCKET_MANAGER_H__
#define __BUCKET_MANAGER_H__
#include <unordered_map>
#include <iterator>
#include <string>
#include "event_queue.h"
#include "instance_awareness.h"
#include "i_time_get.h"
#include "i_encryptor.h"
using bucketName = std::string;
class BucketManager
{
public:
void init(const std::string &service_name);
void fini();
bool doesExist(const bucketName &);
void push(const bucketName &, std::string &&);
bool handleNextBucket();
bool hasValue();
EventQueue & peek();
void flush();
private:
std::string resolveFilesName(const std::string &file_name);
std::string buffer_directory = "";
std::string next_bucket = "";
std::string service_name = "";
std::string management_file_path = "";
uint buffer_max_size = 0; // in MB
uint max_buffer_files = 0;
EventQueue iterator;
std::unordered_map<bucketName, EventQueue> buckets;
I_InstanceAwareness *instance_awareness = nullptr;
I_Encryptor *encryptor = nullptr;
};
#endif // __BUCKET_MANAGER_H__

View File

@@ -1,125 +0,0 @@
// Copyright (C) 2022 Check Point Software Technologies Ltd. All rights reserved.
// Licensed under the Apache License, Version 2.0 (the "License");
// You may obtain a copy of the License at
//
// http://www.apache.org/licenses/LICENSE-2.0
//
// Unless required by applicable law or agreed to in writing, software
// distributed under the License is distributed on an "AS IS" BASIS,
// WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
// See the License for the specific language governing permissions and
// limitations under the License.
#ifndef __EVENT_QUEUE_H__
#define __EVENT_QUEUE_H__
#include <boost/range/iterator_range.hpp>
#include <cstring>
#include <iostream>
#include <fstream>
#include <memory>
#include <list>
#include <chrono>
#include "i_time_get.h"
#include "maybe_res.h"
USE_DEBUG_FLAG(D_EVENT_BUFFER);
class EventQueueFile
{
public:
EventQueueFile(const std::string &_file_path)
:
file_path(_file_path)
{}
EventQueueFile(
const std::string &file_location_path,
const std::string &file_extention,
bool is_file_compressed);
EventQueueFile(const EventQueueFile &other_event, int _num_of_events_in_file, uint64_t _size_of_file)
:
file_path(other_event.file_path),
suffix(other_event.suffix),
num_of_events_in_file(_num_of_events_in_file),
size_of_file(_size_of_file)
{}
static const std::string zip_file_suffix;
const std::string & getFilePath() const { return file_path; }
bool isCompressed() const { return is_compressed; }
int getSuffix() const { return suffix; }
int getNumOfEvents() const { return num_of_events_in_file; }
uint64_t getFileSizeInBytes() const { return size_of_file; }
void restoreNumberOfLines();
void incFileSize(uint64_t size_to_add);
void handleCompression(int size_of_files_list);
void decompress(const std::string &infilename, const std::string &outfilename, bool remove_old = true);
void compress();
private:
std::string file_path;
int suffix = -1;
bool is_compressed = false;
int num_of_events_in_file = 0;
size_t size_of_file = 0;
};
class EventQueue
{
public:
EventQueue() = default;
~EventQueue();
void init(const std::string &path, uint max_buff_size);
void fini();
bool isEmpty() const;
const std::string & peek();
void push(std::string &&event_data);
void reloadEventsIntoList(const std::string &path);
Maybe<void> refreshBufferFile();
void refreshReadBuff();
void trim();
void flush();
private:
void rotate();
void updateReadFile();
void setReaderFileAndOpen(const EventQueueFile &file);
void sortEventFilesBySuffix(std::vector<EventQueueFile> &tmp_vec);
void pushNewEventQueueFile(EventQueueFile &eventFile, std::vector<EventQueueFile> &tmp_vec);
double getSizeMB(double size_in_B) const;
Maybe<void> writeCachesToFile();
void enforceMaxNumberOfFiles();
// File management
std::list<EventQueueFile> files; //front is write, back is read
std::ifstream reader;
std::ofstream writer;
// Read & write management
double max_size; // in MB
uint64_t size_on_disk; // in B
uint64_t write_cache_size; // in B
uint64_t read_cache_size; // in B
std::list<std::string> write_cache_buff;
std::list<std::string> read_cache_buff;
unsigned int num_of_events_on_disk;
unsigned int read_events_on_disk;
// Timing management
std::chrono::microseconds next_sync_freq_in_sec;
I_TimeGet *timer = nullptr;
bool is_pending_rotate = false;
bool is_pending_write = false;
};
#endif // __EVENT_QUEUE_H__

0
core/include/internal/shell_cmd.h Executable file → Normal file
View File

0
core/include/internal/trap_handler.h Executable file → Normal file
View File

0
core/include/services_sdk/interfaces/i_agent_details.h Executable file → Normal file
View File

0
core/include/services_sdk/interfaces/i_cpu.h Executable file → Normal file
View File

View File

@@ -80,6 +80,7 @@ public:
virtual std::string getCurrentTrace() const = 0;
virtual std::string getCurrentSpan() const = 0;
virtual std::string getCurrentHeaders() = 0;
virtual std::map<std::string, std::string> getCurrentHeadersMap() = 0;
virtual void startNewTrace(bool new_span = true, const std::string &_trace_id = std::string()) = 0;
virtual void startNewSpan(
Span::ContextType _type,

0
core/include/services_sdk/interfaces/i_failopen.h Executable file → Normal file
View File

View File

View File

@@ -131,20 +131,18 @@ private:
IntelligenceQuery<Data> &intelligence_query,
const std::string &query_uri,
I_Messaging *i_message,
Flags<MessageConnConfig> conn_flags,
Flags<MessageConnectionConfig> conn_flags,
const std::string &ip,
uint server_port
) {
if (ip == "" && server_port == 0) {
return i_message->sendObject(
intelligence_query,
I_Messaging::Method::POST,
auto req_status = i_message->sendSyncMessage(
HTTPMethod::POST,
query_uri,
"",
nullptr,
true,
MessageTypeTag::INTELLIGENCE
intelligence_query,
MessageCategory::INTELLIGENCE
);
return req_status.ok();
}
dbgTrace(D_INTELLIGENCE)
@@ -154,18 +152,15 @@ private:
<< server_port
<< " query_uri: "
<< query_uri;
return i_message->sendObject(
intelligence_query,
I_Messaging::Method::POST,
ip,
server_port,
conn_flags,
MessageMetadata req_md(ip, server_port, conn_flags);
auto req_status = i_message->sendSyncMessage(
HTTPMethod::POST,
query_uri,
"",
nullptr,
MessageTypeTag::INTELLIGENCE
intelligence_query,
MessageCategory::INTELLIGENCE,
req_md
);
return req_status.ok();
}
template<typename Data>
@@ -174,7 +169,7 @@ private:
IntelligenceQuery<Data> &intelligence_query,
const std::string &query_uri,
I_Messaging *i_message,
Flags<MessageConnConfig> conn_flags,
Flags<MessageConnectionConfig> conn_flags,
const std::string &ip = "",
uint server_port = 0
) {
@@ -233,7 +228,7 @@ private:
const std::string &query_uri,
int assets_limit,
I_Messaging *i_message,
Flags<MessageConnConfig> conn_flags,
Flags<MessageConnectionConfig> conn_flags,
const std::string &ip = "",
uint server_port = 0
) {
@@ -265,7 +260,7 @@ private:
bool is_primary_port,
int assets_limit,
I_Messaging *i_message,
Flags<MessageConnConfig> conn_flags
Flags<MessageConnectionConfig> conn_flags
) {
static const std::string primary_port_setting = "local intelligence server primary port";
static const std::string secondary_port_setting = "local intelligence server secondary port";
@@ -299,7 +294,7 @@ private:
sendQueryObject(IntelligenceQuery<Data> &intelligence_query, const std::string &query_uri, int assets_limit)
{
auto i_message = getMessaging();
Flags<MessageConnConfig> conn_flags;
Flags<MessageConnectionConfig> conn_flags;
bool crowdsec_enabled = std::getenv("CROWDSEC_ENABLED") ?
std::string(std::getenv("CROWDSEC_ENABLED")) == "true" :

0
core/include/services_sdk/interfaces/i_ioctl.h Executable file → Normal file
View File

220
core/include/services_sdk/interfaces/i_messaging.h Executable file → Normal file
View File

@@ -10,172 +10,98 @@
// WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
// See the License for the specific language governing permissions and
// limitations under the License.
#ifndef __I_FOG_MESSAGING_H__
#define __I_FOG_MESSAGING_H__
#ifndef __I_MESSAGING_H__
#define __I_MESSAGING_H__
#include <string>
#include <map>
#include <sstream>
#include <fstream>
#include <functional>
#include <ostream>
#include "cereal/archives/json.hpp"
#include "cereal/types/common.hpp"
#include "cereal/types/string.hpp"
#include "cereal/types/vector.hpp"
#include "maybe_res.h"
#include "debug.h"
#include "messaging/http_core.h"
#include "i_agent_details.h"
#include "i_proxy_configuration.h"
#include "flags.h"
#include "maybe_res.h"
#include "messaging/http_response.h"
#include "messaging/messaging_metadata.h"
USE_DEBUG_FLAG(D_COMMUNICATION);
enum class MessageTypeTag
{
GENERIC,
LOG,
DEBUG,
METRIC,
REPORT,
WAAP_LEARNING,
INTELLIGENCE,
BUFFERED_MESSAGES,
COUNT
};
enum class MessageConnConfig
{
SECURE_CONN,
ONE_TIME_CONN,
EXPECT_REPLY,
EXTERNAL,
IGNORE_SSL_VALIDATION,
COUNT
};
USE_DEBUG_FLAG(D_MESSAGING);
class I_Messaging
:
Singleton::Consume<I_AgentDetails>,
Singleton::Consume<I_ProxyConfiguration>
{
public:
using string = std::string;
using ErrorCB = std::function<void(HTTPStatusCode)>;
template <typename serializableObject>
Maybe<void, HTTPResponse> sendSyncMessage(
HTTPMethod method,
const std::string &uri,
serializableObject &req_obj,
MessageCategory category = MessageCategory::GENERIC,
MessageMetadata message_metadata = MessageMetadata());
enum class Method { GET, POST, PATCH, CONNECT, PUT };
template <typename serializableObject>
bool sendSyncMessageWithoutResponse(
const HTTPMethod method,
const std::string &uri,
serializableObject &req_obj,
const MessageCategory category = MessageCategory::GENERIC,
MessageMetadata message_metadata = MessageMetadata());
template <typename T, typename ...Args>
bool
sendObject(T &obj, Args ...args)
{
auto req = obj.genJson();
if (!req.ok()) {
dbgWarning(D_COMMUNICATION) << "Failed to create a request. Error: " << req.getErr();
return false;
}
template <typename serializableObject>
void sendAsyncMessage(
const HTTPMethod method,
const std::string &uri,
serializableObject &req_obj,
const MessageCategory category = MessageCategory::GENERIC,
MessageMetadata message_metadata = MessageMetadata());
dbgTrace(D_COMMUNICATION) << "Request generated from json. Request: " << req.unpack();
auto res = sendMessage(true, *req, args...);
if (!res.ok()) {
dbgWarning(D_COMMUNICATION) << "Failed to send request. Error: " << res.getErr();
return false;
}
dbgTrace(D_COMMUNICATION) << "Successfully got response: " << res.unpack();
virtual void sendAsyncMessage(
const HTTPMethod method,
const std::string &uri,
const std::string &body,
const MessageCategory category,
MessageMetadata message_metadata
) = 0;
virtual Maybe<HTTPResponse, HTTPResponse> sendSyncMessage(
const HTTPMethod method,
const std::string &uri,
const std::string &body,
const MessageCategory category = MessageCategory::GENERIC,
MessageMetadata message_metadata = MessageMetadata()
) = 0;
auto res_json = obj.loadJson(res.unpack());
if (!res_json) {
dbgWarning(D_COMMUNICATION) << "Failed to parse response body. Content: " << res.unpack();
} else {
dbgTrace(D_COMMUNICATION) << "Successfully parsed response body";
}
return res_json;
}
virtual Maybe<HTTPStatusCode, HTTPResponse> downloadFile(
const HTTPMethod method,
const std::string &uri,
const std::string &download_file_path,
const MessageCategory category = MessageCategory::GENERIC,
MessageMetadata message_metadata = MessageMetadata()
) = 0;
template <typename T, typename ...Args>
bool
sendNoReplyObject(T &obj, Args ...args)
{
auto req = obj.genJson();
if (!req.ok()) {
dbgWarning(D_COMMUNICATION) << "Failed to create a request. Error: " << req.getErr();;
return false;
}
virtual Maybe<HTTPStatusCode, HTTPResponse> uploadFile(
const std::string & uri,
const std::string & upload_file_path,
const MessageCategory category = MessageCategory::GENERIC,
MessageMetadata message_metadata = MessageMetadata()
) = 0;
auto res = sendMessage(false, *req, args...);
if (!res.ok()) {
dbgWarning(D_COMMUNICATION) << "Failed to send request. Error: " << res.getErr();
}
return res.ok();
}
template <typename T, typename ...Args>
void
sendObjectWithPersistence(T &obj, Args ...args)
{
auto req = obj.genJson();
if (!req.ok()) {
dbgWarning(D_COMMUNICATION) << "Failed to create a request. Error: " << req.getErr();;
return;
}
sendPersistentMessage(false, req.unpackMove(), args...);
}
template <typename T, typename ...Args>
Maybe<string>
downloadFile(T &obj, Args ...args)
{
auto req = obj.genJson();
if (!req.ok()) return genError("Invalid request");
auto response = sendMessage(true, *req, args...);
if (response.ok()) {
return response.unpack();
}
return genError("Failed to download file. Error: " + response.getErr());
}
virtual bool setActiveFog(MessageTypeTag tag) = 0;
virtual bool setActiveFog(const string &host, const uint16_t port, bool is_secure, MessageTypeTag tag) = 0;
protected:
~I_Messaging() {}
private:
virtual Maybe<string>
sendPersistentMessage(
bool get_reply,
const string &&body,
Method method,
const string &uri,
const string &headers = "",
bool should_yield = true,
MessageTypeTag tag = MessageTypeTag::GENERIC,
bool skip_sending = false) = 0;
virtual Maybe<string>
sendMessage(
bool get_reply,
const string &body,
Method method,
const string &uri,
const string &headers = "",
ErrorCB err_call_back = nullptr,
bool should_yield = true,
MessageTypeTag tag = MessageTypeTag::GENERIC) = 0;
virtual Maybe<string>
sendMessage(
bool get_reply,
const string &body,
Method method,
virtual bool setFogConnection(
const std::string &host,
uint16_t port,
Flags<MessageConnConfig> &conn_flags,
const string &uri,
const string &headers = "",
ErrorCB err_call_back = nullptr,
MessageTypeTag tag = MessageTypeTag::GENERIC) = 0;
bool is_secure,
MessageCategory category
) = 0;
virtual bool setFogConnection(MessageCategory category = MessageCategory::GENERIC) = 0;
protected:
virtual ~I_Messaging() {}
};
#endif // __I_FOG_MESSAGING_H__
#include "messaging/interface_impl.h"
#endif // __I_MESSAGING_H__

View File

@@ -27,12 +27,12 @@ enum class ProxyProtocol
class I_ProxyConfiguration
{
public:
virtual Maybe<std::string> getProxyDomain(ProxyProtocol protocol) const = 0;
virtual Maybe<std::string> getProxyCredentials(ProxyProtocol protocol) const = 0;
virtual Maybe<uint16_t> getProxyPort(ProxyProtocol protocol) const = 0;
virtual bool getProxyExists(ProxyProtocol protocol) const = 0;
virtual Maybe<std::string> getProxyAddress(ProxyProtocol protocol) const = 0;
virtual Maybe<void> loadProxy() = 0;
virtual Maybe<std::string> getProxyDomain(ProxyProtocol protocol) const = 0;
virtual Maybe<std::string> getProxyAuthentication(ProxyProtocol protocol) const = 0;
virtual Maybe<uint16_t> getProxyPort(ProxyProtocol protocol) const = 0;
virtual bool getProxyExists(ProxyProtocol protocol) const = 0;
virtual Maybe<std::string> getProxyAddress(ProxyProtocol protocol) const = 0;
virtual Maybe<void> loadProxy() = 0;
};
#endif // __I_PROXY_CONFIGURATION_H__

0
core/include/services_sdk/interfaces/i_shell_cmd.h Executable file → Normal file
View File

View File

0
core/include/services_sdk/interfaces/i_socket_is.h Executable file → Normal file
View File

0
core/include/services_sdk/interfaces/i_trap_handler.h Executable file → Normal file
View File

View File

@@ -45,7 +45,8 @@ enum class Condition
IN,
NOT_IN,
GREATER_THAN,
LESS_THAN
LESS_THAN,
RANGE
};
enum class CursorState {
@@ -60,7 +61,7 @@ enum class ResponseStatus
IN_PROGRESS
};
enum class ObjectType { ASSET, ZONE, CONFIGURATION, COUNT };
enum class ObjectType { ASSET, ZONE, CONFIGURATION, SHORTLIVED, COUNT};
const std::string & convertConditionTypeToString(const Condition &condition_type);
const std::string & convertOperationTypeToString(const Operator &operation_type);

View File

@@ -30,7 +30,7 @@ using namespace Intelligence_IS_V2;
class SerializableQueryCondition
{
public:
typedef boost::variant<int64_t, std::string> ValueVariant;
typedef boost::variant<int64_t, std::string, std::vector<std::string>> ValueVariant;
SerializableQueryCondition() {}
@@ -48,6 +48,13 @@ public:
value(_value)
{}
SerializableQueryCondition(Condition _condition_type, std::string _key, std::vector<std::string> _value)
:
condition_type(_condition_type),
key(_key),
value(_value)
{}
void save(cereal::JSONOutputArchive &ar) const;
Condition getConditionType() const { return condition_type; }
@@ -66,11 +73,13 @@ public:
SerializableQueryFilter() {}
SerializableQueryFilter(Condition condition_type, const std::string &key, const std::string &value);
SerializableQueryFilter(Condition condition_type, const std::string &key, const int64_t &value);
SerializableQueryFilter(Condition condition_type, const std::string &key, const std::vector<std::string> &value);
void save(cereal::JSONOutputArchive &ar) const;
void addCondition(Condition condition_type, const std::string &key, const std::string &value);
void addCondition(Condition condition_type, const std::string &key, const int64_t &value);
void addCondition(Condition condition_type, const std::string &key, const std::vector<std::string> &value);
Operator getOperator() const { return operator_type; }
const std::vector<SerializableQueryCondition> & getConditionOperands() const { return condition_operands; }

View File

@@ -45,6 +45,14 @@ public:
AttributeKeyType type = AttributeKeyType::MAIN
);
QueryRequest(
Condition condition_type,
const std::string &key,
const std::vector<std::string> &value,
bool full_response,
AttributeKeyType type = AttributeKeyType::MAIN
);
void saveToJson(cereal::JSONOutputArchive &ar) const;
void save(cereal::JSONOutputArchive &ar) const;
@@ -66,6 +74,13 @@ public:
AttributeKeyType attribute_type = AttributeKeyType::MAIN
);
void addCondition(
Condition condition_type,
const std::string &key,
const std::vector<std::string> &value,
AttributeKeyType attribute_type = AttributeKeyType::MAIN
);
void setRequestedAttr(
const std::string &attr,
AttributeKeyType attribute_type = AttributeKeyType::REGULAR

View File

@@ -0,0 +1,45 @@
// Copyright (C) 2022 Check Point Software Technologies Ltd. All rights reserved.
// Licensed under the Apache License, Version 2.0 (the "License");
// You may obtain a copy of the License at
//
// http://www.apache.org/licenses/LICENSE-2.0
//
// Unless required by applicable law or agreed to in writing, software
// distributed under the License is distributed on an "AS IS" BASIS,
// WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
// See the License for the specific language governing permissions and
// limitations under the License.
#ifndef __HTTP_RESPONSE_H__
#define __HTTP_RESPONSE_H__
#include <string>
#include <map>
#include <cereal/archives/json.hpp>
#include "singleton.h"
#include "i_env_details.h"
#include "i_agent_details.h"
#include "i_encryptor.h"
#include "messaging/messaging_enums.h"
class HTTPResponse
{
public:
// LCOV_EXCL_START Reason: Not actually called but is required by the caching interface
HTTPResponse() = default;
// LCOV_EXCL_STOP
HTTPResponse(HTTPStatusCode _status_code, const std::string &_body) : status_code(_status_code), body(_body) {}
HTTPStatusCode getHTTPStatusCode() const;
const std::string & getBody() const;
std::string toString() const;
private:
HTTPStatusCode status_code;
std::string body;
};
#endif // __HTTP_RESPONSE_H__

View File

@@ -0,0 +1,148 @@
// Copyright (C) 2022 Check Point Software Technologies Ltd. All rights reserved.
// Licensed under the Apache License, Version 2.0 (the "License");
// You may obtain a copy of the License at
//
// http://www.apache.org/licenses/LICENSE-2.0
//
// Unless required by applicable law or agreed to in writing, software
// distributed under the License is distributed on an "AS IS" BASIS,
// WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
// See the License for the specific language governing permissions and
// limitations under the License.
#ifndef __INTERFACE_IMPL_H__
#define __INTERFACE_IMPL_H__
#ifndef __I_MESSAGING_H__
#error "interface_impl.h should not be included directly"
#endif // __I_MESSAGING_H__
USE_DEBUG_FLAG(D_MESSAGING);
MessageMetadata::MessageMetadata()
{
if (!Singleton::exists<I_AgentDetails>() || !Singleton::exists<I_ProxyConfiguration>()) return;
auto i_agent_details = Singleton::Consume<I_AgentDetails>::by<I_Messaging>();
auto i_proxy_configuration = Singleton::Consume<I_ProxyConfiguration>::by<I_Messaging>();
is_to_fog = true;
host_name = i_agent_details->getFogDomain().ok() ? i_agent_details->getFogDomain().unpack() : "";
port_num = i_agent_details->getFogPort().ok() ? i_agent_details->getFogPort().unpack() : 0;
ProxyProtocol protocol = i_agent_details->getSSLFlag() ? ProxyProtocol::HTTPS : ProxyProtocol::HTTP;
auto maybe_proxy_domain = i_proxy_configuration->getProxyDomain(protocol);
std::string proxy_domain = maybe_proxy_domain.ok() ? *maybe_proxy_domain : "";
dbgTrace(D_MESSAGING) << "Created message metadata. Host name: " << host_name << ", Port num: " << port_num;
if (proxy_domain.empty()) return;
auto maybe_proxy_port = i_proxy_configuration->getProxyPort(protocol);
uint16_t proxy_port = maybe_proxy_port.ok() ? *maybe_proxy_port : 0;
auto maybe_proxy_auth = i_proxy_configuration->getProxyAuthentication(protocol);
std::string proxy_auth = maybe_proxy_auth.ok() ? *maybe_proxy_auth : "";
setProxySettings(MessageProxySettings(proxy_domain, proxy_auth, proxy_port));
dbgTrace(D_MESSAGING) << "Proxy : " << proxy_domain << ":" << proxy_port;
}
template <typename serializableObject>
Maybe<void, HTTPResponse>
I_Messaging::sendSyncMessage(
HTTPMethod method,
const std::string &uri,
serializableObject &req_obj,
MessageCategory category,
MessageMetadata message_metadata)
{
Maybe<std::string> req_body = req_obj.genJson();
if (!req_body.ok()) {
return genError(
HTTPResponse(
HTTPStatusCode::NO_HTTP_RESPONSE,
"Failed to create a request. Error: " + req_body.getErr()
)
);
}
Maybe<HTTPResponse, HTTPResponse> response_data = sendSyncMessage(
method,
uri,
req_body.unpack(),
category,
message_metadata
);
if (!response_data.ok()) return response_data.passErr();
auto res_obj = req_obj.loadJson(response_data.unpack().getBody());
if (!res_obj) {
return genError(
HTTPResponse(
HTTPStatusCode::NO_HTTP_RESPONSE,
"Failed to parse response body. Body: " + response_data.unpack().getBody()
)
);
}
return {};
}
template <typename serializableObject>
bool
I_Messaging::sendSyncMessageWithoutResponse(
const HTTPMethod method,
const std::string &uri,
serializableObject &req_obj,
const MessageCategory category,
MessageMetadata message_metadata)
{
Maybe<std::string> req_body = req_obj.genJson();
if (!req_body.ok()) {
dbgWarning(D_MESSAGING) << "Failed to create a request. Error: " << req_body.getErr();
return false;
}
Maybe<HTTPResponse, HTTPResponse> response_data = sendSyncMessage(
method,
uri,
req_body.unpack(),
category,
message_metadata
);
if (!response_data.ok()) {
dbgWarning(D_MESSAGING)
<< "Received error from server. Status code: "
<< int(response_data.getErr().getHTTPStatusCode())
<< ", error response: "
<< response_data.getErr().getBody();
return false;
}
return true;
}
template <typename serializableObject>
void
I_Messaging::sendAsyncMessage(
const HTTPMethod method,
const std::string &uri,
serializableObject &req_obj,
const MessageCategory category,
MessageMetadata message_metadata)
{
Maybe<std::string> req_body = req_obj.genJson();
if (!req_body.ok()) {
dbgWarning(D_MESSAGING) << "Failed to create a request. Error: " << req_body.getErr();
return;
}
sendAsyncMessage(
method,
uri,
req_body.unpack(),
category,
message_metadata
);
}
#endif // __INTERFACE_IMPL_H__

View File

@@ -11,20 +11,45 @@
// See the License for the specific language governing permissions and
// limitations under the License.
#ifndef __HTTP_CORE_H__
#define __HTTP_CORE_H__
#ifndef __MESSAGING_ENUMS_H__
#define __MESSAGING_ENUMS_H__
#include <string>
#include <unordered_map>
enum class MessageCategory
{
GENERIC,
LOG,
DEBUG,
METRIC,
INTELLIGENCE,
#include "maybe_res.h"
#include "cereal/archives/json.hpp"
#include "cereal/types/string.hpp"
COUNT
};
enum class MessageConnectionConfig
{
UNSECURE_CONN,
ONE_TIME_CONN,
IGNORE_SSL_VALIDATION,
COUNT
};
enum class HTTPMethod
{
GET,
POST,
PATCH,
CONNECT,
PUT,
COUNT
};
enum class HTTPStatusCode
{
// 10X - Information responses. Not supported yet.
// 20x - Successful responses.
NO_HTTP_RESPONSE = 0,
HTTP_OK = 200,
HTTP_NO_CONTENT = 204,
HTTP_MULTI_STATUS = 207,
@@ -51,53 +76,8 @@ enum class HTTPStatusCode
HTTP_NOT_EXTENDED = 510,
HTTP_NETWORK_AUTHENTICATION_REQUIRED = 511,
// Not supported status code.
HTTP_UNKNOWN
HTTP_UNKNOWN = -1,
HTTP_SUSPEND = -2
};
class HTTPResponse
{
public:
HTTPResponse(const HTTPStatusCode status_code, const std::string &&body);
Maybe<std::string> getResponse() const;
HTTPStatusCode getStatusCode() const { return status_code; }
std::string getBody() const { return body; }
class BadRequestResponse
{
public:
void serialize(cereal::JSONInputArchive &ar);
std::string getMsg() const { return message; }
std::string getID() const { return message_id; }
private:
std::string message;
std::string message_id;
};
private:
HTTPStatusCode status_code;
std::string body;
};
class HTTPHeaders
{
public:
HTTPHeaders() = default;
static Maybe<HTTPHeaders> createHTTPHeader(const std::string &http_data);
void insertHeader(const std::string &header_key, const std::string &header_val);
void insertHeader(const std::string &header);
void insertHeaders(const std::string &headers);
Maybe<std::string> getHeaderVal(const std::string &header_key);
std::string toString() const;
private:
HTTPHeaders(const std::string &http_data);
std::unordered_map<std::string, std::string> headers;
};
#endif // __HTTP_CORE_H__
#endif // __MESSAGING_ENUMS_H__

View File

@@ -0,0 +1,198 @@
#ifndef __MESSAGING_METADATA_H__
#define __MESSAGING_METADATA_H__
#include <map>
#include <string>
#include "flags.h"
#include "singleton.h"
#include "i_agent_details.h"
class MessageProxySettings
{
public:
MessageProxySettings() {}
MessageProxySettings(const std::string &_proxy_host, const std::string &_proxy_auth, uint16_t _proxy_port)
:
proxy_host(_proxy_host), proxy_authentication(_proxy_auth), proxy_port(_proxy_port)
{}
const std::string &
getProxyHost() const
{
return proxy_host;
}
const std::string &
getProxyAuth() const
{
return proxy_authentication;
}
uint16_t
getProxyPort() const
{
return proxy_port;
}
template <class Archive>
void
serialize(Archive &ar)
{
ar(
cereal::make_nvp("proxy_host", proxy_host),
cereal::make_nvp("proxy_authentication", proxy_authentication),
cereal::make_nvp("proxy_port", proxy_port)
);
}
private:
std::string proxy_host = "";
std::string proxy_authentication = "";
uint16_t proxy_port = 0;
};
class MessageMetadata
{
public:
inline MessageMetadata();
MessageMetadata(const std::string &_host_name, uint16_t _port_num, bool _buffer = false, bool _fog = false) :
host_name(_host_name), port_num(_port_num), should_buffer(_buffer), is_to_fog(_fog)
{}
MessageMetadata(
std::string _host_name,
uint16_t _port_num,
Flags<MessageConnectionConfig> _conn_flags,
bool _should_buffer = false,
bool _is_to_fog = false
) :
host_name(_host_name),
port_num(_port_num),
conn_flags(_conn_flags),
should_buffer(_should_buffer),
is_to_fog(_is_to_fog)
{}
const std::string &
getHostName() const
{
return host_name;
}
const uint16_t &
getPort() const
{
return port_num;
}
void
setConnectioFlag(MessageConnectionConfig flag)
{
conn_flags.setFlag(flag);
}
const Flags<MessageConnectionConfig> &
getConnectionFlags() const
{
return conn_flags;
}
const MessageProxySettings &
getProxySettings() const
{
return proxy_settings;
}
const std::string &
getExternalCertificate() const
{
return external_certificate;
}
const std::map<std::string, std::string> &
getHeaders() const
{
return headers;
}
void
insertHeader(const std::string &header_key, const std::string &header_val)
{
headers[header_key] = header_val;
}
void
insertHeaders(const std::map<std::string, std::string> &_headers)
{
headers.insert(_headers.begin(), _headers.end());
}
void
setProxySettings(const MessageProxySettings &_proxy_settings)
{
proxy_settings = _proxy_settings;
is_proxy_set = true;
}
void
setExternalCertificate(const std::string &_external_certificate)
{
external_certificate = _external_certificate;
}
void
setShouldBufferMessage(bool _should_buffer)
{
should_buffer = _should_buffer;
}
bool
shouldBufferMessage() const
{
return should_buffer;
}
bool
isProxySet() const
{
return is_proxy_set;
}
bool
isToFog() const
{
return is_to_fog;
}
template <class Archive>
void
serialize(Archive &ar)
{
ar(
cereal::make_nvp("host_name", host_name),
cereal::make_nvp("port_num", port_num),
cereal::make_nvp("is_proxy_set", is_proxy_set),
cereal::make_nvp("headers", headers),
cereal::make_nvp("conn_flags", conn_flags),
cereal::make_nvp("external_certificate", external_certificate),
cereal::make_nvp("should_buffer", should_buffer),
cereal::make_nvp("is_to_fog", is_to_fog)
);
}
private:
std::string host_name = "";
uint16_t port_num = 0;
bool is_proxy_set = false;
std::map<std::string, std::string> headers;
Flags<MessageConnectionConfig> conn_flags;
MessageProxySettings proxy_settings;
std::string external_certificate = "";
bool should_buffer = false;
bool is_to_fog = false;
};
#endif // __MESSAGING_METADATA_H__

View File

0
core/include/services_sdk/interfaces/mock/mock_cpu.h Executable file → Normal file
View File

View File

@@ -29,6 +29,7 @@ public:
MOCK_CONST_METHOD0(getCurrentTrace, std::string());
MOCK_CONST_METHOD0(getCurrentSpan, std::string());
MOCK_METHOD0(getCurrentHeaders, std::string());
MOCK_METHOD0(getCurrentHeadersMap, std::map<std::string, std::string>());
MOCK_METHOD2(startNewTrace, void(bool, const std::string &));
MOCK_METHOD3(startNewSpan, void(Span::ContextType, const std::string &, const std::string &));

View File

View File

@@ -2,67 +2,69 @@
#define __MOCK_MESSAGING_H__
#include "i_messaging.h"
#include "cptest.h"
class MockMessaging : public Singleton::Provide<I_Messaging>::From<MockProvider<I_Messaging>>
{
public:
using string = std::string;
MOCK_METHOD10(
sendMessage,
Maybe<string> (
bool,
const string &,
Method,
const string &,
uint16_t,
Flags<MessageConnConfig> &,
MOCK_METHOD5(
sendSyncMessage,
Maybe<HTTPResponse, HTTPResponse> (
HTTPMethod,
const string &,
const string &,
I_Messaging::ErrorCB,
MessageTypeTag
MessageCategory,
MessageMetadata
)
);
MOCK_METHOD5(
sendAsyncMessage,
void (
HTTPMethod,
const string &,
const string &,
MessageCategory,
MessageMetadata
)
);
MOCK_METHOD7(
mockSendPersistentMessage,
Maybe<string>(bool, const string &, Method, const string &, const string &, bool, MessageTypeTag)
);
Maybe<string>
sendPersistentMessage(
bool get_reply,
const string &&body,
Method method,
const string &url,
const string &headers,
bool should_yield,
MessageTypeTag tag,
bool)
{
return mockSendPersistentMessage(get_reply, body, method, url, headers, should_yield, tag);
}
MOCK_METHOD8(
sendMessage,
Maybe<string> (
bool,
const string &,
Method,
MOCK_METHOD5(
downloadFile,
Maybe<HTTPStatusCode, HTTPResponse> (
HTTPMethod,
const string &,
const string &,
I_Messaging::ErrorCB,
bool,
MessageTypeTag
MessageCategory,
MessageMetadata
)
);
MOCK_METHOD0(setActiveFog, bool());
MOCK_METHOD1(setActiveFog, bool(MessageTypeTag));
MOCK_METHOD0(unsetFogProxy, void());
MOCK_METHOD0(loadFogProxy, void());
MOCK_METHOD4(setActiveFog, bool(const string &, const uint16_t, const bool, MessageTypeTag));
MOCK_METHOD4(
uploadFile,
Maybe<HTTPStatusCode, HTTPResponse> (
const string &,
const string &,
MessageCategory,
MessageMetadata
)
);
MOCK_METHOD4(setFogConnection, bool(const string &, uint16_t, bool, MessageCategory));
MOCK_METHOD0(setFogConnection, bool());
MOCK_METHOD1(setFogConnection, bool(MessageCategory));
};
static std::ostream &
operator<<(std::ostream &os, const HTTPResponse &)
{
return os;
}
static std::ostream &
operator<<(std::ostream &os, const HTTPStatusCode &)
{
return os;
}
#endif // __MOCK_MESSAGING_H__

Some files were not shown because too many files have changed in this diff Show More