mirror of
https://github.com/openappsec/openappsec.git
synced 2025-09-30 11:44:29 +03:00
First release of open-appsec source code
This commit is contained in:
62
core/include/services_sdk/interfaces/i_agent_details.h
Executable file
62
core/include/services_sdk/interfaces/i_agent_details.h
Executable file
@@ -0,0 +1,62 @@
|
||||
// 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 __I_AGENT_DETAILS_H__
|
||||
#define __I_AGENT_DETAILS_H__
|
||||
|
||||
#include <string>
|
||||
#include <map>
|
||||
#include "maybe_res.h"
|
||||
|
||||
enum class OrchestrationMode { ONLINE, OFFLINE, HYBRID, COUNT };
|
||||
|
||||
class I_AgentDetails
|
||||
{
|
||||
public:
|
||||
|
||||
// Fog Details
|
||||
virtual void setFogPort(const uint16_t _fog_port) = 0;
|
||||
virtual void setSSLFlag(const bool _is_over_ssl) = 0;
|
||||
virtual void setFogDomain(const std::string &_fog_domain) = 0;
|
||||
virtual void setProfileId(const std::string &_profile_id) = 0;
|
||||
virtual void setTenantId(const std::string &_tenant_id) = 0;
|
||||
|
||||
virtual Maybe<uint16_t> getFogPort() const = 0;
|
||||
virtual bool getSSLFlag() const = 0;
|
||||
virtual Maybe<std::string> getFogDomain() const = 0;
|
||||
virtual std::string getTenantId() const = 0;
|
||||
virtual std::string getProfileId() const = 0;
|
||||
|
||||
// Agent Details
|
||||
virtual Maybe<std::string> getProxy() const = 0;
|
||||
virtual void setProxy(const std::string &_proxy) = 0;
|
||||
virtual void setAgentId(const std::string &_agent_id) = 0;
|
||||
virtual std::string getAgentId() const = 0;
|
||||
virtual void setOrchestrationMode(OrchestrationMode _orchstration_mode) = 0;
|
||||
virtual OrchestrationMode getOrchestrationMode() const = 0;
|
||||
|
||||
// OpenSSL
|
||||
virtual void setOpenSSLDir(const std::string &openssl_dir) = 0;
|
||||
virtual Maybe<std::string> getOpenSSLDir() const = 0;
|
||||
|
||||
// Serialization
|
||||
virtual bool readAgentDetails() = 0;
|
||||
virtual bool writeAgentDetails() = 0;
|
||||
|
||||
// Environment
|
||||
virtual void setClusterId(const std::string &_cluster_id) = 0;
|
||||
|
||||
enum class MachineType { AZURE, AWS, ON_PREM, UNRECOGNIZED };
|
||||
};
|
||||
|
||||
#endif // __I_AGENT_DETAILS_H__
|
@@ -0,0 +1,55 @@
|
||||
// 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 __I_AGENT_DETAILS_REPORTER_H__
|
||||
#define __I_AGENT_DETAILS_REPORTER_H__
|
||||
|
||||
#include "cereal/archives/json.hpp"
|
||||
#include <string>
|
||||
#include <map>
|
||||
|
||||
#include "maybe_res.h"
|
||||
|
||||
class metaDataReport
|
||||
{
|
||||
public:
|
||||
metaDataReport() = default;
|
||||
metaDataReport(const metaDataReport &) = default;
|
||||
|
||||
metaDataReport & operator<<(const std::pair<std::string, std::string> &data);
|
||||
void serialize(cereal::JSONOutputArchive &out_ar) const;
|
||||
|
||||
private:
|
||||
std::map<std::string, std::string> agent_details;
|
||||
};
|
||||
|
||||
class I_AgentDetailsReporter
|
||||
{
|
||||
public:
|
||||
virtual void sendReport(
|
||||
const metaDataReport &agent_details,
|
||||
const Maybe<std::string> &policy_version,
|
||||
const Maybe<std::string> &platform,
|
||||
const Maybe<std::string> &architecture,
|
||||
const Maybe<std::string> &agent_version) = 0;
|
||||
|
||||
virtual bool addAttr(const std::string &key, const std::string &val, bool allow_override = false) = 0;
|
||||
virtual bool addAttr(const std::map<std::string, std::string> &attr, bool allow_override = false) = 0;
|
||||
virtual void deleteAttr(const std::string &key) = 0;
|
||||
virtual bool sendAttributes() = 0;
|
||||
|
||||
protected:
|
||||
~I_AgentDetailsReporter() = default;
|
||||
};
|
||||
|
||||
#endif // __I_AGENT_DETAILS_REPORTER_H__
|
41
core/include/services_sdk/interfaces/i_cpu.h
Executable file
41
core/include/services_sdk/interfaces/i_cpu.h
Executable file
@@ -0,0 +1,41 @@
|
||||
// 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 __I_CPU_H__
|
||||
#define __I_CPU_H__
|
||||
|
||||
#include "enum_array.h"
|
||||
|
||||
class I_CPU
|
||||
{
|
||||
public:
|
||||
enum CPUGeneralDataEntryType {
|
||||
USER,
|
||||
NICE,
|
||||
SYS,
|
||||
IDLE,
|
||||
IOWAIT,
|
||||
IRQ,
|
||||
SOFTIRQ,
|
||||
STEAL,
|
||||
GUEST,
|
||||
GUEST_NICE,
|
||||
|
||||
COUNT
|
||||
};
|
||||
|
||||
virtual double getCurrentProcessCPUUsage() = 0;
|
||||
virtual Maybe<double> getCurrentGeneralCPUUsage() = 0;
|
||||
};
|
||||
|
||||
#endif // __I_CPU_H__
|
44
core/include/services_sdk/interfaces/i_encryptor.h
Normal file
44
core/include/services_sdk/interfaces/i_encryptor.h
Normal file
@@ -0,0 +1,44 @@
|
||||
// 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 __I_ENCRYPTOR_H__
|
||||
#define __I_ENCRYPTOR_H__
|
||||
|
||||
#include "maybe_res.h"
|
||||
|
||||
#include <string>
|
||||
|
||||
static const std::string data1_file_name = "data1.a";
|
||||
static const std::string data4_file_name = "data4.a";
|
||||
static const std::string data6_file_name = "data6.a";
|
||||
|
||||
static const std::string user_cred_file_name = "data5.a";
|
||||
static const std::string proxy_auth_file_name = "data2.a";
|
||||
static const std::string session_token_file_name = "data3.a";
|
||||
|
||||
class I_Encryptor
|
||||
{
|
||||
public:
|
||||
// Base64
|
||||
virtual std::string base64Encode(const std::string &input) = 0;
|
||||
virtual std::string base64Decode(const std::string &input) = 0;
|
||||
|
||||
// Obfuscating
|
||||
virtual std::string obfuscateXor(const std::string &input) = 0;
|
||||
virtual std::string obfuscateXorBase64(const std::string &input) = 0;
|
||||
|
||||
protected:
|
||||
virtual ~I_Encryptor() {}
|
||||
};
|
||||
|
||||
#endif // __I_ENCRYPTOR_H__
|
116
core/include/services_sdk/interfaces/i_environment.h
Normal file
116
core/include/services_sdk/interfaces/i_environment.h
Normal file
@@ -0,0 +1,116 @@
|
||||
// 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 __I_ENVIRONMENT_H__
|
||||
#define __I_ENVIRONMENT_H__
|
||||
|
||||
#include <vector>
|
||||
#include <functional>
|
||||
|
||||
#include "context.h"
|
||||
#include "environment/span.h"
|
||||
#include "scope_exit.h"
|
||||
|
||||
class I_Environment
|
||||
{
|
||||
using Param = EnvKeyAttr::ParamAttr;
|
||||
|
||||
public:
|
||||
enum class TracingStatus { ON, OFF, DISABLED };
|
||||
|
||||
using ActiveContexts = std::pair<std::vector<Context *>, bool>;
|
||||
|
||||
template <typename T>
|
||||
Maybe<T, Context::Error>
|
||||
get(const std::string &name) const
|
||||
{
|
||||
auto active_contexts_vec = getActiveContexts().first;
|
||||
for (auto iter = active_contexts_vec.crbegin(); iter != active_contexts_vec.crend(); iter++) {
|
||||
auto value = (*iter)->get<T>(name);
|
||||
if (value.ok() || (value.getErr() != Context::Error::NO_VALUE)) return value;
|
||||
}
|
||||
return genError(Context::Error::NO_VALUE);
|
||||
}
|
||||
|
||||
template <typename T>
|
||||
Maybe<T, Context::Error>
|
||||
get(Context::MetaDataType name) const
|
||||
{
|
||||
return get<T>(Context::convertToString(name));
|
||||
}
|
||||
|
||||
virtual Context & getConfigurationContext() = 0;
|
||||
|
||||
template <typename T>
|
||||
void
|
||||
registerValue(const std::string &name, const T &value)
|
||||
{
|
||||
getConfigurationContext().registerValue(name, value);
|
||||
}
|
||||
|
||||
template <typename T>
|
||||
void
|
||||
unregisterKey(const std::string &name)
|
||||
{
|
||||
getConfigurationContext().unregisterKey<T>(name);
|
||||
}
|
||||
|
||||
template <typename ... Attr>
|
||||
std::map<std::string, std::string> getAllStrings(Attr ... attr) const { return getAllStrings(Param(attr ...)); }
|
||||
|
||||
template <typename ... Attr>
|
||||
std::map<std::string, uint64_t> getAllUints(Attr ... attr) const { return getAllUints(Param(attr ...)); }
|
||||
|
||||
template <typename ... Attr>
|
||||
std::map<std::string, bool> getAllBools(Attr ... attr) const { return getAllBools(Param(attr ...)); }
|
||||
|
||||
virtual void setActiveTenant(const std::string &tenant_id) = 0;
|
||||
virtual void unsetActiveTenant() = 0;
|
||||
|
||||
virtual std::string getCurrentTrace() const = 0;
|
||||
virtual std::string getCurrentSpan() const = 0;
|
||||
virtual std::string getCurrentHeaders() = 0;
|
||||
virtual void startNewTrace(bool new_span = true, const std::string &_trace_id = std::string()) = 0;
|
||||
virtual void startNewSpan(
|
||||
Span::ContextType _type,
|
||||
const std::string &prev_span = std::string(),
|
||||
const std::string &trace = std::string()
|
||||
) = 0;
|
||||
virtual std::scope_exit<std::function<void(void)>> startNewSpanScope(
|
||||
Span::ContextType _type,
|
||||
const std::string &prev_span = std::string(),
|
||||
const std::string &trace = std::string()
|
||||
) = 0;
|
||||
virtual void finishTrace(const std::string &trace = std::string()) = 0;
|
||||
virtual void finishSpan(const std::string &span = std::string()) = 0;
|
||||
|
||||
protected:
|
||||
~I_Environment() {}
|
||||
virtual const ActiveContexts & getActiveContexts() const = 0;
|
||||
virtual std::map<std::string, std::string> getAllStrings(const Param ¶m) const = 0;
|
||||
virtual std::map<std::string, uint64_t> getAllUints(const Param ¶m) const = 0;
|
||||
virtual std::map<std::string, bool> getAllBools(const Param ¶m) const = 0;
|
||||
|
||||
// Registration of Contexts should be done from the Context object, therefore only those object
|
||||
// should have access to the environment registration methods.
|
||||
friend class Context;
|
||||
virtual void registerContext(Context *ptr) = 0;
|
||||
virtual void unregisterContext(Context *ptr) = 0;
|
||||
|
||||
friend class MainloopComponent;
|
||||
virtual ActiveContexts createEnvironment() = 0;
|
||||
virtual ActiveContexts saveEnvironment() = 0;
|
||||
virtual void loadEnvironment(ActiveContexts &&env) = 0;
|
||||
};
|
||||
|
||||
#endif // __I_ENVIRONMENT_H__
|
22
core/include/services_sdk/interfaces/i_failopen.h
Executable file
22
core/include/services_sdk/interfaces/i_failopen.h
Executable file
@@ -0,0 +1,22 @@
|
||||
// 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 __I_FAILOPEN_H__
|
||||
#define __I_FAILOPEN_H__
|
||||
|
||||
class I_Failopen
|
||||
{
|
||||
virtual bool isFailOpenMode() const = 0;
|
||||
};
|
||||
|
||||
#endif // __I_FAILOPEN_H__
|
31
core/include/services_sdk/interfaces/i_health_check_manager.h
Executable file
31
core/include/services_sdk/interfaces/i_health_check_manager.h
Executable file
@@ -0,0 +1,31 @@
|
||||
// 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 __I_HEALTH_CHECK_MANAGER__
|
||||
#define __I_HEALTH_CHECK_MANAGER__
|
||||
|
||||
#include <fstream>
|
||||
|
||||
#include "health_check_status/health_check_status.h"
|
||||
|
||||
class I_Health_Check_Manager
|
||||
{
|
||||
public:
|
||||
virtual HealthCheckStatus getAggregatedStatus() = 0;
|
||||
virtual void printRepliesHealthStatus(std::ofstream &output_file) = 0;
|
||||
|
||||
protected:
|
||||
~I_Health_Check_Manager() {}
|
||||
};
|
||||
|
||||
#endif //__I_HEALTH_CHECK_MANAGER__
|
33
core/include/services_sdk/interfaces/i_instance_awareness.h
Normal file
33
core/include/services_sdk/interfaces/i_instance_awareness.h
Normal file
@@ -0,0 +1,33 @@
|
||||
// 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 __I_INSTANCE_AWARENESS_H__
|
||||
#define __I_INSTANCE_AWARENESS_H__
|
||||
|
||||
#include <string>
|
||||
|
||||
#include "maybe_res.h"
|
||||
|
||||
class I_InstanceAwareness
|
||||
{
|
||||
public:
|
||||
virtual Maybe<std::string> getUniqueID() = 0;
|
||||
virtual Maybe<std::string> getFamilyID() = 0;
|
||||
virtual Maybe<std::string> getInstanceID() = 0;
|
||||
|
||||
virtual std::string getUniqueID(const std::string &defaul_value) = 0;
|
||||
virtual std::string getFamilyID(const std::string &defaul_value) = 0;
|
||||
virtual std::string getInstanceID(const std::string &defaul_value) = 0;
|
||||
};
|
||||
|
||||
#endif // __I_INSTANCE_AWARENESS_H__
|
285
core/include/services_sdk/interfaces/i_intelligence_is_v2.h
Executable file
285
core/include/services_sdk/interfaces/i_intelligence_is_v2.h
Executable file
@@ -0,0 +1,285 @@
|
||||
// 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 __I_INTELLIGENCE_IS_V2_H__
|
||||
#define __I_INTELLIGENCE_IS_V2_H__
|
||||
|
||||
#include <chrono>
|
||||
|
||||
#include "maybe_res.h"
|
||||
#include "i_messaging.h"
|
||||
#include "i_time_get.h"
|
||||
#include "i_mainloop.h"
|
||||
#include "intelligence_is_v2/intelligence_types_v2.h"
|
||||
#include "intelligence_is_v2/intelligence_query_v2.h"
|
||||
#include "config.h"
|
||||
|
||||
class I_Intelligence_IS_V2
|
||||
{
|
||||
public:
|
||||
template<typename Data>
|
||||
Maybe<std::vector<AssetReply<Data>>>
|
||||
queryIntelligence(QueryRequest &query_request)
|
||||
{
|
||||
uint assets_limit = query_request.getAssetsLimit();
|
||||
static const uint upper_assets_limit = 50;
|
||||
if (assets_limit == 0 || assets_limit > upper_assets_limit) {
|
||||
return genError("Assets limit must be in the range of [1, " + std::to_string(upper_assets_limit) + "]");
|
||||
}
|
||||
|
||||
static const uint upper_confidence_limit = 1000;
|
||||
bool min_conf_res = query_request.checkMinConfidence(upper_confidence_limit);
|
||||
if (!min_conf_res) {
|
||||
return genError(
|
||||
"Minimum confidence value must be in the range of [1, " + std::to_string(upper_confidence_limit) + "]"
|
||||
);
|
||||
}
|
||||
|
||||
if (query_request.isPagingActivated() && query_request.isPagingFinished()) {
|
||||
return genError("Paging is activated and already finished. No need for more queries.");
|
||||
}
|
||||
|
||||
IntelligenceQuery<Data> intelligence_query(query_request);
|
||||
static const std::string query_uri = "/api/v2/intelligence/assets/query";
|
||||
|
||||
bool res = getIsOfflineOnly() ? false : sendQueryObject(intelligence_query, query_uri, assets_limit);
|
||||
if (!res) {
|
||||
dbgTrace(D_INTELLIGENCE) << "Could not message fog, trying to get offline intelligence.";
|
||||
Maybe<std::string> offline_res = getOfflineInfoString(query_request.getQuery());
|
||||
if (!offline_res.ok()) {
|
||||
dbgDebug(D_INTELLIGENCE) << "Offline intelligence error: " << offline_res.getErr();
|
||||
return genError("Could not query intelligence");
|
||||
}
|
||||
if (!intelligence_query.loadJson(offline_res.unpack())) {
|
||||
dbgWarning(D_INTELLIGENCE) << "Offline intelligence error: invalid JSON for requested asset";
|
||||
return genError("Could not query intelligence");
|
||||
}
|
||||
}
|
||||
|
||||
return intelligence_query.getData();
|
||||
}
|
||||
|
||||
private:
|
||||
template<typename Data>
|
||||
bool
|
||||
sendMessage(
|
||||
IntelligenceQuery<Data> &intelligence_query,
|
||||
const std::string &query_uri,
|
||||
I_Messaging *i_message,
|
||||
Flags<MessageConnConfig> conn_flags,
|
||||
const std::string &ip,
|
||||
uint server_port
|
||||
) {
|
||||
if (ip == "" && server_port == 0) {
|
||||
return i_message->sendObject(
|
||||
intelligence_query,
|
||||
I_Messaging::Method::POST,
|
||||
query_uri,
|
||||
"",
|
||||
nullptr,
|
||||
true,
|
||||
MessageTypeTag::INTELLIGENCE
|
||||
);
|
||||
}
|
||||
|
||||
return i_message->sendObject(
|
||||
intelligence_query,
|
||||
I_Messaging::Method::POST,
|
||||
ip,
|
||||
server_port,
|
||||
conn_flags,
|
||||
query_uri,
|
||||
"",
|
||||
nullptr,
|
||||
MessageTypeTag::INTELLIGENCE
|
||||
);
|
||||
}
|
||||
|
||||
template<typename Data>
|
||||
bool
|
||||
sendQueryMessage(
|
||||
IntelligenceQuery<Data> &intelligence_query,
|
||||
const std::string &query_uri,
|
||||
I_Messaging *i_message,
|
||||
Flags<MessageConnConfig> conn_flags,
|
||||
const std::string &ip = "",
|
||||
uint server_port = 0
|
||||
) {
|
||||
auto i_timer = getTimer();
|
||||
auto i_mainloop = getMainloop();
|
||||
|
||||
uint request_overall_timeout_conf = getConfigurationWithDefault<uint>(
|
||||
20,
|
||||
"intelligence",
|
||||
"request overall timeout"
|
||||
);
|
||||
|
||||
uint request_lap_timeout_conf = getConfigurationWithDefault<uint>(
|
||||
5,
|
||||
"intelligence",
|
||||
"request lap timeout"
|
||||
);
|
||||
|
||||
std::chrono::seconds request_overall_timeout = std::chrono::seconds(request_overall_timeout_conf);
|
||||
std::chrono::seconds request_lap_timeout = std::chrono::seconds(request_lap_timeout_conf);
|
||||
|
||||
std::chrono::microseconds send_request_start_time = i_timer->getMonotonicTime();
|
||||
std::chrono::microseconds last_lap_time = i_timer->getMonotonicTime();
|
||||
std::chrono::seconds seconds_since_start = std::chrono::seconds(0);
|
||||
std::chrono::seconds seconds_since_last_lap = std::chrono::seconds(0);
|
||||
|
||||
bool res= true;
|
||||
while (res &&
|
||||
intelligence_query.getResponseStatus() == ResponseStatus::IN_PROGRESS &&
|
||||
seconds_since_start < request_overall_timeout &&
|
||||
seconds_since_last_lap < request_lap_timeout
|
||||
) {
|
||||
res = sendMessage(intelligence_query, query_uri, i_message, conn_flags, ip, server_port);
|
||||
|
||||
if (res && intelligence_query.getResponseStatus() == ResponseStatus::IN_PROGRESS) {
|
||||
i_mainloop->yield(true);
|
||||
}
|
||||
|
||||
seconds_since_start = std::chrono::duration_cast<std::chrono::seconds>(
|
||||
i_timer->getMonotonicTime() - send_request_start_time
|
||||
);
|
||||
|
||||
seconds_since_last_lap = std::chrono::duration_cast<std::chrono::seconds>(
|
||||
i_timer->getMonotonicTime() - last_lap_time
|
||||
);
|
||||
last_lap_time = i_timer->getMonotonicTime();
|
||||
}
|
||||
|
||||
return res;
|
||||
}
|
||||
|
||||
template<typename Data>
|
||||
bool
|
||||
sendPagingQueryMessage(
|
||||
IntelligenceQuery<Data> &intelligence_query,
|
||||
const std::string &query_uri,
|
||||
int assets_limit,
|
||||
I_Messaging *i_message,
|
||||
Flags<MessageConnConfig> conn_flags,
|
||||
const std::string &ip = "",
|
||||
uint server_port = 0
|
||||
) {
|
||||
bool res= true;
|
||||
|
||||
res = sendMessage(intelligence_query, query_uri, i_message, conn_flags, ip, server_port);
|
||||
|
||||
if (intelligence_query.getResponseStatus() == ResponseStatus::DONE &&
|
||||
intelligence_query.getResponseAssetCollectionsSize() < assets_limit
|
||||
) {
|
||||
intelligence_query.setRequestCursor(Intelligence_IS_V2::CursorState::DONE, "");
|
||||
} else {
|
||||
intelligence_query.setRequestCursor(
|
||||
Intelligence_IS_V2::CursorState::IN_PROGRESS,
|
||||
intelligence_query.getResponseCursorVal()
|
||||
);
|
||||
}
|
||||
|
||||
return res;
|
||||
}
|
||||
|
||||
// LCOV_EXCL_START Reason: one templated instance is tested in intelligence ut. the rest are tested in system tests
|
||||
template<typename Data>
|
||||
bool
|
||||
sendQueryObjectToLocalServer(
|
||||
IntelligenceQuery<Data> &intelligence_query,
|
||||
const std::string &query_uri,
|
||||
const std::string &ip,
|
||||
bool is_primary_port,
|
||||
int assets_limit,
|
||||
I_Messaging *i_message,
|
||||
Flags<MessageConnConfig> 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";
|
||||
auto server_port = getSetting<uint>(
|
||||
"intelligence",
|
||||
is_primary_port ? primary_port_setting : secondary_port_setting
|
||||
);
|
||||
if (!server_port.ok()) return false;
|
||||
|
||||
conn_flags.reset();
|
||||
|
||||
if (intelligence_query.getPagingStatus().ok()) {
|
||||
return sendPagingQueryMessage(
|
||||
intelligence_query,
|
||||
query_uri,
|
||||
assets_limit,
|
||||
i_message,
|
||||
conn_flags,
|
||||
ip,
|
||||
*server_port
|
||||
);
|
||||
}
|
||||
|
||||
return sendQueryMessage(intelligence_query, query_uri, i_message, conn_flags, ip, *server_port);
|
||||
}
|
||||
// LCOV_EXCL_STOP
|
||||
|
||||
template<typename Data>
|
||||
bool
|
||||
sendQueryObject(IntelligenceQuery<Data> &intelligence_query, const std::string &query_uri, int assets_limit)
|
||||
{
|
||||
auto i_message = getMessaging();
|
||||
Flags<MessageConnConfig> conn_flags;
|
||||
|
||||
bool use_local_intelligence = getProfileAgentSettingWithDefault<bool>(
|
||||
false,
|
||||
"agent.config.useLocalIntelligence"
|
||||
);
|
||||
auto server_ip = getSetting<std::string>("intelligence", "local intelligence server ip");
|
||||
if (server_ip.ok() && use_local_intelligence) {
|
||||
if (sendQueryObjectToLocalServer(
|
||||
intelligence_query,
|
||||
query_uri,
|
||||
*server_ip,
|
||||
true,
|
||||
assets_limit,
|
||||
i_message,
|
||||
conn_flags
|
||||
)
|
||||
) {
|
||||
return true;
|
||||
}
|
||||
if (sendQueryObjectToLocalServer(
|
||||
intelligence_query,
|
||||
query_uri,
|
||||
*server_ip,
|
||||
false,
|
||||
assets_limit,
|
||||
i_message,
|
||||
conn_flags
|
||||
)
|
||||
) {
|
||||
return true;
|
||||
};
|
||||
}
|
||||
|
||||
if (intelligence_query.getPagingStatus().ok()) {
|
||||
return sendPagingQueryMessage(intelligence_query, query_uri, assets_limit, i_message, conn_flags);
|
||||
}
|
||||
|
||||
return sendQueryMessage(intelligence_query, query_uri, i_message, conn_flags);
|
||||
}
|
||||
|
||||
virtual I_Messaging * getMessaging() const = 0;
|
||||
virtual I_TimeGet * getTimer() const = 0;
|
||||
virtual I_MainLoop * getMainloop() const = 0;
|
||||
virtual Maybe<std::string> getOfflineInfoString(const SerializableQueryFilter &query) const = 0;
|
||||
virtual bool getIsOfflineOnly() const = 0;
|
||||
};
|
||||
#endif // __I_INTELLIGENCE_IS_V2_H__
|
29
core/include/services_sdk/interfaces/i_ioctl.h
Executable file
29
core/include/services_sdk/interfaces/i_ioctl.h
Executable file
@@ -0,0 +1,29 @@
|
||||
// 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 __I_IOCTL_H__
|
||||
#define __I_IOCTL_H__
|
||||
|
||||
#include "maybe_res.h"
|
||||
#include "common_is/ioctl_common.h"
|
||||
|
||||
class I_Ioctl
|
||||
{
|
||||
public:
|
||||
virtual Maybe<int> sendIoctl(AgentIoctlCmdNumber request, void *ioctl_data, uint32_t size_of_data) = 0;
|
||||
|
||||
protected:
|
||||
virtual ~I_Ioctl() {}
|
||||
};
|
||||
|
||||
#endif // __I_IOCTL_H__
|
41
core/include/services_sdk/interfaces/i_logging.h
Normal file
41
core/include/services_sdk/interfaces/i_logging.h
Normal file
@@ -0,0 +1,41 @@
|
||||
// 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 __I_LOGGING_H__
|
||||
#define __I_LOGGING_H__
|
||||
|
||||
#include <functional>
|
||||
|
||||
#include "report/report.h"
|
||||
#include "report/log_rest.h"
|
||||
|
||||
class I_Logging
|
||||
{
|
||||
public:
|
||||
using GeneralModifier = std::function<void(LogBulkRest &)>;
|
||||
|
||||
virtual bool addStream(ReportIS::StreamType type) = 0;
|
||||
virtual bool addStream(ReportIS::StreamType type, const std::string &log_server_url) = 0;
|
||||
virtual bool delStream(ReportIS::StreamType type) = 0;
|
||||
|
||||
virtual void sendLog(const Report &msg) = 0;
|
||||
|
||||
virtual uint64_t getCurrentLogId() = 0;
|
||||
|
||||
virtual void addGeneralModifier(const GeneralModifier &modifier) = 0;
|
||||
|
||||
protected:
|
||||
virtual ~I_Logging() {}
|
||||
};
|
||||
|
||||
#endif // __I_LOGGING_H__
|
87
core/include/services_sdk/interfaces/i_mainloop.h
Normal file
87
core/include/services_sdk/interfaces/i_mainloop.h
Normal file
@@ -0,0 +1,87 @@
|
||||
// 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 __I_MAINLOOP_H__
|
||||
#define __I_MAINLOOP_H__
|
||||
|
||||
#include <functional>
|
||||
#include <string>
|
||||
#include <chrono>
|
||||
|
||||
#include "maybe_res.h"
|
||||
|
||||
class I_MainLoop
|
||||
{
|
||||
public:
|
||||
using Routine = std::function<void(void)>;
|
||||
using RoutineID = uint;
|
||||
enum class RoutineType { RealTime, Timer, System, Offline };
|
||||
|
||||
// There are two types of routines:
|
||||
// 1. The primary routines that perform the main functionality of the product.
|
||||
// 2. The secondary routines that perform auxiliary functionality (upgrade, REST, etc.)
|
||||
// The mainloop needs to run only as long as there are any primary routines in effect.
|
||||
virtual RoutineID
|
||||
addOneTimeRoutine(
|
||||
RoutineType priority,
|
||||
Routine func,
|
||||
const std::string &routine_name,
|
||||
bool is_primary = false
|
||||
) = 0;
|
||||
|
||||
virtual RoutineID
|
||||
addRecurringRoutine(
|
||||
RoutineType priority,
|
||||
std::chrono::microseconds time,
|
||||
Routine func,
|
||||
const std::string &routine_name,
|
||||
bool is_primary = false
|
||||
) = 0;
|
||||
|
||||
virtual RoutineID
|
||||
addFileRoutine(
|
||||
RoutineType priority,
|
||||
int fd,
|
||||
Routine func,
|
||||
const std::string &routine_name,
|
||||
bool is_primary = false
|
||||
) = 0;
|
||||
|
||||
virtual bool doesRoutineExist(RoutineID id) = 0;
|
||||
|
||||
virtual Maybe<I_MainLoop::RoutineID> getCurrentRoutineId() const = 0;
|
||||
|
||||
virtual void run() = 0;
|
||||
|
||||
// When a routine yields the scheduler may choose to let it continue to run (in the case the routine didn't use
|
||||
// all of the time that was allocated to it). However, if the routine doesn't have more work to do at the moment
|
||||
// and wants not to be called directly again by the scheduler, it can force the scheduler not to call it back
|
||||
// immediately by setting `force` to true.
|
||||
virtual void yield(bool force = false) = 0;
|
||||
virtual void yield(std::chrono::microseconds time) = 0;
|
||||
void yield(int) = delete; // This prevents the syntax `yield(0)` which is otherwise ambiguous
|
||||
|
||||
virtual void stopAll() = 0;
|
||||
virtual void stop() = 0;
|
||||
virtual void stop(RoutineID id) = 0;
|
||||
|
||||
virtual void halt() = 0;
|
||||
virtual void halt(RoutineID id) = 0;
|
||||
|
||||
virtual void resume(RoutineID id) = 0;
|
||||
|
||||
protected:
|
||||
virtual ~I_MainLoop() {}
|
||||
};
|
||||
|
||||
#endif // __I_MAINLOOP_H__
|
194
core/include/services_sdk/interfaces/i_messaging.h
Executable file
194
core/include/services_sdk/interfaces/i_messaging.h
Executable file
@@ -0,0 +1,194 @@
|
||||
// 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 __I_FOG_MESSAGING_H__
|
||||
#define __I_FOG_MESSAGING_H__
|
||||
|
||||
#include <string>
|
||||
#include <sstream>
|
||||
#include <fstream>
|
||||
#include <functional>
|
||||
|
||||
#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 "flags.h"
|
||||
|
||||
USE_DEBUG_FLAG(D_COMMUNICATION);
|
||||
|
||||
enum class ProxyProtocol
|
||||
{
|
||||
HTTP,
|
||||
HTTPS
|
||||
};
|
||||
|
||||
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
|
||||
};
|
||||
|
||||
class I_Messaging
|
||||
{
|
||||
public:
|
||||
using string = std::string;
|
||||
using ErrorCB = std::function<void(HTTPStatusCode)>;
|
||||
|
||||
enum class Method { GET, POST, PATCH, CONNECT, PUT };
|
||||
|
||||
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;
|
||||
}
|
||||
|
||||
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();
|
||||
|
||||
|
||||
auto res_json = obj.loadJson(res.unpack());
|
||||
if (!res_json) {
|
||||
dbgWarning(D_COMMUNICATION) << "Failed to parse response body. Content: " << res.unpack();
|
||||
}
|
||||
dbgTrace(D_COMMUNICATION) << "Successfully parsed response body";
|
||||
return res_json;
|
||||
}
|
||||
|
||||
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;
|
||||
}
|
||||
|
||||
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 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 bool setActiveFog(MessageTypeTag tag) = 0;
|
||||
virtual void loadAccessToken() = 0;
|
||||
virtual bool setActiveFog(const string &host, const uint16_t port, bool is_secure, MessageTypeTag tag) = 0;
|
||||
virtual std::string getAccessToken() = 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,
|
||||
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;
|
||||
};
|
||||
|
||||
#endif // __I_FOG_MESSAGING_H__
|
33
core/include/services_sdk/interfaces/i_messaging_buffer.h
Normal file
33
core/include/services_sdk/interfaces/i_messaging_buffer.h
Normal file
@@ -0,0 +1,33 @@
|
||||
// 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 __I_MESSAGING_BUFFER_H__
|
||||
#define __I_MESSAGING_BUFFER_H__
|
||||
|
||||
#include "messaging_buffer/http_request_event.h"
|
||||
#include "maybe_res.h"
|
||||
|
||||
class I_MessagingBuffer
|
||||
{
|
||||
public:
|
||||
virtual Maybe<HTTPRequestEvent> peekRequest() = 0;
|
||||
virtual void popRequest() = 0;
|
||||
virtual void bufferNewRequest(const HTTPRequestEvent &request, bool is_rejected = false) = 0;
|
||||
virtual bool isPending(const HTTPRequestSignature &request) = 0;
|
||||
virtual void cleanBuffer() = 0;
|
||||
|
||||
protected:
|
||||
~I_MessagingBuffer() {}
|
||||
};
|
||||
|
||||
#endif // __I_MESSAGING_BUFFER_H__
|
38
core/include/services_sdk/interfaces/i_messaging_downloader.h
Executable file
38
core/include/services_sdk/interfaces/i_messaging_downloader.h
Executable file
@@ -0,0 +1,38 @@
|
||||
// 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 __I_MESSAGING_DOWNLOADER_H__
|
||||
#define __I_MESSAGING_DOWNLOADER_H__
|
||||
|
||||
#include <string>
|
||||
#include <functional>
|
||||
|
||||
#include "maybe_res.h"
|
||||
|
||||
class I_MessagingDownloader
|
||||
{
|
||||
public:
|
||||
using OnCompleteCB = std::function<void(const Maybe<std::string> &)>;
|
||||
|
||||
virtual bool downloadFile(
|
||||
const std::string &file_name,
|
||||
const std::string &url,
|
||||
OnCompleteCB cb = nullptr,
|
||||
const unsigned int port = 0
|
||||
) = 0;
|
||||
|
||||
protected:
|
||||
virtual ~I_MessagingDownloader() {}
|
||||
};
|
||||
|
||||
#endif // __I_MESSAGING_DOWNLOADER_H__
|
56
core/include/services_sdk/interfaces/i_rest_api.h
Normal file
56
core/include/services_sdk/interfaces/i_rest_api.h
Normal file
@@ -0,0 +1,56 @@
|
||||
// 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 __I_REST_API__
|
||||
#define __I_REST_API__
|
||||
|
||||
#include "rest.h"
|
||||
|
||||
#include <string>
|
||||
#include <memory>
|
||||
|
||||
#include "common.h"
|
||||
|
||||
enum class RestAction { ADD, SET, SHOW, DELETE };
|
||||
|
||||
// The RestInit class provides an interface through which new JsonRest object can be created.
|
||||
class RestInit
|
||||
{
|
||||
public:
|
||||
~RestInit() {}
|
||||
virtual std::unique_ptr<ServerRest> getRest() = 0;
|
||||
};
|
||||
|
||||
template <typename T>
|
||||
class SpecificRestInit : public RestInit
|
||||
{
|
||||
public:
|
||||
std::unique_ptr<ServerRest> getRest() override { return std::make_unique<T>(); }
|
||||
};
|
||||
|
||||
class I_RestApi
|
||||
{
|
||||
public:
|
||||
template <typename T>
|
||||
bool
|
||||
addRestCall(RestAction oper, const std::string &uri)
|
||||
{
|
||||
return addRestCall(oper, uri, std::make_unique<SpecificRestInit<T>>());
|
||||
}
|
||||
|
||||
protected:
|
||||
~I_RestApi() {}
|
||||
virtual bool addRestCall(RestAction oper, const std::string &uri, std::unique_ptr<RestInit> &&init) = 0;
|
||||
};
|
||||
|
||||
#endif // __I_REST_API__
|
34
core/include/services_sdk/interfaces/i_shell_cmd.h
Executable file
34
core/include/services_sdk/interfaces/i_shell_cmd.h
Executable file
@@ -0,0 +1,34 @@
|
||||
// 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 __I_SHELL_CMD_H__
|
||||
#define __I_SHELL_CMD_H__
|
||||
|
||||
#include <string>
|
||||
#include <utility>
|
||||
|
||||
#include "maybe_res.h"
|
||||
|
||||
class I_ShellCmd
|
||||
{
|
||||
using FullOutput = Maybe<std::pair<std::string, int>>;
|
||||
public:
|
||||
virtual Maybe<std::string> getExecOutput(const std::string &cmd, uint ms_tmout = 200, bool do_yield = false) = 0;
|
||||
virtual Maybe<int> getExecReturnCode(const std::string &cmd, uint ms_tmout = 200, bool do_yield = false) = 0;
|
||||
virtual FullOutput getExecOutputAndCode(const std::string &cmd, uint ms_tmout = 200, bool do_yield = false) = 0;
|
||||
|
||||
protected:
|
||||
virtual ~I_ShellCmd() {}
|
||||
};
|
||||
|
||||
#endif // __I_SHELL_CMD_H__
|
27
core/include/services_sdk/interfaces/i_signal_handler.h
Executable file
27
core/include/services_sdk/interfaces/i_signal_handler.h
Executable file
@@ -0,0 +1,27 @@
|
||||
// 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 __I_SIGNAL_HANDLER_H__
|
||||
#define __I_SIGNAL_HANDLER_H__
|
||||
|
||||
class I_SignalHandler
|
||||
{
|
||||
public:
|
||||
virtual void dumpErrorReport(const std::string &error) = 0;
|
||||
virtual Maybe<std::vector<std::string>> getBacktrace() = 0;
|
||||
|
||||
protected:
|
||||
~I_SignalHandler() {}
|
||||
};
|
||||
|
||||
#endif // __I_SIGNAL_HANDLER_H__
|
46
core/include/services_sdk/interfaces/i_socket_is.h
Executable file
46
core/include/services_sdk/interfaces/i_socket_is.h
Executable file
@@ -0,0 +1,46 @@
|
||||
// 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 __I_SOCKET_IS_H__
|
||||
#define __I_SOCKET_IS_H__
|
||||
|
||||
#include <string.h>
|
||||
#include <vector>
|
||||
|
||||
#include "maybe_res.h"
|
||||
|
||||
class I_Socket
|
||||
{
|
||||
public:
|
||||
enum class SocketType { UNIX, TCP, UDP };
|
||||
using socketFd = int;
|
||||
|
||||
virtual Maybe<socketFd>
|
||||
genSocket(SocketType type, bool is_blocking, bool is_server, const std::string &address) = 0;
|
||||
|
||||
virtual Maybe<socketFd> acceptSocket(
|
||||
socketFd server_socket_fd,
|
||||
bool is_blocking,
|
||||
const std::string &authorized_ip = ""
|
||||
) = 0;
|
||||
|
||||
virtual void closeSocket(socketFd &socket) = 0;
|
||||
virtual bool writeData(socketFd socket, const std::vector<char> &data) = 0;
|
||||
virtual Maybe<std::vector<char>> receiveData(socketFd socket, uint data_size, bool is_blocking = true) = 0;
|
||||
virtual bool isDataAvailable(socketFd socket) = 0;
|
||||
|
||||
protected:
|
||||
virtual ~I_Socket() {}
|
||||
};
|
||||
|
||||
#endif // __I_SOCKET_IS_H__
|
86
core/include/services_sdk/interfaces/i_table.h
Normal file
86
core/include/services_sdk/interfaces/i_table.h
Normal file
@@ -0,0 +1,86 @@
|
||||
// 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 __I_TABLE_H__
|
||||
#define __I_TABLE_H__
|
||||
|
||||
#include <chrono>
|
||||
#include <string>
|
||||
#include <typeindex>
|
||||
|
||||
#include "table/opaque_basic.h"
|
||||
#include "table_iter.h"
|
||||
#include "maybe_res.h"
|
||||
#include "cereal/archives/binary.hpp"
|
||||
|
||||
enum class SyncMode
|
||||
{
|
||||
DUPLICATE_ENTRY,
|
||||
TRANSFER_ENTRY
|
||||
};
|
||||
|
||||
class I_Table
|
||||
{
|
||||
public:
|
||||
template <typename Opaque>
|
||||
bool hasState() const;
|
||||
|
||||
template <typename Opaque, typename ...Args>
|
||||
bool createState(Args ...args);
|
||||
|
||||
template <typename Opaque>
|
||||
void deleteState();
|
||||
|
||||
template <typename Opaque>
|
||||
Opaque & getState();
|
||||
|
||||
virtual void setExpiration(std::chrono::milliseconds expire) = 0;
|
||||
virtual bool doesKeyExists() const = 0;
|
||||
virtual std::string keyToString() const = 0;
|
||||
virtual TableIter begin() const = 0;
|
||||
virtual TableIter end() const = 0;
|
||||
|
||||
protected:
|
||||
~I_Table() {}
|
||||
|
||||
virtual bool hasState (const std::type_index &index) const = 0;
|
||||
virtual bool createState(const std::type_index &index, std::unique_ptr<TableOpaqueBase> &&ptr) = 0;
|
||||
virtual bool deleteState(const std::type_index &index) = 0;
|
||||
virtual TableOpaqueBase * getState (const std::type_index &index) = 0;
|
||||
};
|
||||
|
||||
template <typename Key>
|
||||
class I_TableSpecific : public I_Table
|
||||
{
|
||||
public:
|
||||
virtual bool hasEntry (const Key &key) = 0;
|
||||
virtual bool createEntry (const Key &key, std::chrono::microseconds expire) = 0;
|
||||
virtual bool deleteEntry (const Key &key) = 0;
|
||||
virtual bool addLinkToEntry(const Key &key, const Key &link) = 0;
|
||||
virtual uint count () = 0;
|
||||
virtual void expireEntries () = 0;
|
||||
|
||||
virtual void saveEntry(TableIter iter, SyncMode mode, cereal::BinaryOutputArchive &ar) const = 0;
|
||||
virtual void loadEntry(cereal::BinaryInputArchive &ar) = 0;
|
||||
|
||||
virtual bool setActiveKey (const Key &key) = 0;
|
||||
virtual void unsetActiveKey () = 0;
|
||||
virtual Maybe<Key, void> getCurrentKey() const = 0;
|
||||
|
||||
protected:
|
||||
~I_TableSpecific() {}
|
||||
};
|
||||
|
||||
#include "table/i_table_impl.h"
|
||||
|
||||
#endif // __I_TABLE_H__
|
28
core/include/services_sdk/interfaces/i_table_iter.h
Normal file
28
core/include/services_sdk/interfaces/i_table_iter.h
Normal file
@@ -0,0 +1,28 @@
|
||||
// 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 __I_TABLE_ITER_H__
|
||||
#define __I_TABLE_ITER_H__
|
||||
|
||||
class I_TableIter
|
||||
{
|
||||
public:
|
||||
virtual ~I_TableIter() {}
|
||||
virtual void operator++() = 0;
|
||||
virtual void operator++(int) = 0;
|
||||
virtual void setEntry() = 0;
|
||||
virtual void unsetEntry() = 0;
|
||||
virtual void * getUniqueId() const = 0;
|
||||
};
|
||||
|
||||
#endif // __I_TABLE_ITER_H__
|
49
core/include/services_sdk/interfaces/i_tenant_manager.h
Normal file
49
core/include/services_sdk/interfaces/i_tenant_manager.h
Normal file
@@ -0,0 +1,49 @@
|
||||
// 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 __I_TENANT_MANAGER_H__
|
||||
#define __I_TENANT_MANAGER_H__
|
||||
|
||||
#include <string>
|
||||
#include <vector>
|
||||
#include <chrono>
|
||||
#include <functional>
|
||||
|
||||
class I_TenantManager
|
||||
{
|
||||
public:
|
||||
using newTenantCB = std::function<void(const std::vector<std::string> &)>;
|
||||
|
||||
virtual void uponNewTenants(const newTenantCB &cb) = 0;
|
||||
virtual bool isTenantActive(const std::string &tenant_id) const = 0;
|
||||
|
||||
virtual std::vector<std::string> fetchActiveTenants() const = 0;
|
||||
virtual std::vector<std::string> getInstances(const std::string &tenant_id) const = 0;
|
||||
|
||||
virtual void addActiveTenant(const std::string &tenant_id) = 0;
|
||||
virtual void addActiveTenants(const std::vector<std::string> &tenants_id) = 0;
|
||||
|
||||
virtual void deactivateTenant(const std::string &tenant_id) = 0;
|
||||
virtual void deactivateTenants(const std::vector<std::string> &tenants_id) = 0;
|
||||
|
||||
virtual std::chrono::microseconds getTimeoutVal() const = 0;
|
||||
|
||||
private:
|
||||
friend class LoadNewTenants;
|
||||
virtual void addInstance(const std::string &tenant_id, const std::string &instace_id) = 0;
|
||||
|
||||
protected:
|
||||
virtual ~I_TenantManager() {}
|
||||
};
|
||||
|
||||
#endif // __I_TENANT_MANAGER_H__
|
33
core/include/services_sdk/interfaces/i_time_get.h
Normal file
33
core/include/services_sdk/interfaces/i_time_get.h
Normal file
@@ -0,0 +1,33 @@
|
||||
// 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 __I_TIME_GET_H__
|
||||
#define __I_TIME_GET_H__
|
||||
|
||||
#include <string>
|
||||
#include <chrono>
|
||||
|
||||
class I_TimeGet
|
||||
{
|
||||
public:
|
||||
virtual std::chrono::microseconds getMonotonicTime() = 0;
|
||||
virtual std::chrono::microseconds getWalltime() = 0;
|
||||
virtual std::string getWalltimeStr() = 0;
|
||||
virtual std::string getWalltimeStr(const std::chrono::microseconds &ms) = 0;
|
||||
virtual std::string getLocalTimeStr() = 0;
|
||||
|
||||
protected:
|
||||
virtual ~I_TimeGet() {}
|
||||
};
|
||||
|
||||
#endif // __I_TIME_GET_H__
|
29
core/include/services_sdk/interfaces/i_time_set.h
Normal file
29
core/include/services_sdk/interfaces/i_time_set.h
Normal file
@@ -0,0 +1,29 @@
|
||||
// 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 __I_TIME_SET_H__
|
||||
#define __I_TIME_SET_H__
|
||||
|
||||
#include <chrono>
|
||||
|
||||
class I_TimeSet
|
||||
{
|
||||
public:
|
||||
virtual void setMonotonicTime(std::chrono::microseconds new_time) = 0;
|
||||
virtual void setWalltime(std::chrono::microseconds new_time) = 0;
|
||||
|
||||
protected:
|
||||
virtual ~I_TimeSet() {}
|
||||
};
|
||||
|
||||
#endif // __I_TIME_SET_H__
|
33
core/include/services_sdk/interfaces/i_trap_handler.h
Executable file
33
core/include/services_sdk/interfaces/i_trap_handler.h
Executable file
@@ -0,0 +1,33 @@
|
||||
// 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 __I_TRAP_HANDLER_H__
|
||||
#define __I_TRAP_HANDLER_H__
|
||||
|
||||
#include <signal.h>
|
||||
|
||||
#include "maybe_res.h"
|
||||
#include "common_is/trap_common.h"
|
||||
|
||||
class I_TrapHandler
|
||||
{
|
||||
public:
|
||||
using SignalHandler = std::function<Maybe<bool>(AgentTrapCmd)>;
|
||||
virtual Maybe<bool> registerTrap(AgentTrapCmd cmd, SignalHandler signal_handler) = 0;
|
||||
virtual void signalFunctionHandler(siginfo_t *info) = 0;
|
||||
|
||||
protected:
|
||||
virtual ~I_TrapHandler() {}
|
||||
};
|
||||
|
||||
#endif // __I_TRAP_HANDLER_H__
|
71
core/include/services_sdk/interfaces/intelligence_is_v2/asset_source_v2.h
Executable file
71
core/include/services_sdk/interfaces/intelligence_is_v2/asset_source_v2.h
Executable file
@@ -0,0 +1,71 @@
|
||||
// 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 __ASSET_SOURCE_V2_H__
|
||||
#define __ASSET_SOURCE_V2_H__
|
||||
|
||||
#include "debug.h"
|
||||
#include "intelligence_types_v2.h"
|
||||
#include "cereal/archives/json.hpp"
|
||||
#include "cereal/types/vector.hpp"
|
||||
#include "customized_cereal_map.h"
|
||||
|
||||
template <typename UserSerializableReplyAttr>
|
||||
class SerializableAssetSource
|
||||
{
|
||||
public:
|
||||
SerializableAssetSource() {}
|
||||
|
||||
void load(cereal::JSONInputArchive &ar);
|
||||
|
||||
const std::string & getTenantId() const { return tenant_id; }
|
||||
const std::string & getSourceId() const { return source_id; }
|
||||
const std::string & getAssetId() const { return asset_id; }
|
||||
const std::chrono::seconds getTTL() const { return ttl; }
|
||||
const std::string & getExpirationTime() const { return expiration_time; }
|
||||
uint getConfidence() const { return confidence; }
|
||||
const std::vector<UserSerializableReplyAttr> & getAttributes() const { return attributes; }
|
||||
|
||||
UserSerializableReplyAttr
|
||||
mergeReplyData() const
|
||||
{
|
||||
UserSerializableReplyAttr reply_data;
|
||||
for (const UserSerializableReplyAttr &reply_attr : attributes) {
|
||||
reply_data.insert(reply_attr);
|
||||
}
|
||||
return reply_data;
|
||||
}
|
||||
|
||||
template <typename Values>
|
||||
bool
|
||||
matchValues(const Values &requested_vals) const
|
||||
{
|
||||
for (const UserSerializableReplyAttr &recieved_attr : attributes) {
|
||||
if (recieved_attr.matchValues(requested_vals)) return true;
|
||||
}
|
||||
return false;
|
||||
}
|
||||
|
||||
private:
|
||||
std::string tenant_id = "";
|
||||
std::string source_id = "";
|
||||
std::string asset_id = "";
|
||||
std::chrono::seconds ttl = std::chrono::seconds::zero();
|
||||
std::string expiration_time = "";
|
||||
uint confidence = 0;
|
||||
std::vector<UserSerializableReplyAttr> attributes;
|
||||
};
|
||||
|
||||
#include "asset_source_v2_impl.h"
|
||||
|
||||
#endif //__ASSET_SOURCE_V2_H__
|
@@ -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 __ASSET_SOURCE_V2_IMPL_H__
|
||||
#define __ASSET_SOURCE_V2_IMPL_H__
|
||||
|
||||
#ifndef __ASSET_SOURCE_V2_H__
|
||||
#error intelligence_query_impl_8_0.h should not be included directly!
|
||||
#endif //__ASSET_V2_SOURCE_H__
|
||||
|
||||
USE_DEBUG_FLAG(D_INTELLIGENCE);
|
||||
|
||||
template <typename UserSerializableReplyAttr>
|
||||
void
|
||||
SerializableAssetSource<UserSerializableReplyAttr>::load(cereal::JSONInputArchive &ar)
|
||||
{
|
||||
uint raw_seconds;
|
||||
ar(
|
||||
cereal::make_nvp("tenantId", tenant_id),
|
||||
cereal::make_nvp("sourceId", source_id),
|
||||
cereal::make_nvp("assetId", asset_id),
|
||||
cereal::make_nvp("ttl", raw_seconds),
|
||||
cereal::make_nvp("expirationTime", expiration_time),
|
||||
cereal::make_nvp("confidence", confidence)
|
||||
);
|
||||
ttl = std::chrono::seconds(raw_seconds);
|
||||
|
||||
UserSerializableReplyAttr raw_attribute;
|
||||
try {
|
||||
ar(cereal::make_nvp("attributes", raw_attribute));
|
||||
} catch(const std::exception &e) {}
|
||||
attributes.push_back(raw_attribute);
|
||||
}
|
||||
|
||||
#endif //__ASSET_SOURCE_V2_IMPL_H__
|
@@ -0,0 +1,55 @@
|
||||
// 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 __INTELLIGENCE_QUERY_V2_H__
|
||||
#define __INTELLIGENCE_QUERY_V2_H__
|
||||
|
||||
#include "cereal/archives/json.hpp"
|
||||
#include "intelligence_types_v2.h"
|
||||
#include "query_request_v2.h"
|
||||
#include "query_response_v2.h"
|
||||
#include "rest.h"
|
||||
|
||||
template <typename UserSerializableReplyAttr>
|
||||
class IntelligenceQuery
|
||||
{
|
||||
public:
|
||||
IntelligenceQuery(QueryRequest &filter)
|
||||
:
|
||||
request(filter),
|
||||
response()
|
||||
{}
|
||||
|
||||
Maybe<std::string> genJson() const;
|
||||
bool loadJson(const std::string &json);
|
||||
|
||||
void load(cereal::JSONInputArchive &ar);
|
||||
void save(cereal::JSONOutputArchive &ar) const;
|
||||
|
||||
std::vector<AssetReply<UserSerializableReplyAttr>> getData();
|
||||
ResponseStatus getResponseStatus() { return response.getResponseStatus(); }
|
||||
int getResponseAssetCollectionsSize() const { return response.getAssetCollectionsSize(); }
|
||||
const std::string & getResponseCursorVal() const { return response.getCursor(); }
|
||||
|
||||
void activatePaging();
|
||||
Maybe<Intelligence_IS_V2::CursorState> getPagingStatus();
|
||||
void setRequestCursor(CursorState state, const std::string &value);
|
||||
|
||||
private:
|
||||
QueryRequest &request;
|
||||
IntelligenceQueryResponse<UserSerializableReplyAttr> response;
|
||||
};
|
||||
|
||||
#include "intelligence_query_v2_impl.h"
|
||||
|
||||
#endif // __INTELLIGENCE_QUERY_V2_H__
|
@@ -0,0 +1,100 @@
|
||||
// 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 __INTELLIGENCE_QUERY_V2_IMPL_H_
|
||||
#define __INTELLIGENCE_QUERY_V2_IMPL_H_
|
||||
|
||||
#ifndef __INTELLIGENCE_QUERY_V2_H__
|
||||
#error intelligence_query_impl_v2.h should not be included directly!
|
||||
#endif // __INTELLIGENCE_QUERY_V2_H__
|
||||
|
||||
USE_DEBUG_FLAG(D_INTELLIGENCE);
|
||||
|
||||
template <typename UserSerializableReplyAttr>
|
||||
Maybe<std::string>
|
||||
IntelligenceQuery<UserSerializableReplyAttr>::genJson() const
|
||||
{
|
||||
{
|
||||
std::stringstream out;
|
||||
{
|
||||
cereal::JSONOutputArchive out_ar(out);
|
||||
request.saveToJson(out_ar);
|
||||
}
|
||||
return out.str();
|
||||
}
|
||||
}
|
||||
|
||||
template <typename UserSerializableReplyAttr>
|
||||
bool
|
||||
IntelligenceQuery<UserSerializableReplyAttr>::loadJson(const std::string &json)
|
||||
{
|
||||
try {
|
||||
std::stringstream in;
|
||||
in.str(json);
|
||||
try {
|
||||
cereal::JSONInputArchive in_ar(in);
|
||||
load(in_ar);
|
||||
} catch (const Intelligence_IS_V2::IntelligenceException &e) {
|
||||
dbgWarning(D_INTELLIGENCE) << "Failed to load query response. Error: " << e.what();
|
||||
return false;
|
||||
}
|
||||
return true;
|
||||
} catch (const std::exception &e) {
|
||||
return false;
|
||||
}
|
||||
}
|
||||
|
||||
template <typename UserSerializableReplyAttr>
|
||||
void
|
||||
IntelligenceQuery<UserSerializableReplyAttr>::load(cereal::JSONInputArchive &ar)
|
||||
{
|
||||
response.loadFromJson(ar);
|
||||
}
|
||||
|
||||
template <typename UserSerializableReplyAttr>
|
||||
void
|
||||
IntelligenceQuery<UserSerializableReplyAttr>::save(cereal::JSONOutputArchive &ar) const
|
||||
{
|
||||
request.saveToJson(ar);
|
||||
}
|
||||
|
||||
template <typename UserSerializableReplyAttr>
|
||||
std::vector<AssetReply<UserSerializableReplyAttr>>
|
||||
IntelligenceQuery<UserSerializableReplyAttr>::getData()
|
||||
{
|
||||
return response.getData();
|
||||
}
|
||||
|
||||
template <typename UserSerializableReplyAttr>
|
||||
void
|
||||
IntelligenceQuery<UserSerializableReplyAttr>::activatePaging()
|
||||
{
|
||||
request.setCursor(Intelligence_IS_V2::CursorState::START, "start");
|
||||
}
|
||||
|
||||
template <typename UserSerializableReplyAttr>
|
||||
Maybe<Intelligence_IS_V2::CursorState>
|
||||
IntelligenceQuery<UserSerializableReplyAttr>::getPagingStatus()
|
||||
{
|
||||
if (!request.isPagingActivated()) return genError("Paging not activated");
|
||||
return request.getCursorState();
|
||||
}
|
||||
|
||||
template <typename UserSerializableReplyAttr>
|
||||
void
|
||||
IntelligenceQuery<UserSerializableReplyAttr>::setRequestCursor(CursorState state, const std::string &value)
|
||||
{
|
||||
request.setCursor(state, value);
|
||||
}
|
||||
|
||||
#endif //__INTELLIGENCE_QUERY_V2_IMPL_H_
|
@@ -0,0 +1,80 @@
|
||||
// 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 __INTELLIGENCE_TYPES_V2_H__
|
||||
#define __INTELLIGENCE_TYPES_V2_H__
|
||||
|
||||
#include <string>
|
||||
#include <chrono>
|
||||
#include <unordered_map>
|
||||
#include "debug.h"
|
||||
|
||||
namespace Intelligence_IS_V2
|
||||
{
|
||||
|
||||
enum class AttributeKeyType {
|
||||
MAIN,
|
||||
REGULAR,
|
||||
NONE
|
||||
};
|
||||
|
||||
enum class Operator
|
||||
{
|
||||
AND,
|
||||
OR,
|
||||
NONE
|
||||
};
|
||||
|
||||
enum class Condition
|
||||
{
|
||||
EQUALS,
|
||||
NOT_EQUALS,
|
||||
MATCH,
|
||||
STARTS_WITH,
|
||||
CONTAINS,
|
||||
IN,
|
||||
NOT_IN
|
||||
};
|
||||
|
||||
enum class CursorState {
|
||||
START,
|
||||
IN_PROGRESS,
|
||||
DONE
|
||||
};
|
||||
|
||||
enum class ResponseStatus
|
||||
{
|
||||
DONE,
|
||||
IN_PROGRESS
|
||||
};
|
||||
|
||||
const std::string & convertConditionTypeToString(const Condition &condition_type);
|
||||
const std::string & convertOperationTypeToString(const Operator &operation_type);
|
||||
std::string createAttributeString(const std::string &key, AttributeKeyType type);
|
||||
ResponseStatus convertStringToResponseStatus(const std::string &status);
|
||||
|
||||
class IntelligenceException : public std::exception
|
||||
{
|
||||
public:
|
||||
IntelligenceException() : message() {}
|
||||
IntelligenceException(const std::string &msg) : message(msg) {}
|
||||
|
||||
const char * what() const throw() { return message.c_str(); }
|
||||
|
||||
private:
|
||||
std::string message;
|
||||
};
|
||||
|
||||
} // namespace Intelligence_IS_V2
|
||||
|
||||
#endif // __INTELLIGENCE_TYPES_V2_H__
|
90
core/include/services_sdk/interfaces/intelligence_is_v2/query_filter_v2.h
Executable file
90
core/include/services_sdk/interfaces/intelligence_is_v2/query_filter_v2.h
Executable file
@@ -0,0 +1,90 @@
|
||||
// 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 __QUERY_FILTER_V2_H__
|
||||
#define __QUERY_FILTER_V2_H__
|
||||
|
||||
#include <string>
|
||||
#include <chrono>
|
||||
#include <boost/functional/hash.hpp>
|
||||
|
||||
#include "cereal/archives/json.hpp"
|
||||
#include "cereal/types/vector.hpp"
|
||||
#include "debug.h"
|
||||
#include "intelligence_types_v2.h"
|
||||
#include "maybe_res.h"
|
||||
|
||||
using namespace Intelligence_IS_V2;
|
||||
|
||||
class SerializableQueryCondition
|
||||
{
|
||||
public:
|
||||
SerializableQueryCondition() {}
|
||||
|
||||
SerializableQueryCondition(Condition _condition_type, std::string _key, std::string _value)
|
||||
:
|
||||
condition_type(_condition_type),
|
||||
key(_key),
|
||||
value(_value)
|
||||
{};
|
||||
|
||||
void save(cereal::JSONOutputArchive &ar) const;
|
||||
|
||||
Condition getConditionType() const { return condition_type; }
|
||||
const std::string & getKey() const { return key; }
|
||||
const std::string & getValue() const { return value; }
|
||||
|
||||
private:
|
||||
Condition condition_type = Condition::EQUALS;
|
||||
std::string key = "";
|
||||
std::string value = "";
|
||||
};
|
||||
|
||||
class SerializableQueryFilter
|
||||
{
|
||||
public:
|
||||
SerializableQueryFilter() {}
|
||||
SerializableQueryFilter(Condition condition_type, const std::string &key, const std::string &value);
|
||||
SerializableQueryFilter(
|
||||
Operator operator_type,
|
||||
Condition condition_type,
|
||||
const std::string &key,
|
||||
const std::string &value
|
||||
);
|
||||
|
||||
void save(cereal::JSONOutputArchive &ar) const;
|
||||
|
||||
void addCondition(Condition condition_type, const std::string &key, const std::string &value);
|
||||
|
||||
Operator getOperator() const { return operator_type; }
|
||||
const std::vector<SerializableQueryCondition> & getConditionOperands() const { return condition_operands; }
|
||||
const std::vector<SerializableQueryFilter> & getQueriesOperands() const { return queries_operands; }
|
||||
|
||||
const std::string & getConditionValueByKey(const std::string &key) const;
|
||||
|
||||
bool empty() const { return condition_operands.empty() && queries_operands.empty(); }
|
||||
|
||||
SerializableQueryFilter operator &&(const SerializableQueryFilter &other_query);
|
||||
SerializableQueryFilter operator ||(const SerializableQueryFilter &other_query);
|
||||
|
||||
private:
|
||||
void saveCondition(cereal::JSONOutputArchive &ar) const;
|
||||
void saveOperation(cereal::JSONOutputArchive &ar) const;
|
||||
SerializableQueryFilter calcOperator(const SerializableQueryFilter &other_query, const Operator &operator_type);
|
||||
|
||||
Operator operator_type = Operator::NONE;
|
||||
std::vector<SerializableQueryFilter> queries_operands = {};
|
||||
std::vector<SerializableQueryCondition> condition_operands = {};
|
||||
};
|
||||
|
||||
#endif // __QUERY_FILTER_V2_H__
|
92
core/include/services_sdk/interfaces/intelligence_is_v2/query_request_v2.h
Executable file
92
core/include/services_sdk/interfaces/intelligence_is_v2/query_request_v2.h
Executable file
@@ -0,0 +1,92 @@
|
||||
// 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 __QUERY_REQUEST_V2_H__
|
||||
#define __QUERY_REQUEST_V2_H__
|
||||
|
||||
#include "rest.h"
|
||||
#include "common.h"
|
||||
#include "intelligence_is_v2/intelligence_types_v2.h"
|
||||
#include "intelligence_is_v2/query_filter_v2.h"
|
||||
#include "intelligence_is_v2/requested_attributes_v2.h"
|
||||
#include "intelligence_is_v2/query_types_v2.h"
|
||||
#include "maybe_res.h"
|
||||
|
||||
class QueryRequest
|
||||
{
|
||||
public:
|
||||
using RequestCursor = std::pair<CursorState, std::string>;
|
||||
|
||||
QueryRequest() {}
|
||||
|
||||
QueryRequest(
|
||||
Condition condition_type,
|
||||
const std::string &key,
|
||||
const std::string &value,
|
||||
bool full_response,
|
||||
AttributeKeyType type = AttributeKeyType::MAIN
|
||||
);
|
||||
|
||||
void saveToJson(cereal::JSONOutputArchive &ar) const;
|
||||
|
||||
uint getAssetsLimit() const;
|
||||
const SerializableQueryFilter & getQuery() const;
|
||||
const SerializableAttributesMap & getRequestedAttributes() const;
|
||||
|
||||
void addCondition(
|
||||
Condition condition_type,
|
||||
const std::string &key,
|
||||
const std::string &value,
|
||||
AttributeKeyType attribute_type = AttributeKeyType::MAIN
|
||||
);
|
||||
|
||||
void setRequestedAttr(
|
||||
const std::string &attr,
|
||||
AttributeKeyType attribute_type = AttributeKeyType::REGULAR
|
||||
);
|
||||
|
||||
void setRequestedAttr(
|
||||
const std::string &attr,
|
||||
uint min_conf,
|
||||
AttributeKeyType = AttributeKeyType::REGULAR
|
||||
);
|
||||
|
||||
void setTenantsList(const std::vector<std::string> tenants);
|
||||
|
||||
void setAssetsLimit(uint _assets_limit);
|
||||
bool checkMinConfidence(uint upper_confidence_limit);
|
||||
|
||||
void activatePaging();
|
||||
bool isPagingActivated();
|
||||
Maybe<CursorState> getCursorState();
|
||||
bool isPagingFinished();
|
||||
void setCursor(CursorState state, const std::string &value);
|
||||
bool empty() const { return query.empty(); }
|
||||
|
||||
QueryRequest operator &&(const QueryRequest &other_query);
|
||||
QueryRequest operator ||(const QueryRequest &other_query);
|
||||
|
||||
static const uint default_min_confidence;
|
||||
static const uint default_assets_limit;
|
||||
|
||||
private:
|
||||
uint assets_limit = default_assets_limit;
|
||||
bool full_response = false;
|
||||
Maybe<RequestCursor> cursor = genError("Cursor not initialized");
|
||||
SerializableQueryFilter query;
|
||||
SerializableAttributesMap requested_attributes;
|
||||
SerializableQueryTypes query_types;
|
||||
QueryRequest calcQueryRequestOperator(const QueryRequest &other_query, const Operator &operator_type);
|
||||
};
|
||||
|
||||
#endif // __QUERY_REQUEST_V2_H__
|
120
core/include/services_sdk/interfaces/intelligence_is_v2/query_response_v2.h
Executable file
120
core/include/services_sdk/interfaces/intelligence_is_v2/query_response_v2.h
Executable file
@@ -0,0 +1,120 @@
|
||||
// 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 __QUERY_RESPONSE_V2_H__
|
||||
#define __QUERY_RESPONSE_V2_H__
|
||||
|
||||
#include <sstream>
|
||||
#include <vector>
|
||||
#include <map>
|
||||
|
||||
#include "cereal/archives/json.hpp"
|
||||
#include "cereal/types/vector.hpp"
|
||||
#include "cereal/types/map.hpp"
|
||||
|
||||
#include "debug.h"
|
||||
#include "maybe_res.h"
|
||||
#include "customized_cereal_map.h"
|
||||
#include "customized_cereal_multimap.h"
|
||||
#include "intelligence_types_v2.h"
|
||||
#include "asset_source_v2.h"
|
||||
|
||||
USE_DEBUG_FLAG(D_INTELLIGENCE);
|
||||
|
||||
template <typename UserSerializableReplyAttr>
|
||||
class AssetReply
|
||||
{
|
||||
public:
|
||||
AssetReply() {}
|
||||
|
||||
void load(cereal::JSONInputArchive &ar);
|
||||
std::vector<UserSerializableReplyAttr> getData() const;
|
||||
const std::map<std::string, std::vector<std::string>> & getMainAttributes() const { return main_attributes; }
|
||||
const std::vector<SerializableAssetSource<UserSerializableReplyAttr>> & getSources() const { return sources; }
|
||||
|
||||
uint getAssetSchemaVersion() const { return asset_schema_version; }
|
||||
const std::string & getAssetType() const { return asset_type; }
|
||||
uint getAssetTypeSchemaVersion() const { return asset_type_schema_version; }
|
||||
const std::string & getAssetPermissionGroupId() const { return asset_permission_group_id; }
|
||||
const std::string & getAssetName() const { return asset_name; }
|
||||
const std::string & getAssetID() const { return asset_id; }
|
||||
const std::string & getAssetClass() const { return asset_class; }
|
||||
const std::string & getAssetCategory() const { return asset_category; }
|
||||
const std::string & getAssetFamily() const { return asset_family; }
|
||||
const std::string & getAssetGroup() const { return asset_group; }
|
||||
const std::string & getAssetOrder() const { return asset_order; }
|
||||
const std::string & getAssetKind() const { return asset_kind; }
|
||||
|
||||
UserSerializableReplyAttr
|
||||
mergeReplyData() const
|
||||
{
|
||||
UserSerializableReplyAttr reply_data;
|
||||
for (const SerializableAssetSource<UserSerializableReplyAttr> &source : sources) {
|
||||
UserSerializableReplyAttr data_by_source = source.mergeReplyData();
|
||||
reply_data.insert(data_by_source);
|
||||
}
|
||||
return reply_data;
|
||||
}
|
||||
|
||||
template <typename Values>
|
||||
bool
|
||||
matchValues(const Values &values) const
|
||||
{
|
||||
for (const SerializableAssetSource<UserSerializableReplyAttr> &source : sources) {
|
||||
if (source.template matchValues<Values>(values)) return true;
|
||||
}
|
||||
return false;
|
||||
}
|
||||
|
||||
private:
|
||||
uint asset_schema_version = 0;
|
||||
std::string asset_type = "";
|
||||
uint asset_type_schema_version = 0;
|
||||
std::string asset_permission_group_id = "";
|
||||
std::string asset_name = "";
|
||||
std::string asset_id = "";
|
||||
std::string asset_class = "";
|
||||
std::string asset_category = "";
|
||||
std::string asset_family = "";
|
||||
std::string asset_group = "";
|
||||
std::string asset_order = "";
|
||||
std::string asset_kind = "";
|
||||
|
||||
std::map<std::string, std::vector<std::string>> main_attributes;
|
||||
std::vector<SerializableAssetSource<UserSerializableReplyAttr>> sources;
|
||||
};
|
||||
|
||||
template <typename UserSerializableReplyAttr>
|
||||
class IntelligenceQueryResponse
|
||||
{
|
||||
public:
|
||||
IntelligenceQueryResponse() {}
|
||||
|
||||
void loadFromJson(cereal::JSONInputArchive &ar);
|
||||
|
||||
Intelligence_IS_V2::ResponseStatus getResponseStatus() const;
|
||||
uint getAmountOfAssets() const;
|
||||
const std::string & getCursor() const;
|
||||
int getAssetCollectionsSize() const;
|
||||
const std::vector<AssetReply<UserSerializableReplyAttr>> & getData() const;
|
||||
|
||||
private:
|
||||
Intelligence_IS_V2::ResponseStatus status = Intelligence_IS_V2::ResponseStatus::IN_PROGRESS;
|
||||
uint total_num_assets = 0;
|
||||
std::string cursor = "";
|
||||
std::vector<AssetReply<UserSerializableReplyAttr>> asset_collections;
|
||||
};
|
||||
|
||||
#include "query_response_v2_impl.h"
|
||||
|
||||
#endif // __QUERY_RESPONSE_V2_H__
|
138
core/include/services_sdk/interfaces/intelligence_is_v2/query_response_v2_impl.h
Executable file
138
core/include/services_sdk/interfaces/intelligence_is_v2/query_response_v2_impl.h
Executable file
@@ -0,0 +1,138 @@
|
||||
// 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 __QUERY_RESPONSE_V2_IMPL_H_
|
||||
#define __QUERY_RESPONSE_V2_IMPL_H_
|
||||
|
||||
#ifndef __QUERY_RESPONSE_V2_H__
|
||||
#error intelligence_query_response_v2_impl.h should not be included directly!
|
||||
#endif // __QUERY_RESPONSE_V2_H__
|
||||
|
||||
#include "debug.h"
|
||||
#include "intelligence_types_v2.h"
|
||||
|
||||
USE_DEBUG_FLAG(D_INTELLIGENCE);
|
||||
|
||||
template <typename UserSerializableReplyAttr>
|
||||
void
|
||||
AssetReply<UserSerializableReplyAttr>::load(cereal::JSONInputArchive &ar)
|
||||
{
|
||||
SerializableMultiMap<std::string, std::vector<std::string>> tmp_multimap;
|
||||
ar(
|
||||
cereal::make_nvp("schemaVersion", asset_schema_version),
|
||||
cereal::make_nvp("assetTypeSchemaVersion", asset_type_schema_version),
|
||||
cereal::make_nvp("class", asset_class),
|
||||
cereal::make_nvp("category", asset_category),
|
||||
cereal::make_nvp("family", asset_family),
|
||||
cereal::make_nvp("mainAttributes", tmp_multimap)
|
||||
);
|
||||
|
||||
for (auto const &attr : tmp_multimap.getMap<std::string>()) {
|
||||
std::vector<std::string> attr_vec = { attr.second };
|
||||
main_attributes[attr.first] = attr_vec;
|
||||
}
|
||||
|
||||
for (auto const &attr : tmp_multimap.getMap<std::vector<std::string>>()) {
|
||||
main_attributes[attr.first] = attr.second;
|
||||
}
|
||||
|
||||
try {
|
||||
ar(cereal::make_nvp("permissionGroupId", asset_permission_group_id));
|
||||
} catch(...) {}
|
||||
|
||||
try {
|
||||
ar(cereal::make_nvp("name", asset_name));
|
||||
} catch(...) {}
|
||||
|
||||
try {
|
||||
ar(cereal::make_nvp("group", asset_group));
|
||||
} catch(...) {}
|
||||
|
||||
try {
|
||||
ar(cereal::make_nvp("order", asset_order));
|
||||
} catch(...) {}
|
||||
|
||||
try {
|
||||
ar(cereal::make_nvp("kind", asset_kind));
|
||||
} catch(...) {}
|
||||
|
||||
ar(cereal::make_nvp("sources", sources));
|
||||
ar(cereal::make_nvp("assetType", asset_type));
|
||||
}
|
||||
|
||||
template <typename UserSerializableReplyAttr>
|
||||
std::vector<UserSerializableReplyAttr>
|
||||
AssetReply<UserSerializableReplyAttr>::getData() const
|
||||
{
|
||||
std::vector<UserSerializableReplyAttr> all_attributes;
|
||||
for (SerializableAssetSource<UserSerializableReplyAttr> const &asset_source : sources) {
|
||||
for (UserSerializableReplyAttr const &attribute : asset_source.getAttributes()) {
|
||||
all_attributes.push_back(attribute);
|
||||
}
|
||||
}
|
||||
return all_attributes;
|
||||
}
|
||||
|
||||
template <typename UserSerializableReplyAttr>
|
||||
void
|
||||
IntelligenceQueryResponse<UserSerializableReplyAttr>::loadFromJson(cereal::JSONInputArchive &ar)
|
||||
{
|
||||
std::string raw_data;
|
||||
ar(
|
||||
cereal::make_nvp("status", raw_data),
|
||||
cereal::make_nvp("totalNumAssets", total_num_assets),
|
||||
cereal::make_nvp("assetCollections", asset_collections)
|
||||
);
|
||||
status = Intelligence_IS_V2::convertStringToResponseStatus(raw_data);
|
||||
|
||||
try {
|
||||
ar(cereal::make_nvp("cursor", cursor));
|
||||
} catch(...) {}
|
||||
}
|
||||
|
||||
template <typename UserSerializableReplyAttr>
|
||||
Intelligence_IS_V2::ResponseStatus
|
||||
IntelligenceQueryResponse<UserSerializableReplyAttr>::getResponseStatus() const
|
||||
{
|
||||
return status;
|
||||
}
|
||||
|
||||
template <typename UserSerializableReplyAttr>
|
||||
uint
|
||||
IntelligenceQueryResponse<UserSerializableReplyAttr>::getAmountOfAssets() const
|
||||
{
|
||||
return total_num_assets;
|
||||
}
|
||||
|
||||
template <typename UserSerializableReplyAttr>
|
||||
const std::string &
|
||||
IntelligenceQueryResponse<UserSerializableReplyAttr>::getCursor() const
|
||||
{
|
||||
return cursor;
|
||||
}
|
||||
|
||||
template <typename UserSerializableReplyAttr>
|
||||
int
|
||||
IntelligenceQueryResponse<UserSerializableReplyAttr>::getAssetCollectionsSize() const
|
||||
{
|
||||
return asset_collections.size();
|
||||
}
|
||||
|
||||
template <typename UserSerializableReplyAttr>
|
||||
const std::vector<AssetReply<UserSerializableReplyAttr>> &
|
||||
IntelligenceQueryResponse<UserSerializableReplyAttr>::getData() const
|
||||
{
|
||||
return asset_collections;
|
||||
}
|
||||
|
||||
#endif // __QUERY_RESPONSE_V2_IMPL_H_
|
@@ -0,0 +1,53 @@
|
||||
// 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 __QUERY_TYPES_V2_H__
|
||||
#define __QUERY_TYPES_V2_H__
|
||||
|
||||
#include "cereal/archives/json.hpp"
|
||||
#include "cereal/types/string.hpp"
|
||||
#include "cereal/types/tuple.hpp"
|
||||
#include "cereal/types/vector.hpp"
|
||||
#include "intelligence_types_v2.h"
|
||||
|
||||
#include <vector>
|
||||
#include <unordered_map>
|
||||
|
||||
class serializableTenantList
|
||||
{
|
||||
public:
|
||||
serializableTenantList(const std::vector<std::string> &_tenants)
|
||||
:
|
||||
tenants(_tenants)
|
||||
{}
|
||||
|
||||
void serialize(cereal::JSONOutputArchive &ar) const;
|
||||
|
||||
private:
|
||||
std::vector<std::string> tenants;
|
||||
};
|
||||
|
||||
class SerializableQueryTypes
|
||||
{
|
||||
public:
|
||||
SerializableQueryTypes() {};
|
||||
|
||||
void save(cereal::JSONOutputArchive &ar) const;
|
||||
void setSerializableTenantList(const std::vector<std::string> tenants);
|
||||
|
||||
private:
|
||||
std::vector<std::string> tenants;
|
||||
bool is_nsaas = false;
|
||||
};
|
||||
|
||||
#endif // __QUERY_TYPES_V2_H__
|
@@ -0,0 +1,60 @@
|
||||
// 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 __REQUESTED_ATTRIBUTES_V2_H__
|
||||
#define __REQUESTED_ATTRIBUTES_V2_H__
|
||||
|
||||
#include "cereal/archives/json.hpp"
|
||||
#include "cereal/types/string.hpp"
|
||||
#include "cereal/types/tuple.hpp"
|
||||
#include "cereal/types/vector.hpp"
|
||||
#include "intelligence_types_v2.h"
|
||||
|
||||
#include <vector>
|
||||
#include <unordered_map>
|
||||
|
||||
class serializableAttribute
|
||||
{
|
||||
public:
|
||||
serializableAttribute(std::string _key, uint _min_confidence)
|
||||
:
|
||||
key(_key),
|
||||
min_confidence(_min_confidence)
|
||||
{}
|
||||
|
||||
void serialize(cereal::JSONOutputArchive &ar) const;
|
||||
|
||||
private:
|
||||
std::string key;
|
||||
uint min_confidence;
|
||||
};
|
||||
|
||||
class SerializableAttributesMap
|
||||
{
|
||||
public:
|
||||
SerializableAttributesMap() {};
|
||||
|
||||
void save(cereal::JSONOutputArchive &ar) const;
|
||||
|
||||
void setSerializableAttribute(const std::string &attribute, uint confidence = 500);
|
||||
uint getAttributeByKey(const std::string &key) const;
|
||||
uint getSize() const { return requested_attributes.size(); }
|
||||
bool isRequestedAttributesMapEmpty() const { return requested_attributes.empty(); }
|
||||
|
||||
bool checkMinConfidence(uint upper_confidence_limit);
|
||||
|
||||
private:
|
||||
std::unordered_map<std::string, uint> requested_attributes;
|
||||
};
|
||||
|
||||
#endif // __REQUESTED_ATTRIBUTES_V2_H__
|
103
core/include/services_sdk/interfaces/messaging/http_core.h
Normal file
103
core/include/services_sdk/interfaces/messaging/http_core.h
Normal file
@@ -0,0 +1,103 @@
|
||||
// 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_CORE_H__
|
||||
#define __HTTP_CORE_H__
|
||||
|
||||
#include <string>
|
||||
#include <unordered_map>
|
||||
|
||||
#include "maybe_res.h"
|
||||
#include "cereal/archives/json.hpp"
|
||||
#include "cereal/types/string.hpp"
|
||||
|
||||
enum class HTTPStatusCode
|
||||
{
|
||||
// 10X - Information responses. Not supported yet.
|
||||
// 20x - Successful responses.
|
||||
HTTP_OK = 200,
|
||||
HTTP_NO_CONTENT = 204,
|
||||
HTTP_MULTI_STATUS = 207,
|
||||
// 30x - Redirection messages. Not supported yet.
|
||||
// 4xx - Client error responses.
|
||||
HTTP_BAD_REQUEST = 400,
|
||||
HTTP_UNAUTHORIZED = 401,
|
||||
HTTP_FORBIDDEN = 403,
|
||||
HTTP_NOT_FOUND = 404,
|
||||
HTTP_METHOD_NOT_ALLOWED = 405,
|
||||
HTTP_PROXY_AUTHENTICATION_REQUIRED = 407,
|
||||
HTTP_REQUEST_TIME_OUT = 408,
|
||||
HTTP_PAYLOAD_TOO_LARGE = 413,
|
||||
// 5xx - Server error responses.
|
||||
HTTP_INTERNAL_SERVER_ERROR = 500,
|
||||
HTTP_NOT_IMPLEMENTED = 501,
|
||||
HTTP_BAD_GATEWAY = 502,
|
||||
HTTP_SERVICE_UNABAILABLE = 503,
|
||||
HTTP_GATEWAY_TIMEOUT = 504,
|
||||
HTTP_VERSION_NOT_SUPPORTED = 505,
|
||||
HTTP_VARIANT_ALSO_NEGOTIATES = 506,
|
||||
HTTP_INSUFFICIENT_STORAGE = 507,
|
||||
HTTP_LOOP_DETECTED = 508,
|
||||
HTTP_NOT_EXTENDED = 510,
|
||||
HTTP_NETWORK_AUTHENTICATION_REQUIRED = 511,
|
||||
// Not supported status code.
|
||||
HTTP_UNKNOWN
|
||||
};
|
||||
|
||||
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__
|
42
core/include/services_sdk/interfaces/mock/mock_agent_details.h
Executable file
42
core/include/services_sdk/interfaces/mock/mock_agent_details.h
Executable file
@@ -0,0 +1,42 @@
|
||||
#ifndef __MOCK_AGENT_DTEAILS_H__
|
||||
#define __MOCK_AGENT_DTEAILS_H__
|
||||
|
||||
#include "i_agent_details.h"
|
||||
#include "cptest.h"
|
||||
|
||||
class MockAgentDetails : public Singleton::Provide<I_AgentDetails>::From<MockProvider<I_AgentDetails>>
|
||||
{
|
||||
public:
|
||||
MOCK_METHOD1(setFogPort, void(const uint16_t));
|
||||
MOCK_METHOD1(setSSLFlag, void(const bool));
|
||||
MOCK_METHOD1(setOrchestrationMode, void(const OrchestrationMode));
|
||||
MOCK_METHOD1(setFogDomain, void(const std::string&));
|
||||
MOCK_METHOD1(setProfileId, void(const std::string&));
|
||||
MOCK_METHOD1(setTenantId, void(const std::string&));
|
||||
|
||||
MOCK_CONST_METHOD0(getFogPort, Maybe<uint16_t>());
|
||||
MOCK_CONST_METHOD0(getSSLFlag, bool());
|
||||
MOCK_CONST_METHOD0(getOrchestrationMode, OrchestrationMode());
|
||||
MOCK_CONST_METHOD0(getFogDomain, Maybe<std::string>());
|
||||
MOCK_CONST_METHOD0(getTenantId, std::string());
|
||||
MOCK_CONST_METHOD0(getProfileId, std::string());
|
||||
|
||||
// Agent Details
|
||||
MOCK_CONST_METHOD0(getProxy, Maybe<std::string>());
|
||||
MOCK_METHOD1(setProxy, void(const std::string&));
|
||||
MOCK_METHOD1(setAgentId, void(const std::string&));
|
||||
MOCK_CONST_METHOD0(getAgentId, std::string());
|
||||
|
||||
// OpenSSL
|
||||
MOCK_METHOD1(setOpenSSLDir, void(const std::string&));
|
||||
MOCK_CONST_METHOD0(getOpenSSLDir, Maybe<std::string>());
|
||||
|
||||
// Serialization
|
||||
MOCK_METHOD0(readAgentDetails, bool());
|
||||
MOCK_METHOD0(writeAgentDetails, bool());
|
||||
|
||||
// Environment
|
||||
MOCK_METHOD1(setClusterId, void(const std::string&));
|
||||
};
|
||||
|
||||
#endif
|
@@ -0,0 +1,32 @@
|
||||
#ifndef __MOCK_AGENT_DETAILS_REPORTER_H__
|
||||
#define __MOCK_AGENT_DETAILS_REPORTER_H__
|
||||
|
||||
#include <string>
|
||||
|
||||
#include "i_agent_details_reporter.h"
|
||||
#include "cptest.h"
|
||||
|
||||
|
||||
class MockAgenetDetailsReporter
|
||||
:
|
||||
public Singleton::Provide<I_AgentDetailsReporter>::From<MockProvider<I_AgentDetailsReporter>>
|
||||
{
|
||||
public:
|
||||
MOCK_METHOD5(
|
||||
sendReport,
|
||||
void(
|
||||
const metaDataReport &,
|
||||
const Maybe<std::string> &,
|
||||
const Maybe<std::string> &,
|
||||
const Maybe<std::string> &,
|
||||
const Maybe<std::string> &
|
||||
)
|
||||
);
|
||||
|
||||
MOCK_METHOD3(addAttr, bool(const std::string &key, const std::string &val, bool allow_override));
|
||||
MOCK_METHOD2(addAttr, bool(const std::map<std::string, std::string> &attr, bool allow_override));
|
||||
MOCK_METHOD1(deleteAttr, void(const std::string &key));
|
||||
MOCK_METHOD0(sendAttributes, bool());
|
||||
};
|
||||
|
||||
#endif // __MOCK_AGENT_DETAILS_REPORTER_H__
|
15
core/include/services_sdk/interfaces/mock/mock_cpu.h
Executable file
15
core/include/services_sdk/interfaces/mock/mock_cpu.h
Executable file
@@ -0,0 +1,15 @@
|
||||
#ifndef __MOCK_CPU_H__
|
||||
#define __MOCK_CPU_H__
|
||||
|
||||
#include "i_cpu.h"
|
||||
#include "singleton.h"
|
||||
#include "cptest.h"
|
||||
|
||||
class MockCPU : public Singleton::Provide<I_CPU>::From<MockProvider<I_CPU>>
|
||||
{
|
||||
public:
|
||||
MOCK_METHOD0(getCurrentProcessCPUUsage, double());
|
||||
MOCK_METHOD0(getCurrentGeneralCPUUsage, Maybe<double>());
|
||||
};
|
||||
|
||||
#endif // __MOCK_CPU_H__
|
26
core/include/services_sdk/interfaces/mock/mock_encryptor.h
Normal file
26
core/include/services_sdk/interfaces/mock/mock_encryptor.h
Normal file
@@ -0,0 +1,26 @@
|
||||
#ifndef __MOCK_ENCRYPTOR_H__
|
||||
#define __MOCK_ENCRYPTOR_H__
|
||||
|
||||
#include "i_encryptor.h"
|
||||
#include "cptest.h"
|
||||
|
||||
class MockEncryptor : public Singleton::Provide<I_Encryptor>::From<MockProvider<I_Encryptor>>
|
||||
{
|
||||
public:
|
||||
// Base64
|
||||
MOCK_METHOD1(base64Encode, std::string(const std::string &));
|
||||
MOCK_METHOD1(base64Decode, std::string(const std::string &));
|
||||
|
||||
// Obfuscating
|
||||
MOCK_METHOD1(obfuscateXor, std::string(const std::string &));
|
||||
MOCK_METHOD1(obfuscateXorBase64, std::string(const std::string &));
|
||||
|
||||
// AES256
|
||||
MOCK_METHOD1(decryptAES256obfuscateXorBase64, Maybe<std::string>(const std::string &));
|
||||
MOCK_METHOD1(encryptAES256obfuscateXorBase64, std::string(const std::string &));
|
||||
MOCK_METHOD1(aes256EncryptWithSizePad, std::string(const std::string &));
|
||||
MOCK_METHOD1(aes256DecryptWithSizePad, Maybe<std::string>(const std::string &));
|
||||
|
||||
};
|
||||
|
||||
#endif //__MOCK_ENCRYPTOR_H__
|
49
core/include/services_sdk/interfaces/mock/mock_environment.h
Normal file
49
core/include/services_sdk/interfaces/mock/mock_environment.h
Normal file
@@ -0,0 +1,49 @@
|
||||
#ifndef __MOCK_ENVIRONMENT_H__
|
||||
#define __MOCK_ENVIRONMENT_H__
|
||||
|
||||
#include "i_environment.h"
|
||||
#include "singleton.h"
|
||||
#include "cptest.h"
|
||||
|
||||
std::ostream &
|
||||
operator<<(std::ostream &os, const Maybe<std::string, Context::Error> &)
|
||||
{
|
||||
return os;
|
||||
}
|
||||
|
||||
class MockEnvironment : public Singleton::Provide<I_Environment>::From<MockProvider<I_Environment>>
|
||||
{
|
||||
public:
|
||||
MOCK_METHOD0 (getConfigurationContext, Context &());
|
||||
MOCK_CONST_METHOD0(getActiveContexts, const ActiveContexts &());
|
||||
|
||||
MOCK_METHOD1 (setActiveTenant, void(const std::string &));
|
||||
MOCK_METHOD0 (unsetActiveTenant, void());
|
||||
|
||||
MOCK_METHOD1 (registerContext, void(Context *));
|
||||
MOCK_METHOD1 (unregisterContext, void(Context *));
|
||||
|
||||
MOCK_METHOD0 (createEnvironment, ActiveContexts());
|
||||
MOCK_METHOD0 (saveEnvironment, ActiveContexts());
|
||||
|
||||
MOCK_CONST_METHOD0(getCurrentTrace, std::string());
|
||||
MOCK_CONST_METHOD0(getCurrentSpan, std::string());
|
||||
MOCK_METHOD0(getCurrentHeaders, std::string());
|
||||
MOCK_METHOD2(startNewTrace, void(bool, const std::string &));
|
||||
MOCK_METHOD3(startNewSpan, void(Span::ContextType, const std::string &, const std::string &));
|
||||
|
||||
using on_exit = std::scope_exit<std::function<void(void)>>;
|
||||
MOCK_METHOD3(startNewSpanScope, on_exit(Span::ContextType, const std::string &, const std::string &));
|
||||
MOCK_METHOD1(finishTrace, void(const std::string &));
|
||||
MOCK_METHOD1(finishSpan, void(const std::string &));
|
||||
|
||||
// You can't mock a function with an R-value reference. So mock a slightly different one
|
||||
void loadEnvironment(ActiveContexts &&env) { mockLoadEnvironment(env); }
|
||||
MOCK_METHOD1 (mockLoadEnvironment, void(const ActiveContexts &));
|
||||
|
||||
MOCK_CONST_METHOD1(getAllStrings, std::map<std::string, std::string>(const EnvKeyAttr::ParamAttr &));
|
||||
MOCK_CONST_METHOD1(getAllUints, std::map<std::string, uint64_t>(const EnvKeyAttr::ParamAttr &));
|
||||
MOCK_CONST_METHOD1(getAllBools, std::map<std::string, bool>(const EnvKeyAttr::ParamAttr &));
|
||||
};
|
||||
|
||||
#endif // __MOCK_ENVIRONMENT_H__
|
@@ -0,0 +1,20 @@
|
||||
#ifndef __MOCK_INSTACE_AWARENESS__
|
||||
#define __MOCK_INSTACE_AWARENESS__
|
||||
|
||||
#include "cptest.h"
|
||||
#include "i_instance_awareness.h"
|
||||
#include "singleton.h"
|
||||
|
||||
class MockInstanceAwareness : public Singleton::Provide<I_InstanceAwareness>::From<MockProvider<I_InstanceAwareness>>
|
||||
{
|
||||
public:
|
||||
MOCK_METHOD0(getUniqueID, Maybe<std::string>());
|
||||
MOCK_METHOD0(getFamilyID, Maybe<std::string>());
|
||||
MOCK_METHOD0(getInstanceID, Maybe<std::string>());
|
||||
|
||||
MOCK_METHOD1(getUniqueID, std::string(const std::string &));
|
||||
MOCK_METHOD1(getFamilyID, std::string(const std::string &));
|
||||
MOCK_METHOD1(getInstanceID, std::string(const std::string &));
|
||||
};
|
||||
|
||||
#endif // __MOCK_INSTACE_AWARENESS__
|
19
core/include/services_sdk/interfaces/mock/mock_logging.h
Executable file
19
core/include/services_sdk/interfaces/mock/mock_logging.h
Executable file
@@ -0,0 +1,19 @@
|
||||
#ifndef __MOCK_LOGGING_H__
|
||||
#define __MOCK_LOGGING_H__
|
||||
|
||||
#include "i_logging.h"
|
||||
#include "cptest.h"
|
||||
#include "common.h"
|
||||
|
||||
class MockLogging : public Singleton::Provide<I_Logging>::From<MockProvider<I_Logging>>
|
||||
{
|
||||
public:
|
||||
MOCK_METHOD1(sendLog, void (const Report &));
|
||||
MOCK_METHOD1(addStream, bool (ReportIS::StreamType));
|
||||
MOCK_METHOD2(addStream, bool (ReportIS::StreamType, const std::string &));
|
||||
MOCK_METHOD1(delStream, bool (ReportIS::StreamType));
|
||||
MOCK_METHOD0(getCurrentLogId, uint64_t ());
|
||||
MOCK_METHOD1(addGeneralModifier, void (const GeneralModifier &));
|
||||
};
|
||||
|
||||
#endif // __MOCK_LOGGING_H__
|
41
core/include/services_sdk/interfaces/mock/mock_mainloop.h
Normal file
41
core/include/services_sdk/interfaces/mock/mock_mainloop.h
Normal file
@@ -0,0 +1,41 @@
|
||||
#ifndef __MOCK_MAINLOOP_H__
|
||||
#define __MOCK_MAINLOOP_H__
|
||||
|
||||
#include "i_mainloop.h"
|
||||
#include "singleton.h"
|
||||
#include "cptest.h"
|
||||
|
||||
class MockMainLoop : public Singleton::Provide<I_MainLoop>::From<MockProvider<I_MainLoop>>
|
||||
{
|
||||
public:
|
||||
MOCK_METHOD4(addOneTimeRoutine, uint (RoutineType, Routine, const std::string &, bool));
|
||||
|
||||
MOCK_METHOD5(
|
||||
addRecurringRoutine,
|
||||
uint (RoutineType, std::chrono::microseconds, Routine, const std::string &, bool)
|
||||
);
|
||||
|
||||
MOCK_METHOD5(
|
||||
addFileRoutine,
|
||||
uint (RoutineType, int, Routine, const std::string &, bool)
|
||||
);
|
||||
|
||||
MOCK_METHOD0(run, void ());
|
||||
|
||||
MOCK_METHOD1(doesRoutineExist, bool (RoutineID id));
|
||||
|
||||
MOCK_CONST_METHOD0(getCurrentRoutineId, Maybe<I_MainLoop::RoutineID> ());
|
||||
|
||||
MOCK_METHOD1(yield, void (bool));
|
||||
MOCK_METHOD1(yield, void (std::chrono::microseconds));
|
||||
|
||||
MOCK_METHOD0(stopAll, void ());
|
||||
MOCK_METHOD0(stop, void ());
|
||||
MOCK_METHOD1(stop, void (uint));
|
||||
MOCK_METHOD0(halt, void ());
|
||||
MOCK_METHOD1(halt, void (uint));
|
||||
|
||||
MOCK_METHOD1(resume, void (uint));
|
||||
};
|
||||
|
||||
#endif // __MOCK_MAINLOOP_H__
|
76
core/include/services_sdk/interfaces/mock/mock_messaging.h
Executable file
76
core/include/services_sdk/interfaces/mock/mock_messaging.h
Executable file
@@ -0,0 +1,76 @@
|
||||
#ifndef __MOCK_MESSAGING_H__
|
||||
#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> &,
|
||||
const string &,
|
||||
const string &,
|
||||
I_Messaging::ErrorCB,
|
||||
MessageTypeTag
|
||||
)
|
||||
);
|
||||
|
||||
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,
|
||||
const string &,
|
||||
const string &,
|
||||
I_Messaging::ErrorCB,
|
||||
bool,
|
||||
MessageTypeTag
|
||||
)
|
||||
);
|
||||
|
||||
MOCK_METHOD0(loadAccessToken, void());
|
||||
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_METHOD0(getAccessToken, string());
|
||||
|
||||
MOCK_CONST_METHOD1(getProxyDomain, Maybe<std::string>(ProxyProtocol protocol));
|
||||
MOCK_CONST_METHOD1(getProxyCredentials, Maybe<std::string>(ProxyProtocol protocol));
|
||||
MOCK_CONST_METHOD1(getProxyPort, Maybe<uint16_t>(ProxyProtocol protocol));
|
||||
MOCK_CONST_METHOD1(getProxyExists, bool(ProxyProtocol protocol));
|
||||
MOCK_CONST_METHOD1(getProxyAddress, Maybe<std::string>(ProxyProtocol protocol));
|
||||
MOCK_METHOD0(loadProxy, Maybe<void>());
|
||||
};
|
||||
|
||||
#endif // __MOCK_MESSAGING_H__
|
22
core/include/services_sdk/interfaces/mock/mock_rest_api.h
Normal file
22
core/include/services_sdk/interfaces/mock/mock_rest_api.h
Normal file
@@ -0,0 +1,22 @@
|
||||
#ifndef __MOCK_REST_API_H__
|
||||
#define __MOCK_REST_API_H__
|
||||
|
||||
#include "i_rest_api.h"
|
||||
#include "cptest.h"
|
||||
#include "singleton.h"
|
||||
|
||||
class MockRestApi : public Singleton::Provide<I_RestApi>::From<MockProvider<I_RestApi>>
|
||||
{
|
||||
public:
|
||||
// You can't mock a function with an R-value reference. So mock a slightly different one
|
||||
MOCK_METHOD3(mockRestCall, bool(RestAction, const std::string &, const std::unique_ptr<RestInit> &));
|
||||
|
||||
bool
|
||||
addRestCall(RestAction oper, const std::string &uri, std::unique_ptr<RestInit> &&init)
|
||||
{
|
||||
return mockRestCall(oper, uri, init);
|
||||
}
|
||||
};
|
||||
|
||||
|
||||
#endif // __MOCK_REST_API_H__
|
24
core/include/services_sdk/interfaces/mock/mock_shell_cmd.h
Executable file
24
core/include/services_sdk/interfaces/mock/mock_shell_cmd.h
Executable file
@@ -0,0 +1,24 @@
|
||||
#ifndef __MOCK_SHELL_CMD_H__
|
||||
#define __MOCK_SHELL_CMD_H__
|
||||
|
||||
#include <gmock/gmock.h>
|
||||
|
||||
#include "i_shell_cmd.h"
|
||||
#include "singleton.h"
|
||||
#include "cptest.h"
|
||||
|
||||
class MockShellCmd : public Singleton::Provide<I_ShellCmd>::From<MockProvider<I_ShellCmd>>
|
||||
{
|
||||
public:
|
||||
MOCK_METHOD3(getExecOutput, Maybe<std::string>(const std::string &cmd, uint tmout, bool do_yield));
|
||||
MOCK_METHOD3(getExecReturnCode, Maybe<int>(const std::string &cmd, uint tmout, bool do_yield));
|
||||
MOCK_METHOD3(getExecOutputAndCode, Maybe<std::pair<std::string, int>>(const std::string &, uint, bool));
|
||||
};
|
||||
|
||||
static std::ostream &
|
||||
operator<<(std::ostream &os, const std::pair<std::string, int> &val)
|
||||
{
|
||||
return os << "<" << val.first << ", " << val.second << ">";
|
||||
}
|
||||
|
||||
#endif // __MOCK_SHELL_CMD_H__
|
19
core/include/services_sdk/interfaces/mock/mock_socket_is.h
Executable file
19
core/include/services_sdk/interfaces/mock/mock_socket_is.h
Executable file
@@ -0,0 +1,19 @@
|
||||
#ifndef __MOCK_SOCKET_IS_H__
|
||||
#define __MOCK_SOCKET_IS_H__
|
||||
|
||||
#include "i_socket_is.h"
|
||||
#include "cptest.h"
|
||||
#include "common.h"
|
||||
|
||||
class MockSocketIS : public Singleton::Provide<I_Socket>::From<MockProvider<I_Socket>>
|
||||
{
|
||||
public:
|
||||
MOCK_METHOD4(genSocket, Maybe<socketFd> (SocketType, bool, bool, const std::string &));
|
||||
MOCK_METHOD3(acceptSocket, Maybe<socketFd> (socketFd, bool, const std::string &authorized_ip));
|
||||
MOCK_METHOD1(closeSocket, void (socketFd &));
|
||||
MOCK_METHOD1(isDataAvailable, bool (socketFd));
|
||||
MOCK_METHOD2(writeData, bool (socketFd, const std::vector<char> &));
|
||||
MOCK_METHOD3(receiveData, Maybe<std::vector<char>> (socketFd, uint, bool is_blocking));
|
||||
};
|
||||
|
||||
#endif // __MOCK_SOCKET_IS_H__
|
31
core/include/services_sdk/interfaces/mock/mock_table.h
Executable file
31
core/include/services_sdk/interfaces/mock/mock_table.h
Executable file
@@ -0,0 +1,31 @@
|
||||
#ifndef __MOCK_TABLE_H__
|
||||
#define __MOCK_TABLE_H__
|
||||
|
||||
#include <gmock/gmock.h>
|
||||
|
||||
#include "i_table.h"
|
||||
#include "singleton.h"
|
||||
#include "cptest.h"
|
||||
|
||||
class MockTable : public Singleton::Provide<I_Table>::From<MockProvider<I_Table>>
|
||||
{
|
||||
public:
|
||||
MOCK_METHOD1(setExpiration, void(std::chrono::milliseconds expire));
|
||||
MOCK_CONST_METHOD0(doesKeyExists, bool());
|
||||
MOCK_CONST_METHOD0(keyToString, std::string());
|
||||
MOCK_CONST_METHOD0(begin, TableIter());
|
||||
MOCK_CONST_METHOD0(end, TableIter());
|
||||
|
||||
bool
|
||||
createState(const std::type_index &index, std::unique_ptr<TableOpaqueBase> &&ptr)
|
||||
{
|
||||
return createStateRValueRemoved(index, ptr);
|
||||
}
|
||||
|
||||
MOCK_CONST_METHOD1(hasState, bool(const std::type_index &index));
|
||||
MOCK_METHOD2(createStateRValueRemoved, bool(const std::type_index &index, std::unique_ptr<TableOpaqueBase> &ptr));
|
||||
MOCK_METHOD1(deleteState, bool(const std::type_index &index));
|
||||
MOCK_METHOD1(getState, TableOpaqueBase *(const std::type_index &index));
|
||||
};
|
||||
|
||||
#endif // __MOCK_TABLE_H__
|
@@ -0,0 +1,34 @@
|
||||
#ifndef __MOCK_TENANT_MANAGER_H__
|
||||
#define __MOCK_TENANT_MANAGER_H__
|
||||
|
||||
#include "i_tenant_manager.h"
|
||||
|
||||
#include <string>
|
||||
#include <vector>
|
||||
#include <chrono>
|
||||
|
||||
#include "singleton.h"
|
||||
#include "cptest.h"
|
||||
|
||||
class MockTenantManager : public Singleton::Provide<I_TenantManager>::From<MockProvider<I_TenantManager>>
|
||||
{
|
||||
public:
|
||||
MOCK_METHOD1(uponNewTenants, void(const I_TenantManager::newTenantCB &cb));
|
||||
MOCK_CONST_METHOD1(isTenantActive, bool(const std::string &));
|
||||
|
||||
MOCK_CONST_METHOD0(fetchActiveTenants, std::vector<std::string>());
|
||||
MOCK_CONST_METHOD1(getInstances, std::vector<std::string>(const std::string &));
|
||||
|
||||
MOCK_METHOD1(addActiveTenant, void(const std::string &));
|
||||
MOCK_METHOD1(addActiveTenants, void(const std::vector<std::string> &));
|
||||
|
||||
MOCK_METHOD1(deactivateTenant, void(const std::string &));
|
||||
MOCK_METHOD1(deactivateTenants, void(const std::vector<std::string> &));
|
||||
|
||||
MOCK_CONST_METHOD0(getTimeoutVal, std::chrono::microseconds());
|
||||
|
||||
private:
|
||||
MOCK_METHOD2(addInstance, void(const std::string &, const std::string &));
|
||||
};
|
||||
|
||||
#endif // __MOCK_TENANT_MANAGER_H__
|
14
core/include/services_sdk/interfaces/mock/mock_time_get.h
Executable file
14
core/include/services_sdk/interfaces/mock/mock_time_get.h
Executable file
@@ -0,0 +1,14 @@
|
||||
#include <gmock/gmock.h>
|
||||
#include "i_time_get.h"
|
||||
#include "singleton.h"
|
||||
#include "cptest.h"
|
||||
|
||||
class MockTimeGet : public Singleton::Provide<I_TimeGet>::From<MockProvider<I_TimeGet>>
|
||||
{
|
||||
public:
|
||||
MOCK_METHOD0(getMonotonicTime, std::chrono::microseconds());
|
||||
MOCK_METHOD0(getWalltime, std::chrono::microseconds());
|
||||
MOCK_METHOD0(getWalltimeStr, std::string());
|
||||
MOCK_METHOD0(getLocalTimeStr, std::string());
|
||||
MOCK_METHOD1(getWalltimeStr, std::string(const std::chrono::microseconds &));
|
||||
};
|
89
core/include/services_sdk/resources/agent_details.h
Executable file
89
core/include/services_sdk/resources/agent_details.h
Executable file
@@ -0,0 +1,89 @@
|
||||
// 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 __AGENT_DETAILS_H__
|
||||
#define __AGENT_DETAILS_H__
|
||||
|
||||
#include <cereal/archives/json.hpp>
|
||||
|
||||
#include "i_agent_details.h"
|
||||
#include "i_encryptor.h"
|
||||
#include "i_shell_cmd.h"
|
||||
#include "i_environment.h"
|
||||
#include "singleton.h"
|
||||
#include "component.h"
|
||||
#include "enum_array.h"
|
||||
|
||||
class AgentDetails
|
||||
:
|
||||
public Component,
|
||||
Singleton::Provide<I_AgentDetails>::SelfInterface,
|
||||
Singleton::Consume<I_Encryptor>,
|
||||
Singleton::Consume<I_ShellCmd>,
|
||||
Singleton::Consume<I_Environment>
|
||||
{
|
||||
public:
|
||||
AgentDetails() : Component("AgentDetails") {}
|
||||
|
||||
void preload();
|
||||
|
||||
void init();
|
||||
|
||||
Maybe<std::string> getProxy() const;
|
||||
Maybe<std::string> getFogDomain() const;
|
||||
Maybe<uint16_t> getFogPort() const;
|
||||
std::string getAgentId() const;
|
||||
std::string getTenantId() const;
|
||||
std::string getProfileId() const;
|
||||
Maybe<std::string> getOpenSSLDir() const;
|
||||
std::string getClusterId() const;
|
||||
OrchestrationMode getOrchestrationMode() const;
|
||||
|
||||
void setFogDomain(const std::string &_fog_domain) { fog_domain = _fog_domain; }
|
||||
void setFogPort(const uint16_t _fog_port) { fog_port = _fog_port; }
|
||||
void setProxy(const std::string &_proxy) { proxy = _proxy; }
|
||||
void setAgentId(const std::string &_agent_id) { agent_id = _agent_id; }
|
||||
void setProfileId(const std::string &_profile_id) { profile_id = _profile_id; }
|
||||
void setTenantId(const std::string &_tenant_id) { tenant_id = _tenant_id; }
|
||||
void setOpenSSLDir(const std::string &_openssl_dir) { openssl_dir = _openssl_dir; }
|
||||
void setSSLFlag(const bool _encrypted_connection) { encrypted_connection = _encrypted_connection; }
|
||||
void setOrchestrationMode(OrchestrationMode _orchstration_mode) { orchestration_mode = _orchstration_mode; }
|
||||
bool getSSLFlag() const { return encrypted_connection; }
|
||||
|
||||
bool readAgentDetails();
|
||||
bool writeAgentDetails();
|
||||
|
||||
void serialize(cereal::JSONOutputArchive &ar);
|
||||
void serialize(cereal::JSONInputArchive &ar);
|
||||
|
||||
void setClusterId(const std::string &_cluster_id);
|
||||
private:
|
||||
std::string fog_domain = "";
|
||||
std::string agent_id = "";
|
||||
std::string tenant_id = "";
|
||||
std::string profile_id = "";
|
||||
std::string proxy = "";
|
||||
std::string openssl_dir = "";
|
||||
std::string cluster_id = "";
|
||||
std::string filesystem_path = "/etc/cp";
|
||||
std::string log_files_path = "/var/log";
|
||||
uint16_t fog_port = 0;
|
||||
bool encrypted_connection = false;
|
||||
OrchestrationMode orchestration_mode = OrchestrationMode::ONLINE;
|
||||
|
||||
static const std::map<std::string, I_AgentDetails::MachineType> machineTypes;
|
||||
void registerMachineType();
|
||||
Maybe<I_AgentDetails::MachineType> getMachineTypeFromDmiTable();
|
||||
};
|
||||
|
||||
#endif // __AGENT_DETAILS_H__
|
51
core/include/services_sdk/resources/agent_details_report.h
Normal file
51
core/include/services_sdk/resources/agent_details_report.h
Normal file
@@ -0,0 +1,51 @@
|
||||
// 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 __AGENT_DETAILS_REPORT_H__
|
||||
#define __AGENT_DETAILS_REPORT_H__
|
||||
|
||||
#include <string>
|
||||
#include <map>
|
||||
|
||||
#include "i_agent_details_reporter.h"
|
||||
#include "singleton.h"
|
||||
#include "maybe_res.h"
|
||||
|
||||
#define AgentReportField(value) make_pair(#value, value)
|
||||
#define AgentReportFieldWithLabel(key, value) make_pair(key, value)
|
||||
|
||||
class AgentDataReport
|
||||
:
|
||||
Singleton::Consume<I_AgentDetailsReporter>
|
||||
{
|
||||
public:
|
||||
AgentDataReport() = default;
|
||||
~AgentDataReport();
|
||||
|
||||
AgentDataReport & operator<<(const std::pair<std::string, std::string> &data);
|
||||
|
||||
void setPolicyVersion(const std::string &policy_version);
|
||||
void setPlatform(const std::string &platform);
|
||||
void setArchitecture(const std::string &architecture);
|
||||
void setAgentVersion(const std::string &_agent_version);
|
||||
|
||||
private:
|
||||
metaDataReport agent_details;
|
||||
Maybe<std::string> policy_version = genError("Not set");
|
||||
Maybe<std::string> platform = genError("Not set");
|
||||
Maybe<std::string> architecture = genError("Not set");
|
||||
Maybe<std::string> agent_version = genError("Not set");
|
||||
Maybe<std::map<std::string, std::string>> attributes = genError("Not set");
|
||||
};
|
||||
|
||||
#endif // __AGENT_DETAILS_REPORT_H__
|
39
core/include/services_sdk/resources/component.h
Executable file
39
core/include/services_sdk/resources/component.h
Executable file
@@ -0,0 +1,39 @@
|
||||
// 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 __COMPONENT_H__
|
||||
#define __COMPONENT_H__
|
||||
|
||||
#include <string>
|
||||
#include <typeinfo>
|
||||
|
||||
class Component
|
||||
{
|
||||
public:
|
||||
Component(const std::string &component_name) : name(component_name) {}
|
||||
virtual ~Component() {}
|
||||
|
||||
// LCOV_EXCL_START Reason: This functions are tested in system tests
|
||||
virtual void preload() {}
|
||||
|
||||
virtual void init() {}
|
||||
virtual void fini() {}
|
||||
// LCOV_EXCL_STOP
|
||||
|
||||
const std::string & getName() const { return name; }
|
||||
|
||||
private:
|
||||
std::string name;
|
||||
};
|
||||
|
||||
#endif // __COMPONENT_H__
|
236
core/include/services_sdk/resources/component_is/components_list_impl.h
Executable file
236
core/include/services_sdk/resources/component_is/components_list_impl.h
Executable file
@@ -0,0 +1,236 @@
|
||||
// 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 __COMPONENTS_LIST_IMPL_H__
|
||||
#define __COMPONENTS_LIST_IMPL_H__
|
||||
|
||||
#ifndef __COMPONENTS_LIST_H__
|
||||
#error components_list_impl.h should not be included directly!
|
||||
#endif // __COMPONENTS_LIST_H__
|
||||
|
||||
#include <type_traits>
|
||||
|
||||
#include "component.h"
|
||||
#include "time_proxy.h"
|
||||
#include "debug.h"
|
||||
#include "config_component.h"
|
||||
#include "mainloop.h"
|
||||
#include "version.h"
|
||||
#include "environment.h"
|
||||
#include "rest_server.h"
|
||||
#include "logging_comp.h"
|
||||
#include "log_generator.h"
|
||||
#include "proto_message_comp.h"
|
||||
#include "table.h"
|
||||
#include "agent_details.h"
|
||||
#include "encryptor.h"
|
||||
#include "signal_handler.h"
|
||||
#include "cpu.h"
|
||||
#include "memory_consumption.h"
|
||||
#include "instance_awareness.h"
|
||||
#include "socket_is.h"
|
||||
#include "generic_rulebase/generic_rulebase.h"
|
||||
#include "generic_rulebase/generic_rulebase_context.h"
|
||||
#include "messaging_buffer.h"
|
||||
#include "shell_cmd.h"
|
||||
#include "generic_metric.h"
|
||||
#include "tenant_manager.h"
|
||||
#include "buffer.h"
|
||||
#include "intelligence_comp_v2.h"
|
||||
|
||||
USE_DEBUG_FLAG(D_COMP_IS);
|
||||
|
||||
namespace Infra
|
||||
{
|
||||
|
||||
class ComponentListException
|
||||
{
|
||||
public:
|
||||
static ComponentListException
|
||||
createVersioException(const std::string &version)
|
||||
{
|
||||
return ComponentListException(version, false);
|
||||
}
|
||||
|
||||
static ComponentListException
|
||||
createException(const std::string &_str)
|
||||
{
|
||||
return ComponentListException(_str, true);
|
||||
}
|
||||
|
||||
const std::string & getError() const { return str; }
|
||||
bool getIsError() const { return is_error; }
|
||||
|
||||
private:
|
||||
ComponentListException(const std::string &_str, bool _is_error) : str(_str), is_error(_is_error) {}
|
||||
|
||||
std::string str;
|
||||
bool is_error;
|
||||
};
|
||||
|
||||
template <typename Component, bool>
|
||||
class ComponentWrapper
|
||||
{
|
||||
public:
|
||||
void preload() { comp.preload(); }
|
||||
void init() { comp.init(); }
|
||||
void fini() { comp.fini(); }
|
||||
|
||||
const std::string & getName() const { return comp.getName(); }
|
||||
|
||||
private:
|
||||
Component comp;
|
||||
};
|
||||
|
||||
template <typename Component>
|
||||
class ComponentWrapper<Component, false>
|
||||
{
|
||||
public:
|
||||
void preload() { Component::preload(); }
|
||||
void init() { Component::init(); }
|
||||
void fini() { Component::fini(); }
|
||||
|
||||
const std::string getName() const { return Component::getName(); }
|
||||
};
|
||||
|
||||
template <typename ... Components>
|
||||
class ComponentList
|
||||
{
|
||||
};
|
||||
|
||||
template <typename Component, typename ... MoreComponents>
|
||||
class ComponentList<Component, MoreComponents...> : public ComponentList<MoreComponents...>
|
||||
{
|
||||
protected:
|
||||
void
|
||||
preloadComponents(const std::string &nano_service_name)
|
||||
{
|
||||
dbgInfo(D_COMP_IS) << "Preloading component: " << comp.getName();
|
||||
comp.preload();
|
||||
ComponentList<MoreComponents...>::preloadComponents(nano_service_name);
|
||||
}
|
||||
|
||||
void
|
||||
init()
|
||||
{
|
||||
dbgInfo(D_COMP_IS) << "Initializing component: " << comp.getName();
|
||||
comp.init();
|
||||
ComponentList<MoreComponents...>::init();
|
||||
}
|
||||
|
||||
void
|
||||
fini()
|
||||
{
|
||||
ComponentList<MoreComponents...>::fini();
|
||||
dbgInfo(D_COMP_IS) << "Finalizing component: " << comp.getName();
|
||||
comp.fini();
|
||||
}
|
||||
|
||||
private:
|
||||
ComponentWrapper<Component, std::is_base_of<::Component, Component>::value> comp;
|
||||
};
|
||||
|
||||
template <>
|
||||
class ComponentList<>
|
||||
:
|
||||
Singleton::Consume<I_Environment>,
|
||||
Singleton::Consume<Config::I_Config>,
|
||||
Singleton::Consume<I_MainLoop>
|
||||
{
|
||||
public:
|
||||
template <typename T>
|
||||
void
|
||||
registerGlobalValue(const std::string &name, const T &value)
|
||||
{
|
||||
Singleton::Consume<I_Environment>::by<ComponentList>()->registerValue(name, value);
|
||||
}
|
||||
|
||||
void
|
||||
handleArgs(const std::vector<std::string> &arg_vec)
|
||||
{
|
||||
for (auto &arg : arg_vec) {
|
||||
if (arg == "--version") {
|
||||
throw ComponentListException::createVersioException(Version::get());
|
||||
}
|
||||
}
|
||||
|
||||
registerGlobalValue<std::string>("Executable Name", arg_vec.front());
|
||||
}
|
||||
|
||||
void
|
||||
preloadComponents(const std::string &nano_service_name)
|
||||
{
|
||||
registerGlobalValue<std::string>("Service Name", nano_service_name);
|
||||
}
|
||||
|
||||
void
|
||||
loadConfiguration(const std::vector<std::string> &arg_vec)
|
||||
{
|
||||
if (!Singleton::Consume<Config::I_Config>::by<ComponentList>()->loadConfiguration(arg_vec)) {
|
||||
throw ComponentListException::createException("Failed to load configuration");
|
||||
}
|
||||
}
|
||||
|
||||
void init() {}
|
||||
void fini() {}
|
||||
|
||||
void
|
||||
run(const std::string &nano_service_name)
|
||||
{
|
||||
LogGen(
|
||||
"Check Point Nano-service started",
|
||||
ReportIS::Audience::SECURITY,
|
||||
ReportIS::Severity::INFO,
|
||||
ReportIS::Priority::MEDIUM,
|
||||
ReportIS::Tags::INFORMATIONAL
|
||||
) << LogField("serviceName", nano_service_name);
|
||||
Singleton::Consume<I_MainLoop>::by<ComponentList>()->run();
|
||||
}
|
||||
};
|
||||
|
||||
template <typename ... Components>
|
||||
class ComponentListCore
|
||||
:
|
||||
public ComponentList<
|
||||
Environment,
|
||||
Debug,
|
||||
Version,
|
||||
Buffer,
|
||||
ShellCmd,
|
||||
GenericMetric,
|
||||
ConfigComponent,
|
||||
InstanceAwareness,
|
||||
IntelligenceComponentV2,
|
||||
AgentDetails,
|
||||
LoggingComp,
|
||||
TimeProxyComponent,
|
||||
MainloopComponent,
|
||||
SignalHandler,
|
||||
RestServer,
|
||||
Encryptor,
|
||||
SocketIS,
|
||||
ProtoMessageComp,
|
||||
CPUCalculator,
|
||||
CPUManager,
|
||||
MemoryCalculator,
|
||||
MessagingBuffer,
|
||||
TenantManager,
|
||||
GenericRulebase,
|
||||
Components...
|
||||
>
|
||||
{
|
||||
};
|
||||
|
||||
} // namespace Infra
|
||||
|
||||
#endif // __COMPONENTS_LIST_IMPL_H__
|
54
core/include/services_sdk/resources/component_is/node_components_impl.h
Executable file
54
core/include/services_sdk/resources/component_is/node_components_impl.h
Executable file
@@ -0,0 +1,54 @@
|
||||
// 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 __NODE_COMPONENTS_IMPL_H__
|
||||
#define __NODE_COMPONENTS_IMPL_H__
|
||||
|
||||
#ifndef __COMPONENTS_LIST_H__
|
||||
#error node_components_impl.h should not be included directly!
|
||||
#endif // __COMPONENTS_LIST_H__
|
||||
|
||||
template <typename ... Components>
|
||||
int
|
||||
NodeComponents<Components...>::run(const std::string &nano_service_name, int argc, char **argv)
|
||||
{
|
||||
std::vector<std::string> arg_vec(argv, argv+argc);
|
||||
|
||||
try {
|
||||
Infra::ComponentListCore<Components...>::handleArgs(arg_vec);
|
||||
|
||||
Infra::ComponentListCore<Components...>::preloadComponents(nano_service_name);
|
||||
Infra::ComponentListCore<Components...>::loadConfiguration(arg_vec);
|
||||
|
||||
Infra::ComponentListCore<Components...>::init();
|
||||
Infra::ComponentListCore<Components...>::run(nano_service_name);
|
||||
Infra::ComponentListCore<Components...>::fini();
|
||||
} catch (const Infra::ComponentListException &comp_exception) {
|
||||
if (comp_exception.getIsError()) {
|
||||
std::cerr << "Error: " << comp_exception.getError() << std::endl;
|
||||
abort();
|
||||
} else {
|
||||
std::cout << comp_exception.getError() << std::endl;
|
||||
return 0;
|
||||
}
|
||||
} catch (const std::exception &exception) {
|
||||
std::cerr << "Error: " << exception.what() << std::endl;
|
||||
abort();
|
||||
} catch (...) {
|
||||
std::cerr << "Error: Caught unknown exception" << std::endl;
|
||||
abort();
|
||||
}
|
||||
return 0;
|
||||
}
|
||||
|
||||
#endif // __NODE_COMPONENTS_IMPL_H__
|
35
core/include/services_sdk/resources/components_list.h
Executable file
35
core/include/services_sdk/resources/components_list.h
Executable file
@@ -0,0 +1,35 @@
|
||||
// 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 __COMPONENTS_LIST_H__
|
||||
#define __COMPONENTS_LIST_H__
|
||||
|
||||
#include <string>
|
||||
|
||||
#include "component_is/components_list_impl.h"
|
||||
|
||||
template <typename ... Components>
|
||||
class NodeComponents : public Infra::ComponentListCore<Components...>
|
||||
{
|
||||
public:
|
||||
int run(const std::string &nano_service_name, int argc, char **argv);
|
||||
};
|
||||
|
||||
template <typename TableKey, typename ... Components>
|
||||
class NodeComponentsWithTable : public NodeComponents<Table<TableKey>, Components...>
|
||||
{
|
||||
};
|
||||
|
||||
#include "component_is/node_components_impl.h"
|
||||
|
||||
#endif // __COMPONENTS_LIST_H__
|
98
core/include/services_sdk/resources/config.h
Normal file
98
core/include/services_sdk/resources/config.h
Normal file
@@ -0,0 +1,98 @@
|
||||
// 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 __CONFIG_H__
|
||||
#define __CONFIG_H__
|
||||
|
||||
#include <string>
|
||||
|
||||
#include "common.h"
|
||||
#include "maybe_res.h"
|
||||
#include "config/config_exception.h"
|
||||
#include "config/config_types.h"
|
||||
#include "config/type_wrapper.h"
|
||||
#include "config/config_loader.h"
|
||||
#include "config/generic_config.h"
|
||||
#include "config/range_config.h"
|
||||
#include "config/i_config.h"
|
||||
|
||||
template <typename ConfigurationType, typename ... Strings>
|
||||
const Maybe<ConfigurationType, Config::Errors> & getConfiguration(const Strings & ... tags);
|
||||
|
||||
template <typename ConfigurationType, typename ... Strings>
|
||||
const ConfigurationType & getConfigurationWithDefault(const ConfigurationType &deafult_val, const Strings & ... tags);
|
||||
|
||||
template <typename ConfigurationType, typename ...Strings>
|
||||
Config::ConfigRange<ConfigurationType> getConfigurationMultimatch(const Strings & ... tags);
|
||||
|
||||
template <typename ResourceType, typename ... Strings>
|
||||
const Maybe<ResourceType, Config::Errors> & getResource(const Strings & ... tags);
|
||||
|
||||
template <typename ResourceType, typename ... Strings>
|
||||
const ResourceType & getResourceWithDefault(const ResourceType &deafult_val, const Strings & ... tags);
|
||||
|
||||
template <typename SettingType, typename ... Strings>
|
||||
const Maybe<SettingType, Config::Errors> & getSetting(const Strings & ... tags);
|
||||
|
||||
template <typename SettingType, typename ... Strings>
|
||||
const SettingType & getSettingWithDefault(const SettingType &deafult_val, const Strings & ... tags);
|
||||
|
||||
template <typename SettingType>
|
||||
Maybe<SettingType, Config::Errors> getProfileAgentSetting(const std::string &setting);
|
||||
|
||||
template <typename SettingType>
|
||||
SettingType getProfileAgentSettingWithDefault(const SettingType &deafult_val, const std::string &setting);
|
||||
|
||||
template <typename SettingType>
|
||||
Maybe<std::vector<SettingType>, Config::Errors> getProfileAgentSettingByRegex(const std::string ®ex);
|
||||
|
||||
template <typename ConfigurationType, typename ... Strings>
|
||||
bool setConfiguration(const ConfigurationType &value, const Strings & ... tags);
|
||||
|
||||
template <typename ResourceType, typename ... Strings>
|
||||
bool setResource(const ResourceType &value, const Strings & ... tags);
|
||||
|
||||
template <typename SettingType, typename ... Strings>
|
||||
bool setSetting(const SettingType &value, const Strings & ... tags);
|
||||
|
||||
template <typename ConfigurationType, typename ... Strings>
|
||||
void registerExpectedConfiguration(const Strings & ... tags);
|
||||
|
||||
template <typename ResourceType, typename ... Strings>
|
||||
void registerExpectedResource(const Strings & ... tags);
|
||||
|
||||
template <typename SettingType, typename ... Strings>
|
||||
void registerExpectedSetting(const Strings & ... tags);
|
||||
|
||||
void reportConfigurationError(const std::string &err);
|
||||
|
||||
std::ostream & operator<<(std::ostream &os, const Config::Errors &err);
|
||||
|
||||
void registerConfigPrepareCb(Config::ConfigCb);
|
||||
void registerConfigLoadCb(Config::ConfigCb);
|
||||
void registerConfigAbortCb(Config::ConfigCb);
|
||||
|
||||
bool reloadConfiguration(const std::string &version = "");
|
||||
|
||||
std::string getConfigurationFlag(const std::string &flag);
|
||||
|
||||
const std::string & getFilesystemPathConfig();
|
||||
const std::string & getLogFilesPathConfig();
|
||||
|
||||
std::string getPolicyConfigPath(const std::string &name, Config::ConfigFileType type, const std::string &tenant = "");
|
||||
|
||||
void registerExpectedConfigFile(const std::string &config_name, Config::ConfigFileType type);
|
||||
|
||||
#include "config/config_impl.h"
|
||||
|
||||
#endif // __CONFIG_H__
|
@@ -0,0 +1,36 @@
|
||||
// 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 __CONFIG_EXCEPTION_H__
|
||||
#define __CONFIG_EXCEPTION_H__
|
||||
|
||||
#ifndef __CONFIG_H__
|
||||
#error "config_exception.h should not be included directly"
|
||||
#endif // __CONFIG_H__
|
||||
|
||||
namespace Config
|
||||
{
|
||||
|
||||
class ConfigException
|
||||
{
|
||||
public:
|
||||
ConfigException(const std::string &_str) : str(_str) {}
|
||||
const std::string & getError() const { return str; }
|
||||
|
||||
private:
|
||||
std::string str;
|
||||
};
|
||||
|
||||
} // namespace Config
|
||||
|
||||
#endif // __CONFIG_EXCEPTION_H__
|
256
core/include/services_sdk/resources/config/config_impl.h
Normal file
256
core/include/services_sdk/resources/config/config_impl.h
Normal file
@@ -0,0 +1,256 @@
|
||||
// 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 __CONFIG_IMPL_H__
|
||||
#define __CONFIG_IMPL_H__
|
||||
|
||||
#ifndef __CONFIG_H__
|
||||
#error "config_impl.h should not be included directly"
|
||||
#endif // __CONFIG_H__
|
||||
|
||||
namespace Config
|
||||
{
|
||||
|
||||
class MockConfigProvider : Singleton::Provide<I_Config> {};
|
||||
|
||||
template<typename String>
|
||||
std::size_t
|
||||
getParamsNumber(const String &)
|
||||
{
|
||||
return 1;
|
||||
}
|
||||
|
||||
template<typename String, typename ... Strings>
|
||||
std::size_t
|
||||
getParamsNumber(const String &, const Strings & ... strs)
|
||||
{
|
||||
return getParamsNumber(strs ...) + 1;
|
||||
}
|
||||
|
||||
template<typename String>
|
||||
void
|
||||
addStringsToVector(std::vector<std::string> &vec, const String &str)
|
||||
{
|
||||
vec.emplace_back(str);
|
||||
}
|
||||
|
||||
template<typename String, typename ... Strings>
|
||||
void
|
||||
addStringsToVector(std::vector<std::string> &vec, const String &str, const Strings & ... strs)
|
||||
{
|
||||
vec.emplace_back(str);
|
||||
addStringsToVector(vec, strs ...);
|
||||
}
|
||||
|
||||
template<typename ... Strings>
|
||||
std::vector<std::string>
|
||||
getVector(const Strings & ... strs)
|
||||
{
|
||||
std::vector<std::string> res;
|
||||
res.reserve(getParamsNumber(strs ...));
|
||||
addStringsToVector(res, strs ...);
|
||||
return res;
|
||||
}
|
||||
|
||||
} // namespace Config
|
||||
|
||||
template <typename ConfigurationType, typename ... Strings>
|
||||
const Maybe<ConfigurationType, Config::Errors> &
|
||||
getConfiguration(const Strings & ... strs)
|
||||
{
|
||||
auto i_config = Singleton::Consume<Config::I_Config>::from<Config::MockConfigProvider>();
|
||||
return i_config->getConfiguration(Config::getVector(strs ...)).template getValue<ConfigurationType>();
|
||||
};
|
||||
|
||||
template <typename ConfigurationType, typename ... Strings>
|
||||
const ConfigurationType &
|
||||
getConfigurationWithDefault(const ConfigurationType &deafult_val, const Strings & ... tags)
|
||||
{
|
||||
if (!Singleton::exists<Config::I_Config>()) return deafult_val;
|
||||
auto &res = getConfiguration<ConfigurationType>(tags ...);
|
||||
return res.ok() ? res.unpack() : deafult_val;
|
||||
}
|
||||
|
||||
template <typename ConfigurationType, typename ... Strings>
|
||||
Config::ConfigRange<ConfigurationType>
|
||||
getConfigurationMultimatch(const Strings & ... strs)
|
||||
{
|
||||
if (!Singleton::exists<Config::I_Config>()) return Config::ConfigRange<ConfigurationType>();
|
||||
auto i_config = Singleton::Consume<Config::I_Config>::from<Config::MockConfigProvider>();
|
||||
return Config::ConfigRange<ConfigurationType>(i_config->getAllConfiguration(Config::getVector(strs ...)));
|
||||
}
|
||||
|
||||
template <typename ConfigurationType, typename ... Strings>
|
||||
const Maybe<ConfigurationType, Config::Errors> &
|
||||
getResource(const Strings & ... strs)
|
||||
{
|
||||
auto i_config = Singleton::Consume<Config::I_Config>::from<Config::MockConfigProvider>();
|
||||
return i_config->getResource(Config::getVector(strs ...)).template getValue<ConfigurationType>();
|
||||
};
|
||||
|
||||
template <typename ConfigurationType, typename ... Strings>
|
||||
const ConfigurationType &
|
||||
getResourceWithDefault(const ConfigurationType &deafult_val, const Strings & ... tags)
|
||||
{
|
||||
if (!Singleton::exists<Config::I_Config>()) return deafult_val;
|
||||
auto &res = getResource<ConfigurationType>(tags ...);
|
||||
return res.ok() ? res.unpack() : deafult_val;
|
||||
}
|
||||
|
||||
template <typename ConfigurationType, typename ... Strings>
|
||||
const Maybe<ConfigurationType, Config::Errors> &
|
||||
getSetting(const Strings & ... strs)
|
||||
{
|
||||
auto i_config = Singleton::Consume<Config::I_Config>::from<Config::MockConfigProvider>();
|
||||
return i_config->getSetting(Config::getVector(strs ...)).template getValue<ConfigurationType>();
|
||||
};
|
||||
|
||||
template <typename ConfigurationType, typename ... Strings>
|
||||
const ConfigurationType &
|
||||
getSettingWithDefault(const ConfigurationType &deafult_val, const Strings & ... tags)
|
||||
{
|
||||
if (!Singleton::exists<Config::I_Config>()) return deafult_val;
|
||||
auto &res = getSetting<ConfigurationType>(tags ...);
|
||||
return res.ok() ? res.unpack() : deafult_val;
|
||||
}
|
||||
|
||||
namespace Config
|
||||
{
|
||||
|
||||
template <typename ProfileSettingType>
|
||||
ProfileSettingType
|
||||
loadProfileSetting(const std::string &val)
|
||||
{
|
||||
ProfileSettingType res;
|
||||
res.load(val);
|
||||
return res;
|
||||
}
|
||||
|
||||
template<>
|
||||
bool loadProfileSetting<bool>(const std::string &val);
|
||||
|
||||
template<>
|
||||
int loadProfileSetting<int>(const std::string &val);
|
||||
|
||||
template<>
|
||||
uint loadProfileSetting<uint>(const std::string &val);
|
||||
|
||||
template<>
|
||||
std::string loadProfileSetting<std::string>(const std::string &val);
|
||||
|
||||
} // namespace Config
|
||||
|
||||
template <typename SettingType>
|
||||
Maybe<SettingType, Config::Errors>
|
||||
getProfileAgentSetting(const std::string &setting)
|
||||
{
|
||||
auto i_config = Singleton::Consume<Config::I_Config>::from<Config::MockConfigProvider>();
|
||||
const std::string &value = i_config->getProfileAgentSetting(setting);
|
||||
|
||||
if (value.empty()) return TypeWrapper::failMissing<SettingType>();
|
||||
|
||||
try {
|
||||
return Config::loadProfileSetting<SettingType>(value);
|
||||
} catch (cereal::Exception &e) {
|
||||
dbgTrace(D_CONFIG) << "Failed to get value for setting. Setting name: " << setting << ", Error " << e.what();
|
||||
}
|
||||
|
||||
return TypeWrapper::failBadNode<SettingType>();
|
||||
};
|
||||
|
||||
template <typename SettingType>
|
||||
SettingType
|
||||
getProfileAgentSettingWithDefault(const SettingType &deafult_val, const std::string &setting)
|
||||
{
|
||||
const auto &res = getProfileAgentSetting<SettingType>(setting);
|
||||
return res.ok() ? res.unpack() : deafult_val;
|
||||
}
|
||||
|
||||
template <typename SettingType>
|
||||
Maybe<std::vector<SettingType>, Config::Errors>
|
||||
getProfileAgentSettingByRegex(const std::string ®ex)
|
||||
{
|
||||
auto i_config = Singleton::Consume<Config::I_Config>::from<Config::MockConfigProvider>();
|
||||
auto values = i_config->getProfileAgentSettings(regex);
|
||||
|
||||
if (values.empty()) return genError(Config::Errors::MISSING_TAG);
|
||||
|
||||
std::vector<SettingType> retValues;
|
||||
retValues.reserve(values.size());
|
||||
for (auto &value: values) {
|
||||
try {
|
||||
auto retValue = Config::loadProfileSetting<SettingType>(value);
|
||||
retValues.push_back(retValue);
|
||||
} catch(const std::exception &e) {
|
||||
dbgTrace(D_CONFIG)
|
||||
<< "Failed to get value for setting. Setting value: "
|
||||
<< value
|
||||
<< ", Error: "
|
||||
<< e.what();
|
||||
}
|
||||
}
|
||||
return retValues;
|
||||
}
|
||||
|
||||
template <typename ConfigurationType, typename ... Strings>
|
||||
bool
|
||||
setConfiguration(const ConfigurationType &value, const Strings & ... tags)
|
||||
{
|
||||
auto i_config = Singleton::Consume<Config::I_Config>::from<Config::MockConfigProvider>();
|
||||
return i_config->setConfiguration(TypeWrapper(value), Config::getVector(tags ...));
|
||||
}
|
||||
|
||||
template <typename ResourceType, typename ... Strings>
|
||||
bool
|
||||
setResource(const ResourceType &value, const Strings & ... tags)
|
||||
{
|
||||
auto i_config = Singleton::Consume<Config::I_Config>::from<Config::MockConfigProvider>();
|
||||
return i_config->setResource(TypeWrapper(value), Config::getVector(tags ...));
|
||||
}
|
||||
|
||||
template <typename SettingType, typename ... Strings>
|
||||
bool
|
||||
setSetting(const SettingType &value, const Strings & ... tags)
|
||||
{
|
||||
auto i_config = Singleton::Consume<Config::I_Config>::from<Config::MockConfigProvider>();
|
||||
return i_config->setSetting(TypeWrapper(value), Config::getVector(tags ...));
|
||||
}
|
||||
|
||||
template <typename ConfigurationType, typename ... Strings>
|
||||
void
|
||||
registerExpectedConfiguration(const Strings & ... tags)
|
||||
{
|
||||
auto conf = std::make_unique<Config::SpecificConfig<ConfigurationType, true>>(Config::getVector(tags ...));
|
||||
auto i_config = Singleton::Consume<Config::I_Config>::from<Config::MockConfigProvider>();
|
||||
i_config->registerExpectedConfiguration(std::move(conf));
|
||||
}
|
||||
|
||||
template <typename ResourceType, typename ... Strings>
|
||||
void
|
||||
registerExpectedResource(const Strings & ... tags)
|
||||
{
|
||||
auto conf = std::make_unique<Config::SpecificConfig<ResourceType, false>>(Config::getVector(tags ...));
|
||||
auto i_config = Singleton::Consume<Config::I_Config>::from<Config::MockConfigProvider>();
|
||||
i_config->registerExpectedResource(std::move(conf));
|
||||
}
|
||||
|
||||
template <typename SettingType, typename ... Strings>
|
||||
void
|
||||
registerExpectedSetting(const Strings & ... tags)
|
||||
{
|
||||
auto conf = std::make_unique<Config::SpecificConfig<SettingType, false>>(Config::getVector(tags ...));
|
||||
auto i_config = Singleton::Consume<Config::I_Config>::from<Config::MockConfigProvider>();
|
||||
i_config->registerExpectedSetting(std::move(conf));
|
||||
}
|
||||
|
||||
#endif // __CONFIG_IMPL_H__
|
86
core/include/services_sdk/resources/config/config_loader.h
Normal file
86
core/include/services_sdk/resources/config/config_loader.h
Normal file
@@ -0,0 +1,86 @@
|
||||
// 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 __CONFIG_LOADER_H__
|
||||
#define __CONFIG_LOADER_H__
|
||||
|
||||
#ifndef __CONFIG_H__
|
||||
#error "config_loader.h should not be included directly"
|
||||
#endif // __CONFIG_H__
|
||||
|
||||
#include "cereal/archives/json.hpp"
|
||||
#include "cereal/types/string.hpp"
|
||||
#include "cereal/types/vector.hpp"
|
||||
|
||||
#include "environment_evaluator.h"
|
||||
#include "debug.h"
|
||||
|
||||
USE_DEBUG_FLAG(D_CONFIG);
|
||||
|
||||
namespace Config
|
||||
{
|
||||
|
||||
template <typename T>
|
||||
class ConfigLoader
|
||||
{
|
||||
public:
|
||||
void
|
||||
load(cereal::JSONInputArchive &ar)
|
||||
{
|
||||
try {
|
||||
readValue(ar);
|
||||
} catch (cereal::Exception &e) {
|
||||
dbgTrace(D_CONFIG) << "Failed to read value. Error: " << e.what();
|
||||
throw ConfigException(e.what());
|
||||
}
|
||||
try {
|
||||
std::string context_str;
|
||||
ar(cereal::make_nvp("context", context_str));
|
||||
if (!context_str.empty()) context = getMatcher<bool>(context_str);
|
||||
} catch (cereal::Exception &e) {
|
||||
dbgTrace(D_CONFIG) << "Failed to load. Error: " << e.what();
|
||||
}
|
||||
}
|
||||
|
||||
std::pair<std::unique_ptr<EnvironmentEvaluator<bool>>, TypeWrapper>
|
||||
getLoaderConfig()
|
||||
{
|
||||
return std::move(std::make_pair(std::move(context), TypeWrapper(value)));
|
||||
}
|
||||
|
||||
private:
|
||||
void readValue(cereal::JSONInputArchive &ar) { value.load(ar); }
|
||||
|
||||
T value;
|
||||
std::unique_ptr<EnvironmentEvaluator<bool>> context;
|
||||
};
|
||||
|
||||
template<>
|
||||
void
|
||||
ConfigLoader<bool>::readValue(cereal::JSONInputArchive &ar);
|
||||
|
||||
template<>
|
||||
void
|
||||
ConfigLoader<int>::readValue(cereal::JSONInputArchive &ar);
|
||||
|
||||
template<>
|
||||
void
|
||||
ConfigLoader<uint>::readValue(cereal::JSONInputArchive &ar);
|
||||
|
||||
template<>
|
||||
void
|
||||
ConfigLoader<std::string>::readValue(cereal::JSONInputArchive &ar);
|
||||
|
||||
} // namespace Config
|
||||
|
||||
#endif // __CONFIG_LOADER_H__
|
33
core/include/services_sdk/resources/config/config_types.h
Normal file
33
core/include/services_sdk/resources/config/config_types.h
Normal file
@@ -0,0 +1,33 @@
|
||||
// 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 __CONFIG_TYPES_H__
|
||||
#define __CONFIG_TYPES_H__
|
||||
|
||||
#ifndef __CONFIG_H__
|
||||
#error "config_types.h should not be included directly"
|
||||
#endif // __CONFIG_H__
|
||||
|
||||
#include <functional>
|
||||
|
||||
namespace Config
|
||||
{
|
||||
|
||||
using ConfigCb = std::function<void(void)>;
|
||||
|
||||
enum class Errors { MISSING_TAG, MISSING_CONTEXT, BAD_NODE };
|
||||
enum class ConfigFileType { Policy, Data, RawData, COUNT };
|
||||
|
||||
} // namespace Config
|
||||
|
||||
#endif // __CONFIG_TYPES_H__
|
134
core/include/services_sdk/resources/config/generic_config.h
Normal file
134
core/include/services_sdk/resources/config/generic_config.h
Normal file
@@ -0,0 +1,134 @@
|
||||
// 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 __GENERIC_CONFIG_H__
|
||||
#define __GENERIC_CONFIG_H___
|
||||
|
||||
#ifndef __CONFIG_H__
|
||||
#error "generic_config.h should not be included directly"
|
||||
#endif // __CONFIG_H__
|
||||
|
||||
namespace Config
|
||||
{
|
||||
|
||||
template <bool IsPerContext>
|
||||
struct ConfigTypesBasic
|
||||
{
|
||||
using ReturnType = TypeWrapper;
|
||||
};
|
||||
|
||||
template <typename T, bool IsPerContext>
|
||||
struct ConfigTypes : ConfigTypesBasic<IsPerContext>
|
||||
{
|
||||
using LoadType = T;
|
||||
|
||||
static typename ConfigTypesBasic<IsPerContext>::ReturnType
|
||||
convetLoadToReturn(const LoadType &val)
|
||||
{
|
||||
return typename ConfigTypesBasic<IsPerContext>::ReturnType(val);
|
||||
}
|
||||
};
|
||||
|
||||
template <>
|
||||
struct ConfigTypesBasic<true>
|
||||
{
|
||||
using ReturnType = std::vector<std::pair<std::shared_ptr<EnvironmentEvaluator<bool>>, TypeWrapper>>;
|
||||
};
|
||||
|
||||
template <typename T>
|
||||
struct ConfigTypes<T, true> : ConfigTypesBasic<true>
|
||||
{
|
||||
using LoadType = std::vector<ConfigLoader<T>>;
|
||||
static typename ConfigTypesBasic<true>::ReturnType
|
||||
convetLoadToReturn(LoadType &val)
|
||||
{
|
||||
ReturnType res;
|
||||
res.reserve(val.size());
|
||||
|
||||
for (auto &entry : val) {
|
||||
res.emplace_back(std::move(entry.getLoaderConfig()));
|
||||
}
|
||||
|
||||
return res;
|
||||
}
|
||||
};
|
||||
|
||||
template <bool IsPerContext>
|
||||
class GenericConfig
|
||||
{
|
||||
public:
|
||||
GenericConfig(const std::vector<std::string> &_path) : path(_path) {}
|
||||
|
||||
const std::vector<std::string> & getPath() const { return path; }
|
||||
|
||||
typename ConfigTypesBasic<IsPerContext>::ReturnType
|
||||
loadConfiguration(cereal::JSONInputArchive &ar)
|
||||
{
|
||||
res = typename ConfigTypesBasic<IsPerContext>::ReturnType();
|
||||
iter = path.begin();
|
||||
try {
|
||||
load(ar);
|
||||
} catch (cereal::Exception &e) {
|
||||
dbgTrace(D_CONFIG) << "Failed to load generic configuration. Error: " << e.what();
|
||||
}
|
||||
return res;
|
||||
}
|
||||
|
||||
void
|
||||
load(cereal::JSONInputArchive &ar)
|
||||
{
|
||||
const std::string &curr_tag = *iter;
|
||||
iter++;
|
||||
if (iter == path.end()) {
|
||||
loadContextArray(ar, curr_tag);
|
||||
} else {
|
||||
ar(cereal::make_nvp(curr_tag, *this));
|
||||
}
|
||||
}
|
||||
|
||||
virtual void loadContextArray(cereal::JSONInputArchive &ar, const std::string &curr_tag) = 0;
|
||||
|
||||
protected:
|
||||
std::vector<std::string> path;
|
||||
std::vector<std::string>::iterator iter;
|
||||
typename ConfigTypesBasic<IsPerContext>::ReturnType res;
|
||||
};
|
||||
|
||||
template <typename T, bool IsPerContext>
|
||||
class SpecificConfig : public GenericConfig<IsPerContext>
|
||||
{
|
||||
public:
|
||||
SpecificConfig(const std::vector<std::string> &_path) : GenericConfig<IsPerContext>(_path) {}
|
||||
|
||||
void
|
||||
loadContextArray(cereal::JSONInputArchive &ar, const std::string &curr_tag) override
|
||||
{
|
||||
typename ConfigTypes<T, IsPerContext>::LoadType load;
|
||||
|
||||
try {
|
||||
ar(cereal::make_nvp(curr_tag, load));
|
||||
GenericConfig<IsPerContext>::res = std::move(ConfigTypes<T, IsPerContext>::convetLoadToReturn(load));
|
||||
} catch (cereal::Exception &e) {
|
||||
if (e.what() == "JSON Parsing failed - provided NVP (" + curr_tag + ") not found") {
|
||||
dbgTrace(D_CONFIG) << "Failed to load specific configuration. Error: " << e.what();
|
||||
return;
|
||||
}
|
||||
dbgTrace(D_CONFIG) << "Failed to load specific configuration. Error: " << e.what();
|
||||
throw ConfigException(e.what());
|
||||
}
|
||||
}
|
||||
};
|
||||
|
||||
} // namespace Config
|
||||
|
||||
#endif // __GENERIC_CONFIG_H__
|
106
core/include/services_sdk/resources/config/i_config.h
Normal file
106
core/include/services_sdk/resources/config/i_config.h
Normal file
@@ -0,0 +1,106 @@
|
||||
// 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 __I_CONFIG_H__
|
||||
#define __I_CONFIG_H__
|
||||
|
||||
#ifndef __CONFIG_H__
|
||||
#error "i_config.h should not be included directly"
|
||||
#endif // __CONFIG_H__
|
||||
|
||||
#include <istream>
|
||||
#include <ostream>
|
||||
#include <vector>
|
||||
#include <string>
|
||||
|
||||
namespace Config
|
||||
{
|
||||
|
||||
using namespace std;
|
||||
|
||||
class I_Config
|
||||
{
|
||||
using PerContextValue = std::vector<std::pair<std::shared_ptr<EnvironmentEvaluator<bool>>, TypeWrapper>>;
|
||||
|
||||
public:
|
||||
enum class AsyncLoadConfigStatus { Success, Error, InProgress };
|
||||
|
||||
virtual const TypeWrapper & getConfiguration(const std::vector<std::string> &paths) const = 0;
|
||||
virtual PerContextValue getAllConfiguration(const std::vector<std::string> &paths) const = 0;
|
||||
virtual const TypeWrapper & getResource(const std::vector<std::string> &paths) const = 0;
|
||||
virtual const TypeWrapper & getSetting(const std::vector<std::string> &paths) const = 0;
|
||||
virtual const string & getProfileAgentSetting(const string &setting_name) const = 0;
|
||||
virtual vector<string> getProfileAgentSettings(const string &setting_name_regex) const = 0;
|
||||
|
||||
virtual const string & getConfigurationFlag(const string &flag_name) const = 0;
|
||||
|
||||
virtual const string & getFilesystemPathConfig() const = 0;
|
||||
virtual const string & getLogFilesPathConfig() const = 0;
|
||||
|
||||
virtual string getPolicyConfigPath(const string &policy, ConfigFileType type, const string &tenant) const = 0;
|
||||
|
||||
virtual bool setConfiguration(TypeWrapper &&value, const std::vector<std::string> &paths) = 0;
|
||||
virtual bool setResource(TypeWrapper &&value, const std::vector<std::string> &paths) = 0;
|
||||
virtual bool setSetting(TypeWrapper &&value, const std::vector<std::string> &paths) = 0;
|
||||
|
||||
virtual void registerExpectedConfigFile(const string &file_name, ConfigFileType type) = 0;
|
||||
virtual void registerExpectedConfiguration(unique_ptr<GenericConfig<true>> &&config) = 0;
|
||||
virtual void registerExpectedResource(unique_ptr<GenericConfig<false>> &&config) = 0;
|
||||
virtual void registerExpectedSetting(unique_ptr<GenericConfig<false>> &&config) = 0;
|
||||
|
||||
template<typename T>
|
||||
void
|
||||
registerExpectedConfiguration(const vector<string> &path)
|
||||
{
|
||||
registerExpectedConfiguration(make_unique<SpecificConfig<T, true>>(path));
|
||||
}
|
||||
|
||||
template<typename T>
|
||||
void
|
||||
registerExpectedResource(const vector<string> &path)
|
||||
{
|
||||
registerExpectedResource(make_unique<SpecificConfig<T, false>>(path));
|
||||
}
|
||||
|
||||
template<typename T>
|
||||
void
|
||||
registerExpectedSetting(const vector<string> &path)
|
||||
{
|
||||
registerExpectedSetting(make_unique<SpecificConfig<T, false>>(path));
|
||||
}
|
||||
|
||||
// TODO: merge both loadConfiguration functions to one with vector of streams input when moving to c++17
|
||||
// (c++ < 17 does not support copy of streams and thus it cannot be part of any container)
|
||||
virtual bool loadConfiguration(istream &json_contents) = 0;
|
||||
virtual bool loadConfiguration(const vector<string> &configuration_flags) = 0;
|
||||
|
||||
virtual AsyncLoadConfigStatus
|
||||
reloadConfiguration(
|
||||
const std::string &ver = "",
|
||||
bool do_continuous_report = false,
|
||||
uint id = 0
|
||||
) = 0;
|
||||
|
||||
virtual bool saveConfiguration(ostream &os) const = 0;
|
||||
|
||||
virtual void registerConfigPrepareCb(ConfigCb) = 0;
|
||||
virtual void registerConfigLoadCb(ConfigCb) = 0;
|
||||
virtual void registerConfigAbortCb(ConfigCb) = 0;
|
||||
|
||||
protected:
|
||||
virtual ~I_Config() {}
|
||||
};
|
||||
|
||||
} // namespace Config
|
||||
|
||||
#endif // __I_CONFIG_H__
|
35
core/include/services_sdk/resources/config/i_config_iterator.h
Executable file
35
core/include/services_sdk/resources/config/i_config_iterator.h
Executable file
@@ -0,0 +1,35 @@
|
||||
// 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 __I_CONFIG_ITERATOR_H__
|
||||
#define __I_CONFIG_ITERATOR_H__
|
||||
|
||||
#ifndef __CONFIG_COMPONENT_H__
|
||||
#error "i_config_iterator.h should not be included directly"
|
||||
#endif // __CONFIG_COMPONENT_H__
|
||||
|
||||
#include "maybe_res.h"
|
||||
|
||||
template <typename ConfigurationType>
|
||||
class I_Config_Iterator
|
||||
{
|
||||
public:
|
||||
virtual const ConfigurationType & operator*() const = 0;
|
||||
virtual void operator++() = 0;
|
||||
virtual void operator++(int) = 0;
|
||||
virtual bool operator==(const I_Config_Iterator<ConfigurationType> &other) const = 0;
|
||||
virtual bool operator!=(const I_Config_Iterator<ConfigurationType> &other) const = 0;
|
||||
virtual std::type_index getType() const = 0;
|
||||
};
|
||||
|
||||
#endif // __I_CONFIG_ITERATOR_H__
|
85
core/include/services_sdk/resources/config/range_config.h
Normal file
85
core/include/services_sdk/resources/config/range_config.h
Normal file
@@ -0,0 +1,85 @@
|
||||
// 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 __RANGE_CONFIG_H__
|
||||
#define __RANGE_CONFIG_H___
|
||||
|
||||
#ifndef __CONFIG_H__
|
||||
#error "range_config.h should not be included directly"
|
||||
#endif // __CONFIG_H__
|
||||
|
||||
namespace Config
|
||||
{
|
||||
|
||||
template <typename ConfigurationType>
|
||||
class ConfigRange
|
||||
{
|
||||
using PerContextValue = std::vector<std::pair<std::shared_ptr<EnvironmentEvaluator<bool>>, TypeWrapper>>;
|
||||
using Iterator = PerContextValue::const_iterator;
|
||||
|
||||
class ConfigurationIter
|
||||
{
|
||||
public:
|
||||
ConfigurationIter(const Iterator &begin, const Iterator &end) : curr(begin), end_iter(end)
|
||||
{
|
||||
if (!isLegitimatePosition()) ++(*this);
|
||||
}
|
||||
|
||||
void
|
||||
operator++()
|
||||
{
|
||||
while (curr != end_iter) {
|
||||
++curr;
|
||||
if (isLegitimatePosition()) break;
|
||||
}
|
||||
}
|
||||
|
||||
const ConfigurationType & operator*() const { return curr->second.getValue<ConfigurationType>().unpack(); }
|
||||
bool operator!=(const ConfigurationIter &other) { return curr != other.curr; }
|
||||
bool operator==(const ConfigurationIter &other) { return curr == other.curr; }
|
||||
|
||||
private:
|
||||
bool
|
||||
isLegitimatePosition() const
|
||||
{
|
||||
if (curr == end_iter) return true;
|
||||
if (!checkContext()) return false;
|
||||
return curr->second.getValue<ConfigurationType>().ok();
|
||||
}
|
||||
|
||||
bool
|
||||
checkContext() const
|
||||
{
|
||||
auto &checker = curr->first;
|
||||
if (checker == nullptr) return true;
|
||||
auto res = checker->evalVariable();
|
||||
return res.ok() && *res;
|
||||
}
|
||||
|
||||
Iterator curr, end_iter;
|
||||
};
|
||||
|
||||
public:
|
||||
ConfigRange() {}
|
||||
ConfigRange(const PerContextValue &_values) : values(_values) {}
|
||||
|
||||
ConfigurationIter begin() const { return ConfigurationIter(values.begin(), values.end()); }
|
||||
ConfigurationIter end() const { return ConfigurationIter(values.end(), values.end()); }
|
||||
|
||||
private:
|
||||
PerContextValue values;
|
||||
};
|
||||
|
||||
} // namespace Config
|
||||
|
||||
#endif // __RANGE_CONFIG_H__
|
79
core/include/services_sdk/resources/config/type_wrapper.h
Normal file
79
core/include/services_sdk/resources/config/type_wrapper.h
Normal file
@@ -0,0 +1,79 @@
|
||||
// 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 __TYPE_WRAPPER_H__
|
||||
#define __TYPE_WRAPPER_H__
|
||||
|
||||
#ifndef __CONFIG_H__
|
||||
#error "type_wrapper.h should not be included directly"
|
||||
#endif // __CONFIG_H__
|
||||
|
||||
#include <typeinfo>
|
||||
#include <typeindex>
|
||||
|
||||
class TypeWrapper
|
||||
{
|
||||
class Value
|
||||
{
|
||||
public:
|
||||
virtual ~Value() {}
|
||||
virtual std::type_index getType() const = 0;
|
||||
};
|
||||
|
||||
template <typename T>
|
||||
class SpecificValue : public Value
|
||||
{
|
||||
public:
|
||||
SpecificValue(const T &_val) : val(_val) {}
|
||||
|
||||
std::type_index getType() const override { return typeid(T); }
|
||||
|
||||
const Maybe<T, Config::Errors> val;
|
||||
static Maybe<T, Config::Errors> missing_tag;
|
||||
static Maybe<T, Config::Errors> bad_node;
|
||||
};
|
||||
|
||||
public:
|
||||
TypeWrapper() {}
|
||||
|
||||
template <typename T>
|
||||
TypeWrapper(const T &val) : p_val(std::make_shared<SpecificValue<T>>(val)) {}
|
||||
|
||||
template <typename T>
|
||||
const Maybe<T, Config::Errors> &
|
||||
getValue() const
|
||||
{
|
||||
if (!p_val) return SpecificValue<T>::missing_tag;
|
||||
if (p_val->getType() != typeid(T)) return SpecificValue<T>::bad_node;
|
||||
return static_cast<SpecificValue<T> *>(p_val.get())->val;
|
||||
}
|
||||
|
||||
template <typename T>
|
||||
static const Maybe<T, Config::Errors> & failMissing() { return SpecificValue<T>::missing_tag; }
|
||||
|
||||
template <typename T>
|
||||
static const Maybe<T, Config::Errors> & failBadNode() { return SpecificValue<T>::bad_node; }
|
||||
|
||||
bool ok() { return p_val != nullptr; }
|
||||
|
||||
private:
|
||||
std::shared_ptr<Value> p_val = nullptr;
|
||||
};
|
||||
|
||||
template <typename T>
|
||||
Maybe<T, Config::Errors> TypeWrapper::SpecificValue<T>::missing_tag{genError(Config::Errors::MISSING_TAG)};
|
||||
|
||||
template <typename T>
|
||||
Maybe<T, Config::Errors> TypeWrapper::SpecificValue<T>::bad_node{genError(Config::Errors::BAD_NODE)};
|
||||
|
||||
#endif // __TYPE_WRAPPER_H__
|
114
core/include/services_sdk/resources/context.h
Normal file
114
core/include/services_sdk/resources/context.h
Normal file
@@ -0,0 +1,114 @@
|
||||
// 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 __CONTEXT_H__
|
||||
#define __CONTEXT_H__
|
||||
|
||||
#include <typeinfo>
|
||||
#include <typeindex>
|
||||
#include <string>
|
||||
#include <map>
|
||||
|
||||
#include "common.h"
|
||||
#include "singleton.h"
|
||||
#include "maybe_res.h"
|
||||
|
||||
USE_DEBUG_FLAG(D_ENVIRONMENT);
|
||||
|
||||
class I_Environment;
|
||||
|
||||
namespace EnvKeyAttr
|
||||
{
|
||||
|
||||
// All attributes should start with `NONE`, which marks that the parameter doesn't have an attribute of that type.
|
||||
// When filtering `NONE` means that we don't wish to filter by this attribute.
|
||||
|
||||
enum class LogSection { NONE, SOURCE, DATA, MARKER, SOURCEANDDATA };
|
||||
enum class Verbosity { NONE, LOW, MEDIUM, HIGH };
|
||||
|
||||
} // EnvKeyAttr
|
||||
|
||||
#include "environment/param.h"
|
||||
|
||||
class Context : Singleton::Consume<I_Environment>
|
||||
{
|
||||
public:
|
||||
enum class MetaDataType {
|
||||
File,
|
||||
SubjectIpAddr,
|
||||
OtherIpAddr,
|
||||
Port,
|
||||
Protocol,
|
||||
Service,
|
||||
User,
|
||||
Domain,
|
||||
Url,
|
||||
Direction,
|
||||
Email,
|
||||
COUNT
|
||||
};
|
||||
|
||||
enum class Error { NO_VALUE, NO_EVAL, WRONG_TYPE };
|
||||
template <typename T> using Return = Maybe<T, Error>;
|
||||
|
||||
private:
|
||||
class AbstractValue;
|
||||
|
||||
template <typename T>
|
||||
class Value;
|
||||
|
||||
class Key;
|
||||
|
||||
public:
|
||||
void activate();
|
||||
void deactivate();
|
||||
|
||||
template <typename T, typename ... Attr>
|
||||
void registerValue(const std::string &name, const T &value, Attr ... attr);
|
||||
|
||||
template <typename ... Params>
|
||||
void registerValue(MetaDataType name, Params ... params);
|
||||
|
||||
template <typename T, typename ... Attr>
|
||||
void registerFunc(const std::string &name, std::function<T()> &&func, Attr ... attr);
|
||||
|
||||
template <typename T, typename ... Attr>
|
||||
void registerFunc(const std::string &name, std::function<Return<T>()> &&func, Attr ... attr);
|
||||
|
||||
template <typename T>
|
||||
void unregisterKey(const std::string &name);
|
||||
|
||||
template <typename T>
|
||||
void unregisterKey(MetaDataType name);
|
||||
|
||||
template <typename T>
|
||||
Return<T> get(const std::string &name) const;
|
||||
|
||||
template <typename T>
|
||||
Return<T> get(MetaDataType name) const;
|
||||
|
||||
std::map<std::string, std::string> getAllStrings(const EnvKeyAttr::ParamAttr ¶m) const;
|
||||
std::map<std::string, uint64_t> getAllUints(const EnvKeyAttr::ParamAttr ¶m) const;
|
||||
std::map<std::string, bool> getAllBools(const EnvKeyAttr::ParamAttr ¶m) const;
|
||||
|
||||
static const std::string convertToString(MetaDataType type);
|
||||
|
||||
private:
|
||||
std::map<Key, std::unique_ptr<AbstractValue>> values;
|
||||
};
|
||||
|
||||
class ScopedContext;
|
||||
|
||||
#include "environment/context_impl.h"
|
||||
|
||||
#endif // __CONTEXT_H__
|
106
core/include/services_sdk/resources/cpu.h
Executable file
106
core/include/services_sdk/resources/cpu.h
Executable file
@@ -0,0 +1,106 @@
|
||||
// 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 __CPU_H__
|
||||
#define __CPU_H__
|
||||
|
||||
#include <sys/time.h>
|
||||
|
||||
#include "i_mainloop.h"
|
||||
#include "i_time_get.h"
|
||||
#include "i_environment.h"
|
||||
#include "i_cpu.h"
|
||||
#include "i_failopen.h"
|
||||
#include "cpu/failopen_mode_status.h"
|
||||
#include "cpu/cpu_metric.h"
|
||||
#include "enum_array.h"
|
||||
#include "maybe_res.h"
|
||||
#include "component.h"
|
||||
|
||||
using cpu_data_array = EnumArray<I_CPU::CPUGeneralDataEntryType, double>;
|
||||
|
||||
class CPUCalculator
|
||||
:
|
||||
public Component,
|
||||
Singleton::Provide<I_CPU>::SelfInterface,
|
||||
Singleton::Consume<I_TimeGet>
|
||||
{
|
||||
public:
|
||||
CPUCalculator();
|
||||
|
||||
void init();
|
||||
void fini();
|
||||
|
||||
double getCurrentProcessCPUUsage();
|
||||
Maybe<double> getCurrentGeneralCPUUsage();
|
||||
|
||||
private:
|
||||
std::chrono::microseconds
|
||||
calcTimeDiff(const timeval ¤t_cpu_time, const timeval &last_cpu_time) const;
|
||||
|
||||
Maybe<cpu_data_array> getGeneralCPUData();
|
||||
double GetGeneralCPUActiveTime(const cpu_data_array &cpu_data);
|
||||
|
||||
I_TimeGet *i_time_get;
|
||||
std::chrono::microseconds last_cpu_process_time;
|
||||
timeval last_cpu_usage_time_in_user_mod;
|
||||
timeval last_cpu_usage_time_in_kernel;
|
||||
|
||||
std::chrono::microseconds last_cpu_general_time;
|
||||
double last_cpu_general_time_active;
|
||||
};
|
||||
|
||||
class CPUManager
|
||||
:
|
||||
public Component,
|
||||
Singleton::Provide<I_Failopen>::SelfInterface,
|
||||
Singleton::Consume<I_CPU>,
|
||||
Singleton::Consume<I_MainLoop>,
|
||||
Singleton::Consume<I_TimeGet>,
|
||||
Singleton::Consume<I_Environment>
|
||||
{
|
||||
public:
|
||||
CPUManager() : Component("CPUManager"), cpu_process_metric(false), cpu_general_metric(true) {}
|
||||
void init();
|
||||
bool isFailOpenMode() const;
|
||||
void preload();
|
||||
|
||||
private:
|
||||
void checkCPUStatus();
|
||||
void loadCPUConfig();
|
||||
bool isCPUAboveHighWatermark(double current_cpu) const;
|
||||
bool isCPUUnderHighWatermark(double current_cpu) const;
|
||||
bool isCPUUnderLowWatermark(double current_cpu) const;
|
||||
|
||||
I_MainLoop *i_mainloop;
|
||||
I_TimeGet *i_time_get;
|
||||
I_CPU *i_cpu;
|
||||
I_Environment *i_env;
|
||||
FailopenModeEvent failopen_mode_event;
|
||||
|
||||
int failopen_counter;
|
||||
int current_counter;
|
||||
bool is_failopen_mode;
|
||||
|
||||
uint high_watermark;
|
||||
uint low_watermark;
|
||||
std::chrono::seconds watermark_period;
|
||||
std::chrono::seconds sampling_interval;
|
||||
std::chrono::seconds debug_period;
|
||||
|
||||
std::chrono::seconds metric_report_interval;
|
||||
CPUMetric cpu_process_metric;
|
||||
CPUMetric cpu_general_metric;
|
||||
};
|
||||
|
||||
#endif // __CPU_H__
|
65
core/include/services_sdk/resources/cpu/cpu_metric.h
Executable file
65
core/include/services_sdk/resources/cpu/cpu_metric.h
Executable file
@@ -0,0 +1,65 @@
|
||||
// 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 __CPU_METRIC_H__
|
||||
#define __CPU_METRIC_H__
|
||||
|
||||
#include "generic_metric.h"
|
||||
|
||||
class CPUEvent : public Event<CPUEvent>
|
||||
{
|
||||
public:
|
||||
CPUEvent() = default;
|
||||
|
||||
CPUEvent(double value, bool _is_external)
|
||||
:
|
||||
cpu_usage(value),
|
||||
is_external(_is_external)
|
||||
{}
|
||||
|
||||
double getCPU() const { return cpu_usage; }
|
||||
|
||||
bool isExternal() const { return is_external; }
|
||||
|
||||
void setCPU(double value) { cpu_usage = value; }
|
||||
|
||||
private:
|
||||
double cpu_usage = 0;
|
||||
bool is_external = false;
|
||||
};
|
||||
|
||||
class CPUMetric
|
||||
:
|
||||
public GenericMetric,
|
||||
public Listener<CPUEvent>
|
||||
{
|
||||
public:
|
||||
CPUMetric(bool _is_external = false) : is_external(_is_external) {}
|
||||
|
||||
void
|
||||
upon(const CPUEvent &event) override
|
||||
{
|
||||
if (event.isExternal() != is_external) return;
|
||||
max.report(event.getCPU());
|
||||
last_report.report(event.getCPU());
|
||||
avg.report(event.getCPU());
|
||||
}
|
||||
|
||||
private:
|
||||
MetricCalculations::Max<double> max{this, "cpuMaxSample", 0};
|
||||
MetricCalculations::Average<double> avg{this, "cpuAvgSample"};
|
||||
MetricCalculations::LastReportedValue<double> last_report{this, "cpuSample"};
|
||||
bool is_external = false;
|
||||
};
|
||||
|
||||
#endif //__CPU_METRIC_H__
|
44
core/include/services_sdk/resources/cpu/failopen_mode_status.h
Executable file
44
core/include/services_sdk/resources/cpu/failopen_mode_status.h
Executable file
@@ -0,0 +1,44 @@
|
||||
// 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 __FAILOPEN_MODE_STATUS_H__
|
||||
#define __FAILOPEN_MODE_STATUS_H__
|
||||
|
||||
#include "event.h"
|
||||
|
||||
class FailopenModeEvent : public Event<FailopenModeEvent>
|
||||
{
|
||||
public:
|
||||
FailopenModeEvent(bool _failopen_status = false)
|
||||
:
|
||||
failopen_mode_status(_failopen_status)
|
||||
{
|
||||
}
|
||||
|
||||
void
|
||||
setFailopenMode(bool status)
|
||||
{
|
||||
failopen_mode_status = status;
|
||||
}
|
||||
|
||||
bool
|
||||
getFailopenMode() const
|
||||
{
|
||||
return failopen_mode_status;
|
||||
}
|
||||
|
||||
private:
|
||||
bool failopen_mode_status;
|
||||
};
|
||||
|
||||
#endif // __FAILOPEN_MODE_STATUS_H__
|
159
core/include/services_sdk/resources/debug_flags.h
Executable file
159
core/include/services_sdk/resources/debug_flags.h
Executable file
@@ -0,0 +1,159 @@
|
||||
// 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.
|
||||
|
||||
#ifdef DEFINE_FLAG
|
||||
|
||||
DEFINE_FLAG(D_INFRA, D_ALL)
|
||||
DEFINE_FLAG(D_EXTERNAL_SDK, D_INFRA)
|
||||
DEFINE_FLAG(D_EXTERNAL_SDK_USER, D_INFRA)
|
||||
DEFINE_FLAG(D_EXTERNAL_SDK_SERVER, D_INFRA)
|
||||
DEFINE_FLAG(D_INFRA_API, D_INFRA)
|
||||
DEFINE_FLAG(D_INFRA_UTILS, D_INFRA)
|
||||
DEFINE_FLAG(D_COMPRESSION, D_INFRA)
|
||||
DEFINE_FLAG(D_SHMEM, D_INFRA)
|
||||
DEFINE_FLAG(D_CONFIG, D_INFRA)
|
||||
DEFINE_FLAG(D_ENVIRONMENT, D_INFRA)
|
||||
DEFINE_FLAG(D_INTELLIGENCE, D_INFRA)
|
||||
DEFINE_FLAG(D_RULEBASE_CONFIG, D_INFRA)
|
||||
DEFINE_FLAG(D_DEBUG_FOG, D_INFRA)
|
||||
DEFINE_FLAG(D_METRICS, D_INFRA)
|
||||
DEFINE_FLAG(D_METRICS_HTTP_MANAGER, D_METRICS)
|
||||
DEFINE_FLAG(D_METRICS_NGINX_ATTACHMENT, D_METRICS)
|
||||
DEFINE_FLAG(D_METRICS_ACCESS_CONTROL, D_METRICS)
|
||||
DEFINE_FLAG(D_MAINLOOP, D_INFRA)
|
||||
DEFINE_FLAG(D_SIGNAL_HANDLER, D_INFRA)
|
||||
DEFINE_FLAG(D_MONITORING, D_INFRA)
|
||||
DEFINE_FLAG(D_HEALTH_CHECK_MANAGER, D_INFRA)
|
||||
DEFINE_FLAG(D_REPORT, D_INFRA)
|
||||
DEFINE_FLAG(D_REPORT_BULK, D_REPORT)
|
||||
DEFINE_FLAG(D_TRACE, D_INFRA)
|
||||
DEFINE_FLAG(D_COMP_IS, D_INFRA)
|
||||
DEFINE_FLAG(D_COMMUNICATION, D_INFRA)
|
||||
DEFINE_FLAG(D_API, D_COMMUNICATION)
|
||||
DEFINE_FLAG(D_SOCKET, D_COMMUNICATION)
|
||||
DEFINE_FLAG(D_SYNC, D_COMMUNICATION)
|
||||
DEFINE_FLAG(D_UPGRADE, D_SYNC)
|
||||
DEFINE_FLAG(D_EVENT_BUFFER, D_COMMUNICATION)
|
||||
DEFINE_FLAG(D_HTTP_REQUEST, D_COMMUNICATION)
|
||||
|
||||
DEFINE_FLAG(D_COMPONENT, D_ALL)
|
||||
DEFINE_FLAG(D_PRELOAD, D_COMPONENT)
|
||||
DEFINE_FLAG(D_PENDING, D_COMPONENT)
|
||||
|
||||
DEFINE_FLAG(D_KERNEL_APP, D_COMPONENT)
|
||||
DEFINE_FLAG(D_KERNEL_MESSAGE_READER, D_KERNEL_APP)
|
||||
DEFINE_FLAG(D_MESSAGE_READER, D_KERNEL_APP)
|
||||
|
||||
DEFINE_FLAG(D_TABLE, D_COMPONENT)
|
||||
DEFINE_FLAG(D_STREAMING, D_COMPONENT)
|
||||
DEFINE_FLAG(D_STREAMING_DATA, D_STREAMING)
|
||||
DEFINE_FLAG(D_CHECKSUM, D_STREAMING)
|
||||
DEFINE_FLAG(D_WAAP, D_COMPONENT)
|
||||
DEFINE_FLAG(D_WAAP_API, D_WAAP)
|
||||
DEFINE_FLAG(D_WAAP_AUTOMATION, D_WAAP)
|
||||
DEFINE_FLAG(D_WAAP_REGEX, D_WAAP)
|
||||
DEFINE_FLAG(D_WAAP_SAMPLE_PREPROCESS, D_WAAP)
|
||||
DEFINE_FLAG(D_WAAP_SAMPLE_SCAN, D_WAAP)
|
||||
DEFINE_FLAG(D_WAAP_EVASIONS, D_WAAP)
|
||||
DEFINE_FLAG(D_WAAP_ASSET_STATE, D_WAAP)
|
||||
DEFINE_FLAG(D_WAAP_CONFIDENCE_CALCULATOR, D_WAAP)
|
||||
DEFINE_FLAG(D_WAAP_REPUTATION, D_WAAP)
|
||||
DEFINE_FLAG(D_WAAP_SCORE_BUILDER, D_WAAP)
|
||||
DEFINE_FLAG(D_WAAP_ULIMITS, D_WAAP)
|
||||
DEFINE_FLAG(D_WAAP_SCANNER, D_WAAP)
|
||||
DEFINE_FLAG(D_WAAP_DEEP_PARSER, D_WAAP)
|
||||
DEFINE_FLAG(D_WAAP_BOT_PROTECTION, D_WAAP)
|
||||
DEFINE_FLAG(D_WAAP_PARSER, D_WAAP)
|
||||
DEFINE_FLAG(D_WAAP_PARSER_XML, D_WAAP_PARSER)
|
||||
DEFINE_FLAG(D_WAAP_PARSER_HTML, D_WAAP_PARSER)
|
||||
DEFINE_FLAG(D_WAAP_PARSER_BINARY, D_WAAP_PARSER)
|
||||
DEFINE_FLAG(D_WAAP_PARSER_CONTENT_TYPE, D_WAAP_PARSER)
|
||||
DEFINE_FLAG(D_WAAP_PARSER_CONFLUENCE, D_WAAP_PARSER)
|
||||
DEFINE_FLAG(D_WAAP_PARSER_DELIMITER, D_WAAP_PARSER)
|
||||
DEFINE_FLAG(D_WAAP_PARSER_HDRVALUE, D_WAAP_PARSER)
|
||||
DEFINE_FLAG(D_WAAP_PARSER_JSON, D_WAAP_PARSER)
|
||||
DEFINE_FLAG(D_WAAP_PARSER_MULTIPART_FORM, D_WAAP_PARSER)
|
||||
DEFINE_FLAG(D_WAAP_PARSER_RAW, D_WAAP_PARSER)
|
||||
DEFINE_FLAG(D_WAAP_PARSER_URLENCODE, D_WAAP_PARSER)
|
||||
DEFINE_FLAG(D_WAAP_PARSER_PHPSERIALIZE, D_WAAP_PARSER)
|
||||
DEFINE_FLAG(D_WAAP_OVERRIDE, D_WAAP)
|
||||
|
||||
DEFINE_FLAG(D_IPS, D_COMPONENT)
|
||||
DEFINE_FLAG(D_FILE_UPLOAD, D_COMPONENT)
|
||||
|
||||
DEFINE_FLAG(D_PARSER, D_COMPONENT)
|
||||
DEFINE_FLAG(D_WS, D_COMPONENT)
|
||||
DEFINE_FLAG(D_CMI, D_COMPONENT)
|
||||
DEFINE_FLAG(D_KEYWORD, D_CMI)
|
||||
DEFINE_FLAG(D_PM, D_CMI)
|
||||
DEFINE_FLAG(D_PM_COMP, D_PM)
|
||||
DEFINE_FLAG(D_PM_EXEC, D_PM)
|
||||
|
||||
DEFINE_FLAG(D_FW, D_COMPONENT)
|
||||
DEFINE_FLAG(D_STATELESS_CHECKS, D_FW)
|
||||
DEFINE_FLAG(D_FRAGMENTATION_HANDLER, D_FW)
|
||||
DEFINE_FLAG(D_POLICY, D_FW)
|
||||
DEFINE_FLAG(D_NSAAS, D_FW)
|
||||
DEFINE_FLAG(D_POLICY_MATCHER, D_FW)
|
||||
|
||||
DEFINE_FLAG(D_PACKET, D_COMPONENT)
|
||||
DEFINE_FLAG(D_PKTCAP, D_COMPONENT)
|
||||
DEFINE_FLAG(D_THROUGHPUT, D_COMPONENT)
|
||||
DEFINE_FLAG(D_ASSET_RESOLVER, D_COMPONENT)
|
||||
DEFINE_FLAG(D_ASSET_REPORTER, D_COMPONENT)
|
||||
|
||||
DEFINE_FLAG(D_HTTP_SECURITY_APP, D_COMPONENT)
|
||||
DEFINE_FLAG(D_HTTP_MANAGER, D_COMPONENT)
|
||||
|
||||
DEFINE_FLAG(D_ORCHESTRATOR, D_COMPONENT)
|
||||
DEFINE_FLAG(D_HEALTH_CHECK, D_ORCHESTRATOR)
|
||||
DEFINE_FLAG(D_AGENT_DETAILS, D_ORCHESTRATOR)
|
||||
DEFINE_FLAG(D_K8S_POLICY, D_ORCHESTRATOR)
|
||||
|
||||
DEFINE_FLAG(D_GRADUAL_DEPLOYMENT, D_COMPONENT)
|
||||
DEFINE_FLAG(D_C8_CONTROLLER, D_COMPONENT)
|
||||
DEFINE_FLAG(D_SDWAN, D_COMPONENT)
|
||||
DEFINE_FLAG(D_SDWAN_POLICY, D_SDWAN)
|
||||
DEFINE_FLAG(D_SDWAN_DATA, D_SDWAN)
|
||||
DEFINE_FLAG(D_SDWAN_LOGGER, D_SDWAN)
|
||||
DEFINE_FLAG(D_REVERSE_PROXY, D_COMPONENT)
|
||||
DEFINE_FLAG(D_PLATFORM, D_REVERSE_PROXY)
|
||||
DEFINE_FLAG(D_NGINX_MESSAGE_READER, D_REVERSE_PROXY)
|
||||
DEFINE_FLAG(D_ERROR_REPORTER, D_REVERSE_PROXY)
|
||||
DEFINE_FLAG(D_UPSTREAM_KEEPALIVE, D_REVERSE_PROXY)
|
||||
|
||||
DEFINE_FLAG(D_IOT_NEXT, D_COMPONENT)
|
||||
DEFINE_FLAG(D_IOT_ENFORCE, D_IOT_NEXT)
|
||||
DEFINE_FLAG(D_IOT_DISCOVERY, D_IOT_NEXT)
|
||||
DEFINE_FLAG(D_UTILS, D_IOT_DISCOVERY)
|
||||
DEFINE_FLAG(D_IOT_INTEGRATION_STATUS, D_UTILS)
|
||||
DEFINE_FLAG(D_ASSETS_DATA_COLLECTOR, D_UTILS)
|
||||
DEFINE_FLAG(D_ASSETS_DATA_REPORTER, D_UTILS)
|
||||
DEFINE_FLAG(D_ASSETS_DATA_PARSER, D_UTILS)
|
||||
DEFINE_FLAG(D_IOT_INTEGRATION_SETTINGS, D_UTILS)
|
||||
DEFINE_FLAG(D_IOT_INTEGRATION_MANAGER, D_UTILS)
|
||||
DEFINE_FLAG(D_ASSETS_PROBE, D_UTILS)
|
||||
DEFINE_FLAG(D_HTTP_EVENT_RECORD, D_COMPONENT)
|
||||
DEFINE_FLAG(D_GEO_DB, D_COMPONENT)
|
||||
DEFINE_FLAG(D_CPVIEW_METRIC_PROVIDER, D_COMPONENT)
|
||||
DEFINE_FLAG(D_GEO_FILTER, D_COMPONENT)
|
||||
|
||||
DEFINE_FLAG(D_FLOW, D_ALL)
|
||||
DEFINE_FLAG(D_DROP, D_FLOW)
|
||||
DEFINE_FLAG(D_ATTACHMENT, D_FLOW)
|
||||
DEFINE_FLAG(D_ATTACHMENT_REGISTRATION, D_ATTACHMENT)
|
||||
DEFINE_FLAG(D_NGINX_ATTACHMENT, D_ATTACHMENT)
|
||||
DEFINE_FLAG(D_NGINX_ATTACHMENT_PARSER, D_NGINX_ATTACHMENT)
|
||||
DEFINE_FLAG(D_WLP_ATTACHMENT, D_ATTACHMENT)
|
||||
|
||||
#endif // DEFINE_FLAG
|
@@ -0,0 +1,82 @@
|
||||
// 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 __BASE_EVALUATORS_H__
|
||||
#define __BASE_EVALUATORS_H__
|
||||
|
||||
// This file is only supposed to be included from "environment_evaluator.h", so this is simply a safeguard.
|
||||
#ifndef __ENVIRONMENT_EVALUATOR_H__
|
||||
#error "environment/evaluators_repo.h should not be included directly"
|
||||
#endif // __ENVIRONMENT_EVALUATOR_H__
|
||||
|
||||
#include "i_environment.h"
|
||||
#include "environment.h"
|
||||
|
||||
namespace EnvironmentHelper
|
||||
{
|
||||
|
||||
template <typename Value>
|
||||
class GetEvaluator : public EnvironmentEvaluator<Value>
|
||||
{
|
||||
public:
|
||||
GetEvaluator(const std::vector<std::string> ¶ms)
|
||||
{
|
||||
if (params.size() != 1) reportWrongNumberOfParams("Get", params.size(), 1, 1);
|
||||
name = params[0];
|
||||
}
|
||||
|
||||
Maybe<Value, Context::Error>
|
||||
evalVariable() const override
|
||||
{
|
||||
return Singleton::Consume<I_Environment>::from<Environment>()->get<Value>(name);
|
||||
}
|
||||
|
||||
static std::string getName() { return "Get"; }
|
||||
|
||||
private:
|
||||
std::string name;
|
||||
};
|
||||
|
||||
template <typename Value>
|
||||
class SelectEvaluator : public EnvironmentEvaluator<Value>
|
||||
{
|
||||
public:
|
||||
SelectEvaluator(const std::vector<std::string> ¶ms)
|
||||
{
|
||||
if (params.size() < 2) reportWrongNumberOfParams("Select", params.size(), 2);
|
||||
auto ptr = EvaluatorsRepo<Value>::getRepo();
|
||||
for (const auto ¶m : params) {
|
||||
vars.push_back(ptr->getMatcher(param));
|
||||
}
|
||||
}
|
||||
|
||||
Maybe<Value, Context::Error>
|
||||
evalVariable() const override
|
||||
{
|
||||
for (const auto &var : vars) {
|
||||
auto value = var->evalVariable();
|
||||
if (value.ok()) return value;
|
||||
}
|
||||
|
||||
return genError(Context::Error::NO_EVAL);
|
||||
}
|
||||
|
||||
static std::string getName() { return "Select"; }
|
||||
|
||||
private:
|
||||
std::vector<EvaluatorPtr<Value>> vars;
|
||||
};
|
||||
|
||||
} // EnvironmentHelper
|
||||
|
||||
#endif // __BASE_EVALUATORS_H__
|
175
core/include/services_sdk/resources/environment/context_impl.h
Normal file
175
core/include/services_sdk/resources/environment/context_impl.h
Normal file
@@ -0,0 +1,175 @@
|
||||
// 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 __CONTEXT_H__
|
||||
#error "context_impl.h should not be included directly"
|
||||
#endif // __CONTEXT_H__
|
||||
|
||||
#include <limits>
|
||||
#include <sstream>
|
||||
|
||||
#include "debug.h"
|
||||
|
||||
USE_DEBUG_FLAG(D_ENVIRONMENT);
|
||||
|
||||
class Context::AbstractValue
|
||||
{
|
||||
public:
|
||||
virtual ~AbstractValue() {}
|
||||
virtual Return<uint64_t> getUint() const = 0;
|
||||
virtual Return<bool> getBool() const = 0;
|
||||
virtual Return<std::string> getString() const = 0;
|
||||
};
|
||||
|
||||
template <typename T>
|
||||
class Context::Value : public Context::AbstractValue
|
||||
{
|
||||
template <bool B> class MatchCond {};
|
||||
|
||||
public:
|
||||
Value(std::function<Return<T>()> &&f) : value_getter(std::move(f)) {}
|
||||
|
||||
Return<T> get() const { return value_getter(); }
|
||||
|
||||
Return<std::string> getString() const override { return getString(MatchCond<isString()>()); }
|
||||
Return<bool> getBool() const override { return getBool(MatchCond<isBool()>()); }
|
||||
Return<uint64_t> getUint() const override { return getUint(MatchCond<isUint()>()); }
|
||||
|
||||
private:
|
||||
static constexpr bool isUint() { return std::numeric_limits<T>::is_integer && !std::is_same<T, bool>::value; }
|
||||
Return<uint64_t> getUint(MatchCond<false>) const { return genError(Error::WRONG_TYPE); }
|
||||
Return<uint64_t> getUint(MatchCond<true>) const { return get(); }
|
||||
|
||||
static constexpr bool isBool() { return std::is_same<T, bool>::value; }
|
||||
Return<bool> getBool(MatchCond<false>) const { return genError(Error::WRONG_TYPE); }
|
||||
Return<bool> getBool(MatchCond<true>) const { return get(); }
|
||||
|
||||
static constexpr bool isString() { return std::IsPrintable<T>() && !std::numeric_limits<T>::is_integer; }
|
||||
Return<std::string> getString(MatchCond<false>) const { return genError(Error::WRONG_TYPE); }
|
||||
|
||||
Return<std::string>
|
||||
getString(MatchCond<true>) const
|
||||
{
|
||||
auto val = get();
|
||||
if (!val.ok()) return val.passErr();
|
||||
|
||||
return getString(MatchCond<std::is_convertible<T, std::string>::value>(), *val);
|
||||
}
|
||||
|
||||
std::string
|
||||
getString(MatchCond<true>, const T &val) const
|
||||
{
|
||||
return static_cast<std::string>(val);
|
||||
}
|
||||
|
||||
std::string
|
||||
getString(MatchCond<false>, const T &val) const
|
||||
{
|
||||
std::stringstream output;
|
||||
output << val;
|
||||
return output.str();
|
||||
}
|
||||
|
||||
std::function<Return<T>()> value_getter;
|
||||
};
|
||||
|
||||
class Context::Key : public std::pair<std::string, std::type_index>
|
||||
{
|
||||
public:
|
||||
Key(const std::string &name, const std::type_index &type) : Key(name, type, EnvKeyAttr::ParamAttr()) {}
|
||||
|
||||
Key(const std::string &name, const std::type_index &type, const EnvKeyAttr::ParamAttr &_params)
|
||||
:
|
||||
std::pair<std::string, std::type_index>(name, type),
|
||||
params(_params)
|
||||
{
|
||||
}
|
||||
|
||||
bool doesMatch(const EnvKeyAttr::ParamAttr ¶m) const { return params.doesMatch(param); }
|
||||
|
||||
private:
|
||||
EnvKeyAttr::ParamAttr params;
|
||||
};
|
||||
|
||||
template <typename T, typename ... Attr>
|
||||
void
|
||||
Context::registerValue(const std::string &name, const T &value, Attr ... attr)
|
||||
{
|
||||
std::function<Return<T>()> new_func = [value] () { return Return<T>(value); };
|
||||
registerFunc(name, std::move(new_func), attr ...);
|
||||
}
|
||||
|
||||
template <typename ... Params>
|
||||
void
|
||||
Context::registerValue(MetaDataType name, Params ... params)
|
||||
{
|
||||
return registerValue(convertToString(name), params ...);
|
||||
}
|
||||
|
||||
template <typename T, typename ... Attr>
|
||||
void
|
||||
Context::registerFunc(const std::string &name, std::function<T()> &&func, Attr ... attr)
|
||||
{
|
||||
std::function<Return<T>()> new_func = [func] () { return Return<T>(func()); };
|
||||
registerFunc(name, std::move(new_func), attr ...);
|
||||
}
|
||||
|
||||
template <typename T, typename ... Attr>
|
||||
void
|
||||
Context::registerFunc(const std::string &name, std::function<Return<T>()> &&func, Attr ... attr)
|
||||
{
|
||||
dbgTrace(D_ENVIRONMENT) << "Registering key : " << name;
|
||||
Key key(name, typeid(T), EnvKeyAttr::ParamAttr(attr ...));
|
||||
values[key] = std::make_unique<Value<T>>(std::move(func));
|
||||
}
|
||||
|
||||
template <typename T>
|
||||
void
|
||||
Context::unregisterKey(const std::string &name)
|
||||
{
|
||||
dbgTrace(D_ENVIRONMENT) << "Unregistering key : " << name;
|
||||
Key key(name, typeid(T));
|
||||
values.erase(key);
|
||||
}
|
||||
|
||||
template <typename T>
|
||||
void
|
||||
Context::unregisterKey(MetaDataType name)
|
||||
{
|
||||
unregisterKey<T>(convertToString(name));
|
||||
}
|
||||
|
||||
template <typename T>
|
||||
Context::Return<T>
|
||||
Context::get(const std::string &name) const
|
||||
{
|
||||
Key key(name, typeid(T));
|
||||
auto iter = values.find(key);
|
||||
if (iter == values.end()) return genError(Error::NO_VALUE);
|
||||
Value<T> *val = dynamic_cast<Value<T> *>(iter->second.get());
|
||||
return val->get();
|
||||
}
|
||||
|
||||
template <typename T>
|
||||
Context::Return<T>
|
||||
Context::get(MetaDataType name) const
|
||||
{
|
||||
return get<T>(convertToString(name));
|
||||
}
|
||||
|
||||
class ScopedContext : public Context
|
||||
{
|
||||
public:
|
||||
ScopedContext();
|
||||
~ScopedContext();
|
||||
};
|
@@ -0,0 +1,102 @@
|
||||
// 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 __EVALUATOR_TEMPLATES_H__
|
||||
#define __EVALUATOR_TEMPLATES_H__
|
||||
|
||||
#include "environment_evaluator.h"
|
||||
|
||||
namespace EnvironmentHelper
|
||||
{
|
||||
|
||||
template <typename Value>
|
||||
class Constant : public EnvironmentEvaluator<Value>
|
||||
{
|
||||
using Method = Value(*)(const std::string &);
|
||||
public:
|
||||
Constant(Method parse, const std::vector<std::string> ¶ms)
|
||||
{
|
||||
if (params.size() != 1) reportWrongNumberOfParams(getName(), params.size(), 1, 1);
|
||||
value = parse(params[0]);
|
||||
}
|
||||
|
||||
Maybe<Value, Context::Error>
|
||||
evalVariable() const override
|
||||
{
|
||||
return value;
|
||||
}
|
||||
|
||||
static std::string getName() { return "Constant"; }
|
||||
|
||||
private:
|
||||
Value value;
|
||||
};
|
||||
|
||||
template <typename Value>
|
||||
class Equal : public EnvironmentEvaluator<bool>
|
||||
{
|
||||
public:
|
||||
Equal(const std::vector<std::string> ¶ms)
|
||||
{
|
||||
if (params.size() != 2) reportWrongNumberOfParams(getName(), params.size(), 2, 2);
|
||||
auto repo = EvaluatorsRepo<Value>::getRepo();
|
||||
one = repo->getMatcher(params[0]);
|
||||
two = repo->getMatcher(params[1]);
|
||||
}
|
||||
|
||||
Maybe<bool, Context::Error>
|
||||
evalVariable() const override
|
||||
{
|
||||
auto res1 = one->evalVariable();
|
||||
if (!res1.ok()) return res1.passErr();
|
||||
auto res2 = two->evalVariable();
|
||||
if (!res2.ok()) return res2.passErr();
|
||||
return *res1 == *res2;
|
||||
}
|
||||
|
||||
static std::string getName() { return "Equal"; }
|
||||
|
||||
private:
|
||||
EvaluatorPtr<Value> one, two;
|
||||
};
|
||||
|
||||
template <typename Value, typename T>
|
||||
class Invoker : public EnvironmentEvaluator<Value>
|
||||
{
|
||||
using Method = Value(*)(const T &);
|
||||
public:
|
||||
Invoker(Method _method, const std::vector<std::string> ¶ms) : method(_method)
|
||||
{
|
||||
if (params.size() != 1) reportWrongNumberOfParams(getName(), params.size(), 1, 1);
|
||||
auto repo = EvaluatorsRepo<T>::getRepo();
|
||||
instance = repo->getMatcher(params[0]);
|
||||
}
|
||||
|
||||
Maybe<Value, Context::Error>
|
||||
evalVariable() const override
|
||||
{
|
||||
auto res = instance->evalVariable();
|
||||
if (!res.ok()) return res.passErr();
|
||||
return method(res.unpack());
|
||||
}
|
||||
|
||||
static std::string getName() { return "Invoker"; }
|
||||
|
||||
private:
|
||||
Method method;
|
||||
EvaluatorPtr<T> instance;
|
||||
};
|
||||
|
||||
} // namespace EnvironmentHelper
|
||||
|
||||
#endif // __EVALUATOR_TEMPLATES_H__
|
@@ -0,0 +1,107 @@
|
||||
// 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 __EVALUATORS_REPO_H__
|
||||
#define __EVALUATORS_REPO_H__
|
||||
|
||||
#include <map>
|
||||
#include <vector>
|
||||
#include <string>
|
||||
#include <functional>
|
||||
#include "singleton.h"
|
||||
#include "debug.h"
|
||||
|
||||
USE_DEBUG_FLAG(D_ENVIRONMENT);
|
||||
|
||||
// This file is only supposed to be included from "environment_evaluator.h", so this is simply a safeguard.
|
||||
#ifndef __ENVIRONMENT_EVALUATOR_H__
|
||||
#error "environment/evaluators_repo.h should not be included directly"
|
||||
#endif // __ENVIRONMENT_EVALUATOR_H__
|
||||
|
||||
namespace EnvironmentHelper
|
||||
{
|
||||
|
||||
template <typename Value> using EvaluatorPtr = std::unique_ptr<EnvironmentEvaluator<Value>>;
|
||||
|
||||
template <typename Value>
|
||||
class EvaluatorsRepo : public Singleton::OwnedSingleton
|
||||
{
|
||||
using Constructor = std::function<EvaluatorPtr<Value>(const std::vector<std::string> &)>;
|
||||
public:
|
||||
EvaluatorsRepo();
|
||||
|
||||
template <typename Matcher>
|
||||
bool addMatcher();
|
||||
|
||||
EvaluatorPtr<Value> getMatcher(const std::string &str);
|
||||
|
||||
static EvaluatorsRepo * getRepo();
|
||||
|
||||
private:
|
||||
std::map<std::string, Constructor> constructors;
|
||||
};
|
||||
|
||||
} // EnvironmentHelper
|
||||
|
||||
#include "environment/parsing_functions.h"
|
||||
#include "environment/base_evaluators.h"
|
||||
|
||||
template <typename Value>
|
||||
EnvironmentHelper::EvaluatorsRepo<Value>::EvaluatorsRepo()
|
||||
{
|
||||
addMatcher<GetEvaluator<Value>>();
|
||||
addMatcher<SelectEvaluator<Value>>();
|
||||
}
|
||||
|
||||
template <typename Value>
|
||||
template <typename Matcher>
|
||||
bool
|
||||
EnvironmentHelper::EvaluatorsRepo<Value>::addMatcher()
|
||||
{
|
||||
if (constructors.find(Matcher::getName()) != constructors.end()) {
|
||||
dbgTrace(D_ENVIRONMENT) << "Matcher was already added. Matcher: " << Matcher::getName();
|
||||
return false;
|
||||
}
|
||||
Constructor func = [] (const std::vector<std::string> ¶ms) { return std::make_unique<Matcher>(params); };
|
||||
constructors[Matcher::getName()] = func;
|
||||
dbgTrace(D_ENVIRONMENT) << "Matcher was added successfully. Matcher: " << Matcher::getName();
|
||||
return true;
|
||||
}
|
||||
|
||||
template <typename Value>
|
||||
EnvironmentHelper::EvaluatorPtr<Value>
|
||||
EnvironmentHelper::EvaluatorsRepo<Value>::getMatcher(const std::string &str)
|
||||
{
|
||||
auto matcher = breakEvaluatorString(str);
|
||||
auto iter = constructors.find(matcher.first);
|
||||
if (iter == constructors.end()) {
|
||||
dbgTrace(D_ENVIRONMENT) << "Matcher was not found. Matcher: " << matcher.first;
|
||||
reportUnknownEvaluatorType(matcher.first);
|
||||
}
|
||||
dbgTrace(D_ENVIRONMENT) << "Matcher was found. Matcher: " << matcher.first;
|
||||
return iter->second(matcher.second);
|
||||
}
|
||||
|
||||
template <typename Value>
|
||||
EnvironmentHelper::EvaluatorsRepo<Value> *
|
||||
EnvironmentHelper::EvaluatorsRepo<Value>::getRepo()
|
||||
{
|
||||
using Repo = EnvironmentHelper::EvaluatorsRepo<Value>;
|
||||
|
||||
if (!Singleton::existsOwned<Repo>()) {
|
||||
Singleton::newOwned<Repo>();
|
||||
}
|
||||
return Singleton::getOwned<Repo>();
|
||||
}
|
||||
|
||||
#endif // __EVALUATORS_REPO_H__
|
50
core/include/services_sdk/resources/environment/param.h
Normal file
50
core/include/services_sdk/resources/environment/param.h
Normal file
@@ -0,0 +1,50 @@
|
||||
// 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 __CONTEXT_H__
|
||||
#error "param.h should not be included directly"
|
||||
#endif // __CONTEXT_H__
|
||||
|
||||
namespace EnvKeyAttr
|
||||
{
|
||||
|
||||
class ParamAttr
|
||||
{
|
||||
public:
|
||||
ParamAttr() {}
|
||||
|
||||
template <typename ... Attr>
|
||||
ParamAttr(Attr ... attr)
|
||||
{
|
||||
setAttr(attr...);
|
||||
}
|
||||
|
||||
bool doesMatch(const ParamAttr ¶m) const;
|
||||
|
||||
private:
|
||||
template <typename Attr, typename ... MoreAttr>
|
||||
void
|
||||
setAttr(Attr attr, MoreAttr ... more_attr)
|
||||
{
|
||||
setAttr(attr);
|
||||
setAttr(more_attr...);
|
||||
}
|
||||
|
||||
void setAttr(const LogSection §ion) { log_section = section; }
|
||||
void setAttr(const Verbosity &level) { verbosity_level = level; }
|
||||
|
||||
LogSection log_section = LogSection::NONE;
|
||||
Verbosity verbosity_level = Verbosity::NONE;
|
||||
};
|
||||
|
||||
} // EnvKeyAttr
|
@@ -0,0 +1,77 @@
|
||||
// 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 __PARSING_FUNCTIONS_H__
|
||||
#define __PARSING_FUNCTIONS_H__
|
||||
|
||||
namespace EnvironmentHelper
|
||||
{
|
||||
|
||||
// The EvaluatorParseError is the exception class for the evaluator parsing process.
|
||||
class EvaluatorParseError
|
||||
{
|
||||
public:
|
||||
EvaluatorParseError(const std::string &_str) : str(_str) {}
|
||||
const std::string & getError() const { return str; }
|
||||
|
||||
private:
|
||||
std::string str;
|
||||
};
|
||||
|
||||
// The EvaluatorWrapper is used to bypass the fact that lambda expressions can't capture std::unique_ptr.
|
||||
template <typename Value>
|
||||
class EvaluatorWrapper
|
||||
{
|
||||
public:
|
||||
EvaluatorWrapper(EvaluatorPtr<Value> &&_ptr) : ptr(std::move(_ptr)) {}
|
||||
EvaluatorWrapper(const EvaluatorWrapper &other)
|
||||
{
|
||||
auto p_other = const_cast<EvaluatorWrapper *>(&other);
|
||||
ptr = std::move(p_other->ptr);
|
||||
}
|
||||
|
||||
Maybe<Value, Context::Error>
|
||||
evalVariable() const
|
||||
{
|
||||
auto res = ptr->evalVariable();
|
||||
// The lack of value during evaluation results in no evaluation, so change the error accordingly.
|
||||
if (!res.ok() && res.getErr()==Context::Error::NO_VALUE) return genError(Context::Error::NO_EVAL);
|
||||
return res;
|
||||
}
|
||||
|
||||
private:
|
||||
EvaluatorPtr<Value> ptr;
|
||||
};
|
||||
|
||||
std::pair<std::string, std::vector<std::string>> breakEvaluatorString(const std::string &str);
|
||||
|
||||
template <typename Value>
|
||||
Maybe<std::function<Maybe<Value, Context::Error>()>>
|
||||
genEvaluator(const std::string &str)
|
||||
{
|
||||
EvaluatorPtr<Value> res;
|
||||
try {
|
||||
res = EvaluatorsRepo<Value>::getRepo()->getMatcher(str);
|
||||
} catch (const EvaluatorParseError &e) {
|
||||
return genError(e.getError());
|
||||
}
|
||||
|
||||
EvaluatorWrapper<Value> wrapper(std::move(res));
|
||||
std::function<Maybe<Value, Context::Error>()> func = [wrapper] () { return wrapper.evalVariable(); };
|
||||
|
||||
return func;
|
||||
}
|
||||
|
||||
} // EnvironmentHelper
|
||||
|
||||
#endif // __PARSING_FUNCTIONS_H__
|
66
core/include/services_sdk/resources/environment/span.h
Executable file
66
core/include/services_sdk/resources/environment/span.h
Executable file
@@ -0,0 +1,66 @@
|
||||
// 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 __SPAN_H__
|
||||
#define __SPAN_H__
|
||||
|
||||
#include <string>
|
||||
#include "context.h"
|
||||
|
||||
class Span
|
||||
{
|
||||
public:
|
||||
|
||||
enum class ContextType
|
||||
{
|
||||
NEW,
|
||||
CHILD_OF,
|
||||
FOLLOWS_FROM
|
||||
};
|
||||
|
||||
std::string
|
||||
convertSpanContextTypeToString(ContextType type);
|
||||
|
||||
Span(std::string _trace_id, ContextType _type = ContextType::NEW, std::string _prev_span = std::string());
|
||||
~Span();
|
||||
|
||||
std::string getTraceId() const;
|
||||
std::string getSpanId() const;
|
||||
ContextType getSpanContextType() const;
|
||||
std::string getPrevSpanId() const;
|
||||
|
||||
private:
|
||||
std::string trace_id;
|
||||
std::string span_id;
|
||||
ContextType context_type;
|
||||
std::string prev_span_id;
|
||||
Context context;
|
||||
};
|
||||
|
||||
class SpanWrapper
|
||||
{
|
||||
public:
|
||||
SpanWrapper(
|
||||
std::string _trace_id,
|
||||
Span::ContextType _type = Span::ContextType::NEW,
|
||||
std::string _prev_span = std::string()
|
||||
);
|
||||
std::string getTraceId() const;
|
||||
std::string getSpanId() const;
|
||||
Span::ContextType getSpanContextType() const;
|
||||
std::string getPrevSpanId() const;
|
||||
|
||||
private:
|
||||
std::shared_ptr<Span> span;
|
||||
};
|
||||
#endif // __SPAN_H__
|
43
core/include/services_sdk/resources/environment/trace.h
Executable file
43
core/include/services_sdk/resources/environment/trace.h
Executable file
@@ -0,0 +1,43 @@
|
||||
// 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 __TRACE_H__
|
||||
#define __TRACE_H__
|
||||
|
||||
#include <string>
|
||||
|
||||
#include "context.h"
|
||||
|
||||
class Trace
|
||||
{
|
||||
public:
|
||||
Trace(std::string _id = std::string());
|
||||
~Trace();
|
||||
|
||||
std::string getTraceId() const;
|
||||
|
||||
private:
|
||||
std::string trace_id;
|
||||
Context context;
|
||||
};
|
||||
|
||||
class TraceWrapper
|
||||
{
|
||||
public:
|
||||
TraceWrapper(std::string _id);
|
||||
std::string getTraceId() const;
|
||||
|
||||
private:
|
||||
std::shared_ptr<Trace> trace;
|
||||
};
|
||||
#endif // __TRACE_H__
|
83
core/include/services_sdk/resources/environment/tracing_metric.h
Executable file
83
core/include/services_sdk/resources/environment/tracing_metric.h
Executable file
@@ -0,0 +1,83 @@
|
||||
// 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 __TRACING_METRIC_H__
|
||||
#define __TRACING_METRIC_H__
|
||||
|
||||
#include "generic_metric.h"
|
||||
|
||||
class TraceEvent : public Event<TraceEvent>
|
||||
{
|
||||
public:
|
||||
void
|
||||
setTraceAmount(uint64_t value)
|
||||
{
|
||||
traces = value;
|
||||
}
|
||||
|
||||
uint64_t
|
||||
getTraceAmount() const
|
||||
{
|
||||
return traces;
|
||||
}
|
||||
|
||||
private:
|
||||
uint64_t traces = 0;
|
||||
};
|
||||
|
||||
class TraceFinishEvent : public Event<TraceFinishEvent>
|
||||
{
|
||||
public:
|
||||
void
|
||||
setSpanAmount(uint64_t value)
|
||||
{
|
||||
spans_per_trace = value;
|
||||
}
|
||||
|
||||
uint64_t
|
||||
getSpanAmount() const
|
||||
{
|
||||
return spans_per_trace;
|
||||
}
|
||||
|
||||
private:
|
||||
uint64_t spans_per_trace = 0;
|
||||
};
|
||||
|
||||
class TracingMetric
|
||||
:
|
||||
public GenericMetric,
|
||||
public Listener<TraceEvent>,
|
||||
public Listener<TraceFinishEvent>
|
||||
{
|
||||
public:
|
||||
void
|
||||
upon(const TraceEvent &event) override
|
||||
{
|
||||
current_traces_number.report(event.getTraceAmount());
|
||||
}
|
||||
|
||||
void
|
||||
upon(const TraceFinishEvent &event) override
|
||||
{
|
||||
max_span_number.report(event.getSpanAmount());
|
||||
avg_spans_per_trace.report(event.getSpanAmount());
|
||||
}
|
||||
|
||||
private:
|
||||
MetricCalculations::LastReportedValue<uint64_t> current_traces_number{this, "currentTraceNumber"};
|
||||
MetricCalculations::Max<uint64_t> max_span_number{this, "maxSpanPerTrace", 0};
|
||||
MetricCalculations::Average<double> avg_spans_per_trace{this, "avgSpanPerTrace"};
|
||||
};
|
||||
|
||||
#endif // __TRACING_METRIC_H__
|
76
core/include/services_sdk/resources/environment_evaluator.h
Normal file
76
core/include/services_sdk/resources/environment_evaluator.h
Normal file
@@ -0,0 +1,76 @@
|
||||
// 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 __ENVIRONMENT_EVALUATOR_H__
|
||||
#define __ENVIRONMENT_EVALUATOR_H__
|
||||
|
||||
#include "maybe_res.h"
|
||||
#include "context.h"
|
||||
|
||||
// All evaluators in the system must inherit from `EnvironmentEvaluator` and be templated on their return type.
|
||||
// In addition to implementing `evalVariable()`, they also need to have `static std::string getName()` function.
|
||||
// The constructor of the inherited class should take `const std::vector<std::string> &` as a parameter, this should
|
||||
// be passed as the parameters to the evaluator.
|
||||
template <typename Value>
|
||||
class EnvironmentEvaluator
|
||||
{
|
||||
public:
|
||||
virtual ~EnvironmentEvaluator() {}
|
||||
virtual Maybe<Value, Context::Error> evalVariable() const = 0;
|
||||
|
||||
using Type = Value;
|
||||
};
|
||||
|
||||
// These functions are used in the construction of an Evaluator to report errors. They throw an exception, so that
|
||||
// the creation process stops.
|
||||
void
|
||||
reportWrongNumberOfParams(
|
||||
const std::string &eval_name,
|
||||
uint no_params_given,
|
||||
uint min_expected,
|
||||
uint max_expected = -1
|
||||
);
|
||||
void reportWrongParamType(const std::string &eval_name, const std::string ¶m, const std::string &reason);
|
||||
void reportUnknownEvaluatorType(const std::string &eval_name);
|
||||
|
||||
#include "environment/evaluators_repo.h"
|
||||
|
||||
// This function is used in the creation of an evaluator. For every parameter the constractor can pass the parameter
|
||||
// to getMatcher (with expected return type as Type) and get a pointer to an evaluator the equals to that parameter.
|
||||
template <typename Type>
|
||||
std::unique_ptr<EnvironmentEvaluator<Type>>
|
||||
getMatcher(const std::string ¶m)
|
||||
{
|
||||
auto ptr = EnvironmentHelper::EvaluatorsRepo<Type>::getRepo();
|
||||
return ptr->getMatcher(param);
|
||||
}
|
||||
|
||||
// This function takes an entire string and attempts to interpret it as a (possibly compound) evaluator that returns
|
||||
// the type `Value`.
|
||||
template <typename Value>
|
||||
Maybe<std::function<Maybe<Value, Context::Error>()>>
|
||||
genEvaluator(const std::string &str)
|
||||
{
|
||||
return EnvironmentHelper::genEvaluator<Value>(str);
|
||||
}
|
||||
|
||||
// This function adds a matcher to the the repository of possible evaluators.
|
||||
template <typename Matcher>
|
||||
bool
|
||||
addMatcher()
|
||||
{
|
||||
auto ptr = EnvironmentHelper::EvaluatorsRepo<typename Matcher::Type>::getRepo();
|
||||
return ptr->template addMatcher<Matcher>();
|
||||
}
|
||||
|
||||
#endif // __ENVIRONMENT_EVALUATOR_H__
|
24
core/include/services_sdk/resources/event.h
Normal file
24
core/include/services_sdk/resources/event.h
Normal file
@@ -0,0 +1,24 @@
|
||||
// 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_H__
|
||||
#define __EVENT_H__
|
||||
|
||||
#include "event_is/event_impl.h"
|
||||
|
||||
template <typename EventType, typename ReplyType = void>
|
||||
class Event : public EventImpl<EventType, ReplyType>
|
||||
{
|
||||
};
|
||||
|
||||
#endif // __EVENT_H__
|
51
core/include/services_sdk/resources/event_is/event_impl.h
Normal file
51
core/include/services_sdk/resources/event_is/event_impl.h
Normal file
@@ -0,0 +1,51 @@
|
||||
// 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_H__
|
||||
#error "event_impl.h sould only be included from event.h"
|
||||
#endif // __EVENT_H__
|
||||
|
||||
#include "listener.h"
|
||||
|
||||
template <typename EventType, typename ReturnType>
|
||||
class EventImpl
|
||||
{
|
||||
public:
|
||||
using EventReturnType = ReturnType;
|
||||
using MyListener = Listener<EventType>;
|
||||
|
||||
void notify() const { MyListener::notify(dynamic_cast<const EventType *>(this)); }
|
||||
|
||||
std::vector<ReturnType> query() const { return MyListener::query(dynamic_cast<const EventType *>(this)); }
|
||||
|
||||
std::vector<std::pair<std::string, ReturnType>>
|
||||
performNamedQuery() const
|
||||
{
|
||||
return MyListener::performNamedQuery(dynamic_cast<const EventType *>(this));
|
||||
}
|
||||
|
||||
protected:
|
||||
virtual ~EventImpl() {} // Makes Event polimorphic, so dynamic_cast will work
|
||||
};
|
||||
|
||||
template <typename EventType>
|
||||
class EventImpl<EventType, void>
|
||||
{
|
||||
public:
|
||||
using EventReturnType = void;
|
||||
|
||||
void notify() const { Listener<EventType>::notify(dynamic_cast<const EventType *>(this)); }
|
||||
|
||||
protected:
|
||||
virtual ~EventImpl() {} // Makes Event polimorphic, so dynamic_cast will work
|
||||
};
|
99
core/include/services_sdk/resources/event_is/listener_impl.h
Normal file
99
core/include/services_sdk/resources/event_is/listener_impl.h
Normal file
@@ -0,0 +1,99 @@
|
||||
// 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 __LISTENER_H__
|
||||
#error "listener_impl.h should only be included from listener.h"
|
||||
#endif // __LISTENER_H__
|
||||
|
||||
#include <set>
|
||||
#include <map>
|
||||
#include <vector>
|
||||
#include <string>
|
||||
|
||||
class BaseListener
|
||||
{
|
||||
using ActivationFunction = void(*)(BaseListener *);
|
||||
|
||||
public:
|
||||
virtual ~BaseListener() { unregisterListener(); }
|
||||
|
||||
void registerListener();
|
||||
void unregisterListener();
|
||||
|
||||
protected:
|
||||
void setActivation(ActivationFunction act, ActivationFunction deact);
|
||||
|
||||
private:
|
||||
bool is_registered = false;
|
||||
std::set<ActivationFunction> activate;
|
||||
std::set<ActivationFunction> deactivate;
|
||||
};
|
||||
|
||||
template <typename EventType, typename ReturnType>
|
||||
class ListenerImpl : public ListenerImpl<EventType, void>
|
||||
{
|
||||
public:
|
||||
virtual typename EventType::EventReturnType respond(const EventType &) = 0;
|
||||
virtual std::string getListenerName() const = 0;
|
||||
|
||||
virtual void upon(const EventType &event) { query(&event); }
|
||||
|
||||
static std::vector<typename EventType::EventReturnType>
|
||||
query(const EventType *event)
|
||||
{
|
||||
std::vector<typename EventType::EventReturnType> responses;
|
||||
for (auto &listener : ListenerImpl<EventType, void>::listeners) {
|
||||
responses.push_back(dynamic_cast<ListenerImpl *>(listener)->respond(*event));
|
||||
}
|
||||
return responses;
|
||||
}
|
||||
|
||||
static std::vector<std::pair<std::string, ReturnType>>
|
||||
performNamedQuery(const EventType *event)
|
||||
{
|
||||
std::vector<std::pair<std::string, ReturnType>> responses;
|
||||
for (auto &listener : ListenerImpl<EventType, void>::listeners) {
|
||||
ListenerImpl *listener_impl = dynamic_cast<ListenerImpl *>(listener);
|
||||
responses.emplace_back(listener_impl->getListenerName(), listener_impl->respond(*event));
|
||||
}
|
||||
return responses;
|
||||
}
|
||||
};
|
||||
|
||||
template <typename EventType>
|
||||
class ListenerImpl<EventType, void> : virtual public BaseListener
|
||||
{
|
||||
public:
|
||||
ListenerImpl() { setActivation(activate, deactivate); }
|
||||
|
||||
virtual void upon(const EventType &) = 0;
|
||||
|
||||
static void
|
||||
notify(const EventType *event)
|
||||
{
|
||||
for (auto &listener : listeners) {
|
||||
dynamic_cast<ListenerImpl *>(listener)->upon(*event);
|
||||
}
|
||||
}
|
||||
|
||||
static bool empty() { return listeners.empty(); }
|
||||
|
||||
protected:
|
||||
static std::set<BaseListener *> listeners;
|
||||
|
||||
private:
|
||||
static void activate(BaseListener *ptr) { listeners.insert(ptr); }
|
||||
static void deactivate(BaseListener *ptr) { listeners.erase(ptr); }
|
||||
};
|
||||
|
||||
template <typename EventType> std::set<BaseListener *> ListenerImpl<EventType, void>::listeners;
|
116
core/include/services_sdk/resources/generic_metric.h
Executable file
116
core/include/services_sdk/resources/generic_metric.h
Executable file
@@ -0,0 +1,116 @@
|
||||
// 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 __GENERIC_METRIC_H__
|
||||
#define __GENERIC_METRIC_H__
|
||||
|
||||
#include <chrono>
|
||||
#include <vector>
|
||||
|
||||
#include "metric/metric_calc.h"
|
||||
#include "metric/all_metric_event.h"
|
||||
#include "i_mainloop.h"
|
||||
#include "i_time_get.h"
|
||||
#include "i_agent_details.h"
|
||||
#include "i_environment.h"
|
||||
#include "i_messaging.h"
|
||||
#include "i_rest_api.h"
|
||||
#include "report/report_enums.h"
|
||||
|
||||
namespace MetricCalculations
|
||||
{
|
||||
class Counter;
|
||||
template <typename T> class Max;
|
||||
template <typename T> class Min;
|
||||
template <typename T> class Average;
|
||||
template <typename T> class LastReportedValue;
|
||||
template <typename T, uint N> class TopValues;
|
||||
template <typename PrintableKey, typename Metric> class MetricMap;
|
||||
} // MetricCalculations
|
||||
|
||||
class GenericMetric
|
||||
:
|
||||
Singleton::Consume<I_MainLoop>,
|
||||
Singleton::Consume<I_TimeGet>,
|
||||
Singleton::Consume<I_AgentDetails>,
|
||||
Singleton::Consume<I_Environment>,
|
||||
Singleton::Consume<I_Messaging>,
|
||||
Singleton::Consume<I_RestApi>,
|
||||
public Listener<AllMetricEvent>
|
||||
{
|
||||
public:
|
||||
void
|
||||
init(
|
||||
const std::string &_metric_name,
|
||||
const ReportIS::AudienceTeam &_team,
|
||||
const ReportIS::IssuingEngine &_issuing_engine,
|
||||
std::chrono::seconds _report_interval,
|
||||
bool _reset,
|
||||
ReportIS::Audience _audience = ReportIS::Audience::INTERNAL
|
||||
);
|
||||
|
||||
template <typename Value>
|
||||
void
|
||||
registerContext(
|
||||
const std::string &key,
|
||||
const Value &val,
|
||||
EnvKeyAttr::LogSection log_enreachment = EnvKeyAttr::LogSection::NONE)
|
||||
{
|
||||
ctx.registerValue<Value>(key, val, log_enreachment);
|
||||
}
|
||||
|
||||
static void preload();
|
||||
|
||||
static void init();
|
||||
static void fini() {}
|
||||
|
||||
static std::string getName() { return "GenericMetric"; }
|
||||
|
||||
std::string generateReport(bool with_reset);
|
||||
void upon(const AllMetricEvent &) override;
|
||||
std::string respond(const AllMetricEvent &event) override;
|
||||
std::string getListenerName() const override;
|
||||
|
||||
std::string getMetricName() const;
|
||||
std::chrono::seconds getReportInterval() const;
|
||||
|
||||
private:
|
||||
class MetricsRest;
|
||||
|
||||
friend class MetricCalc;
|
||||
void addCalc(MetricCalc *calc);
|
||||
|
||||
void handleMetricStreamSending();
|
||||
void generateLog();
|
||||
|
||||
I_MainLoop *i_mainloop;
|
||||
I_TimeGet *i_time;
|
||||
std::string metric_name;
|
||||
ReportIS::AudienceTeam team;
|
||||
ReportIS::IssuingEngine issuing_engine;
|
||||
ReportIS::Audience audience;
|
||||
std::chrono::seconds report_interval;
|
||||
std::vector<MetricCalc *> calcs;
|
||||
bool reset;
|
||||
Context ctx;
|
||||
};
|
||||
|
||||
#include "metric/counter.h"
|
||||
#include "metric/max.h"
|
||||
#include "metric/min.h"
|
||||
#include "metric/average.h"
|
||||
#include "metric/top_values.h"
|
||||
#include "metric/last_reported_value.h"
|
||||
#include "metric/metric_map.h"
|
||||
|
||||
#endif // __GENERIC_METRIC_H__
|
@@ -0,0 +1,99 @@
|
||||
// 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 __HEALTH_CHECK_STATUS_H__
|
||||
#define __HEALTH_CHECK_STATUS_H__
|
||||
|
||||
#include <unordered_map>
|
||||
#include <map>
|
||||
#include <string>
|
||||
|
||||
#include "event.h"
|
||||
#include "singleton.h"
|
||||
#include "debug.h"
|
||||
#include "cereal/archives/json.hpp"
|
||||
#include "customized_cereal_map.h"
|
||||
|
||||
USE_DEBUG_FLAG(D_HEALTH_CHECK_MANAGER);
|
||||
|
||||
enum class HealthCheckStatus {UNHEALTHY, DEGRADED, HEALTHY, IGNORED};
|
||||
|
||||
class HealthCheckStatusReply
|
||||
{
|
||||
public:
|
||||
HealthCheckStatusReply() = delete;
|
||||
|
||||
HealthCheckStatusReply(
|
||||
const std::string &_comp_name,
|
||||
HealthCheckStatus _status,
|
||||
const std::map<std::string, std::string> &_extended_status
|
||||
)
|
||||
:
|
||||
comp_name(_comp_name),
|
||||
status(_status),
|
||||
extended_status(_extended_status)
|
||||
{}
|
||||
|
||||
HealthCheckStatusReply &
|
||||
operator=(HealthCheckStatusReply reply)
|
||||
{
|
||||
std::string reply_name = reply.getCompName();
|
||||
HealthCheckStatus reply_status = reply.getStatus();
|
||||
std::map<std::string, std::string> reply_extended_status = reply.getExtendedStatus();
|
||||
|
||||
std::swap(comp_name, reply_name);
|
||||
std::swap(status, reply_status);
|
||||
std::swap(extended_status, reply_extended_status);
|
||||
|
||||
return *this;
|
||||
}
|
||||
|
||||
void
|
||||
serialize(cereal::JSONOutputArchive &ar) const
|
||||
{
|
||||
ar(cereal::make_nvp("status", convertHealthCheckStatusToStr(status)));
|
||||
ar(cereal::make_nvp("extendedStatus", extended_status));
|
||||
}
|
||||
|
||||
const std::string & getCompName() const { return comp_name; }
|
||||
HealthCheckStatus getStatus() const { return status; }
|
||||
const std::map<std::string, std::string> & getExtendedStatus() const { return extended_status; }
|
||||
|
||||
static std::string
|
||||
convertHealthCheckStatusToStr(HealthCheckStatus status)
|
||||
{
|
||||
switch (status) {
|
||||
case HealthCheckStatus::UNHEALTHY : return "Unhealthy";
|
||||
case HealthCheckStatus::DEGRADED : return "Degraded";
|
||||
case HealthCheckStatus::HEALTHY : return "Healthy";
|
||||
case HealthCheckStatus::IGNORED : return "Ignored";
|
||||
}
|
||||
|
||||
dbgError(D_HEALTH_CHECK_MANAGER) << "Trying to convert unknown health check status to string.";
|
||||
return "";
|
||||
}
|
||||
|
||||
private:
|
||||
std::string comp_name = "";
|
||||
HealthCheckStatus status = HealthCheckStatus::IGNORED;
|
||||
std::map<std::string, std::string> extended_status = {};
|
||||
};
|
||||
|
||||
class HealthCheckStatusEvent : public Event<HealthCheckStatusEvent, HealthCheckStatusReply>
|
||||
{
|
||||
public:
|
||||
HealthCheckStatusEvent() {}
|
||||
~HealthCheckStatusEvent() {}
|
||||
};
|
||||
|
||||
#endif // __HEALTH_CHECK_STATUS_H__
|
58
core/include/services_sdk/resources/intelligence_filter.h
Executable file
58
core/include/services_sdk/resources/intelligence_filter.h
Executable file
@@ -0,0 +1,58 @@
|
||||
// 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 __INTELLIGENCE_FILTER_H__
|
||||
#define __INTELLIGENCE_FILTER_H__
|
||||
|
||||
#include "rest.h"
|
||||
#include "common.h"
|
||||
#include "intelligence_is/intelligence_types.h"
|
||||
|
||||
class IntelligenceFilter
|
||||
{
|
||||
public:
|
||||
IntelligenceFilter(
|
||||
const std::string &key,
|
||||
const std::string &value,
|
||||
Intelligence_IS::AttributeKeyType type= Intelligence_IS::AttributeKeyType::NONE
|
||||
);
|
||||
|
||||
void addFilter(
|
||||
const std::string &key,
|
||||
const std::string &value,
|
||||
Intelligence_IS::AttributeKeyType type= Intelligence_IS::AttributeKeyType::NONE
|
||||
);
|
||||
|
||||
std::string getQuery(bool is_encoded = true) const;
|
||||
const std::set<std::pair<std::string, std::string>> & getFilters() const;
|
||||
|
||||
void addRequestedAttr(
|
||||
const std::string &attr,
|
||||
Intelligence_IS::AttributeKeyType type = Intelligence_IS::AttributeKeyType::NONE
|
||||
);
|
||||
|
||||
const std::set<std::string> & getRequestedAttr() const;
|
||||
std::string getRequestedAttrStr() const;
|
||||
|
||||
private:
|
||||
std::string
|
||||
createAttrString(
|
||||
const std::string &value,
|
||||
bool use_quotes,
|
||||
Intelligence_IS::AttributeKeyType type = Intelligence_IS::AttributeKeyType::NONE
|
||||
) const;
|
||||
|
||||
std::set<std::pair<std::string, std::string>> query;
|
||||
std::set<std::string> requested_attr;
|
||||
};
|
||||
#endif // __INTELLIGENCE_FILTER_H__
|
@@ -0,0 +1,63 @@
|
||||
// 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 __DATA_MAP_H__
|
||||
#define __DATA_MAP_H__
|
||||
|
||||
#include <vector>
|
||||
#include <string>
|
||||
#include <sstream>
|
||||
#include <iterator>
|
||||
#include <iostream>
|
||||
|
||||
#include "common.h"
|
||||
|
||||
class DataMap
|
||||
{
|
||||
public:
|
||||
DataMap() {}
|
||||
DataMap(const DataMap &_data) : data(_data.data) {}
|
||||
|
||||
template <typename Archive>
|
||||
void
|
||||
serialize(Archive &ar, const std::string &key)
|
||||
{
|
||||
ar(cereal::make_nvp(key, data));
|
||||
}
|
||||
|
||||
std::string
|
||||
toString() const
|
||||
{
|
||||
std::ostringstream os;
|
||||
bool not_first = false;
|
||||
os << "{";
|
||||
for (const auto &element : data) {
|
||||
if (not_first) os << ", ";
|
||||
os << element.first << ":" << element.second;
|
||||
not_first = true;
|
||||
}
|
||||
os << "}";
|
||||
return os.str();
|
||||
}
|
||||
|
||||
const std::map<std::string, std::string> &
|
||||
getMapData() const
|
||||
{
|
||||
return data;
|
||||
}
|
||||
|
||||
private:
|
||||
std::map<std::string, std::string> data = {};
|
||||
};
|
||||
|
||||
#endif // __DATA_MAP_H__
|
36
core/include/services_sdk/resources/intelligence_is/data_string.h
Executable file
36
core/include/services_sdk/resources/intelligence_is/data_string.h
Executable file
@@ -0,0 +1,36 @@
|
||||
// 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 __DATA_STRING_H__
|
||||
#define __DATA_STRING_H__
|
||||
|
||||
class DataString
|
||||
{
|
||||
public:
|
||||
DataString() {}
|
||||
DataString(const DataString& _data) : data(_data.data){}
|
||||
|
||||
template <typename Archive>
|
||||
void
|
||||
serialize(Archive &ar, const std::string &key)
|
||||
{
|
||||
ar(cereal::make_nvp(key, data));
|
||||
}
|
||||
|
||||
const std::string & toString() const { return data; }
|
||||
|
||||
private:
|
||||
std::string data;
|
||||
};
|
||||
|
||||
#endif // __DATA_STRING_H__
|
@@ -0,0 +1,48 @@
|
||||
// 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 __DATA_VECTOR_H__
|
||||
#define __DATA_VECTOR_H__
|
||||
|
||||
#include <vector>
|
||||
#include <string>
|
||||
#include <sstream>
|
||||
#include <iterator>
|
||||
#include <iostream>
|
||||
|
||||
#include "common.h"
|
||||
|
||||
class DataVector
|
||||
{
|
||||
public:
|
||||
DataVector() {}
|
||||
DataVector(const DataVector &_data) : data(_data.data) {}
|
||||
|
||||
template <typename Archive>
|
||||
void
|
||||
serialize(Archive &ar, const std::string &key)
|
||||
{
|
||||
ar(cereal::make_nvp(key, data));
|
||||
}
|
||||
|
||||
std::string
|
||||
toString() const
|
||||
{
|
||||
return "[" + makeSeparatedStr(data, ", ") + "]";
|
||||
}
|
||||
|
||||
private:
|
||||
std::vector<std::string> data = {};
|
||||
};
|
||||
|
||||
#endif // __DATA_VECTOR_H__
|
55
core/include/services_sdk/resources/intelligence_is/read_attribute_impl.h
Executable file
55
core/include/services_sdk/resources/intelligence_is/read_attribute_impl.h
Executable file
@@ -0,0 +1,55 @@
|
||||
// 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 __READ_ATTRIBUTE_IMPL_H__
|
||||
#define __READ_ATTRIBUTE_IMPL_H__
|
||||
|
||||
#ifndef __READ_ATTRIBUTE_H__
|
||||
#error read_attribute_impl.h should not be included directly!
|
||||
#endif // __READ_ATTRIBUTE_H__
|
||||
|
||||
#include "debug.h"
|
||||
|
||||
USE_DEBUG_FLAG(D_INTELLIGENCE);
|
||||
|
||||
template <typename UserSerializableReply>
|
||||
ReadAttribute<UserSerializableReply>::ReadAttribute(const std::string &_key, UserSerializableReply &_data)
|
||||
:
|
||||
key(_key),
|
||||
data(_data)
|
||||
{}
|
||||
|
||||
template <typename UserSerializableReply>
|
||||
template <typename Archive>
|
||||
void
|
||||
ReadAttribute<UserSerializableReply>::serialize(Archive &ar)
|
||||
{
|
||||
dbgTrace(D_INTELLIGENCE) << "Reading asset's attributes";
|
||||
try {
|
||||
data.serialize(ar, key);
|
||||
} catch (const Intelligence_IS::IntelligenceException &e) {
|
||||
dbgWarning(D_INTELLIGENCE) << "Failed to read attributes of query response";
|
||||
ar.finishNode();
|
||||
|
||||
throw e;
|
||||
}
|
||||
}
|
||||
|
||||
template <typename UserSerializableReply>
|
||||
UserSerializableReply
|
||||
ReadAttribute<UserSerializableReply>::getData() const
|
||||
{
|
||||
return data;
|
||||
}
|
||||
|
||||
#endif // __READ_ATTRIBUTE_IMPL_H__
|
@@ -0,0 +1,103 @@
|
||||
// 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 __DATA_MAP_H__
|
||||
#define __DATA_MAP_H__
|
||||
|
||||
#include <vector>
|
||||
#include <string>
|
||||
#include <sstream>
|
||||
#include <iterator>
|
||||
#include <iostream>
|
||||
|
||||
#include "common.h"
|
||||
|
||||
class DataMap
|
||||
{
|
||||
public:
|
||||
DataMap() {}
|
||||
DataMap(const DataMap &_data) : data(_data.data) {}
|
||||
|
||||
template <typename Archive>
|
||||
void
|
||||
serialize(Archive &ar, const std::string &key)
|
||||
{
|
||||
ar(cereal::make_nvp(key, data));
|
||||
}
|
||||
|
||||
std::string
|
||||
toString() const
|
||||
{
|
||||
std::ostringstream os;
|
||||
bool not_first = false;
|
||||
os << "{";
|
||||
for (const auto &element : data) {
|
||||
if (not_first) os << ", ";
|
||||
os << element.first << ":" << element.second;
|
||||
not_first = true;
|
||||
}
|
||||
os << "}";
|
||||
return os.str();
|
||||
}
|
||||
|
||||
const std::map<std::string, std::string> &
|
||||
getMapData() const
|
||||
{
|
||||
return data;
|
||||
}
|
||||
|
||||
private:
|
||||
std::map<std::string, std::string> data = {};
|
||||
};
|
||||
|
||||
class DataMapVector
|
||||
{
|
||||
public:
|
||||
DataMapVector() {}
|
||||
DataMapVector(const DataMapVector &_data) : data(_data.data) {}
|
||||
|
||||
template <typename Archive>
|
||||
void
|
||||
serialize(Archive &ar, const std::string &key)
|
||||
{
|
||||
ar(cereal::make_nvp(key, data));
|
||||
}
|
||||
|
||||
std::string
|
||||
toString() const
|
||||
{
|
||||
std::ostringstream os;
|
||||
bool not_first = false;
|
||||
os << "{";
|
||||
for (const auto &element : data) {
|
||||
for (const auto &elem : element) {
|
||||
if (not_first) os << ", ";
|
||||
os << elem.first << ":" << elem.second;
|
||||
not_first = true;
|
||||
}
|
||||
}
|
||||
os << "}";
|
||||
return os.str();
|
||||
}
|
||||
|
||||
const std::vector<std::map<std::string, std::string>> &
|
||||
getMapData() const
|
||||
{
|
||||
return data;
|
||||
}
|
||||
|
||||
private:
|
||||
std::vector<std::map<std::string, std::string>> data = {};
|
||||
};
|
||||
|
||||
#endif // __DATA_MAP_H__
|
36
core/include/services_sdk/resources/intelligence_is_v2/data_string_v2.h
Executable file
36
core/include/services_sdk/resources/intelligence_is_v2/data_string_v2.h
Executable file
@@ -0,0 +1,36 @@
|
||||
// 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 __DATA_STRING_V2_H__
|
||||
#define __DATA_STRING_V2_H__
|
||||
|
||||
class DataString
|
||||
{
|
||||
public:
|
||||
DataString() {}
|
||||
DataString(const DataString& _data) : data(_data.data){}
|
||||
|
||||
template <typename Archive>
|
||||
void
|
||||
serialize(Archive &ar, const std::string &key)
|
||||
{
|
||||
ar(cereal::make_nvp(key, data));
|
||||
}
|
||||
|
||||
const std::string & toString() const { return data; }
|
||||
|
||||
private:
|
||||
std::string data = "";
|
||||
};
|
||||
|
||||
#endif // __DATA_STRING_V2_H__
|
54
core/include/services_sdk/resources/intelligence_is_v2/data_vector_v2.h
Executable file
54
core/include/services_sdk/resources/intelligence_is_v2/data_vector_v2.h
Executable file
@@ -0,0 +1,54 @@
|
||||
// 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 __DATA_VECTOR_V2_H__
|
||||
#define __DATA_VECTOR_V2_H__
|
||||
|
||||
#include <vector>
|
||||
#include <string>
|
||||
#include <sstream>
|
||||
#include <iterator>
|
||||
#include <iostream>
|
||||
|
||||
#include "common.h"
|
||||
|
||||
class DataVector
|
||||
{
|
||||
public:
|
||||
DataVector() {}
|
||||
DataVector(const DataVector &_data) : data(_data.data) {}
|
||||
|
||||
template <typename Archive>
|
||||
void
|
||||
serialize(Archive &ar, const std::string &key)
|
||||
{
|
||||
ar(cereal::make_nvp(key, data));
|
||||
}
|
||||
|
||||
std::string
|
||||
toString() const
|
||||
{
|
||||
return "[" + makeSeparatedStr(data, ", ") + "]";
|
||||
}
|
||||
|
||||
const std::vector<std::string> &
|
||||
getVectorData() const
|
||||
{
|
||||
return data;
|
||||
}
|
||||
|
||||
private:
|
||||
std::vector<std::string> data = {};
|
||||
};
|
||||
|
||||
#endif // __DATA_VECTOR_V2_H__
|
@@ -0,0 +1,55 @@
|
||||
// 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 __READ_ATTRIBUTE_V2_IMPL_H__
|
||||
#define __READ_ATTRIBUTE_V2_IMPL_H__
|
||||
|
||||
#ifndef __READ_ATTRIBUTE_V2_H__
|
||||
#error read_attribute_v2_impl.h should not be included directly!
|
||||
#endif // __READ_ATTRIBUTE_V2_H__
|
||||
|
||||
#include "debug.h"
|
||||
|
||||
USE_DEBUG_FLAG(D_INTELLIGENCE);
|
||||
|
||||
template <typename UserSerializableReply>
|
||||
ReadAttribute<UserSerializableReply>::ReadAttribute(const std::string &_key, UserSerializableReply &_data)
|
||||
:
|
||||
key(_key),
|
||||
data(_data)
|
||||
{}
|
||||
|
||||
template <typename UserSerializableReply>
|
||||
template <typename Archive>
|
||||
void
|
||||
ReadAttribute<UserSerializableReply>::serialize(Archive &ar)
|
||||
{
|
||||
dbgTrace(D_INTELLIGENCE) << "Reading asset's attributes";
|
||||
try {
|
||||
data.serialize(ar, key);
|
||||
} catch (const Intelligence_IS_V2::IntelligenceException &e) {
|
||||
dbgWarning(D_INTELLIGENCE) << "Failed to read attributes of query response";
|
||||
ar.finishNode();
|
||||
|
||||
throw e;
|
||||
}
|
||||
}
|
||||
|
||||
template <typename UserSerializableReply>
|
||||
UserSerializableReply
|
||||
ReadAttribute<UserSerializableReply>::getData() const
|
||||
{
|
||||
return data;
|
||||
}
|
||||
|
||||
#endif // __READ_ATTRIBUTE_V2_IMPL_H__
|
24
core/include/services_sdk/resources/listener.h
Normal file
24
core/include/services_sdk/resources/listener.h
Normal file
@@ -0,0 +1,24 @@
|
||||
// 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 __LISTENER_H__
|
||||
#define __LISTENER_H__
|
||||
|
||||
#include "event_is/listener_impl.h"
|
||||
|
||||
template <typename EventType>
|
||||
class Listener : public ListenerImpl<EventType, typename EventType::EventReturnType>
|
||||
{
|
||||
};
|
||||
|
||||
#endif // __LISTENER_H__
|
110
core/include/services_sdk/resources/log_generator.h
Executable file
110
core/include/services_sdk/resources/log_generator.h
Executable file
@@ -0,0 +1,110 @@
|
||||
// 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 __LOG_GENERATOR_H__
|
||||
#define __LOG_GENERATOR_H__
|
||||
|
||||
#include "i_logging.h"
|
||||
#include "singleton.h"
|
||||
#include "report/report.h"
|
||||
#include "i_time_get.h"
|
||||
#include "config.h"
|
||||
#include "i_agent_details.h"
|
||||
#include "i_environment.h"
|
||||
#include "flags.h"
|
||||
|
||||
class LogGen
|
||||
:
|
||||
Singleton::Consume<I_Logging>,
|
||||
Singleton::Consume<I_TimeGet>,
|
||||
Singleton::Consume<I_AgentDetails>,
|
||||
Singleton::Consume<I_Environment>
|
||||
{
|
||||
public:
|
||||
template <typename Trigger, typename ...Args>
|
||||
LogGen(
|
||||
const Trigger &trigger,
|
||||
const std::string &title,
|
||||
Args ...args)
|
||||
:
|
||||
LogGen(trigger(title, std::forward<Args>(args)...))
|
||||
{
|
||||
}
|
||||
|
||||
template <typename ...Args>
|
||||
LogGen(
|
||||
const std::string &title,
|
||||
const ReportIS::Audience &_audience,
|
||||
const ReportIS::Severity &_severity,
|
||||
const ReportIS::Priority &_priority,
|
||||
Args ...args)
|
||||
:
|
||||
LogGen(
|
||||
title,
|
||||
ReportIS::Level::LOG,
|
||||
_audience,
|
||||
_severity,
|
||||
_priority,
|
||||
std::forward<Args>(args)...
|
||||
)
|
||||
{
|
||||
}
|
||||
|
||||
template <typename ...Args>
|
||||
LogGen(
|
||||
const std::string &title,
|
||||
const ReportIS::Level &level,
|
||||
const ReportIS::Audience &_audience,
|
||||
const ReportIS::Severity &_severity,
|
||||
const ReportIS::Priority &_priority,
|
||||
Args ...args)
|
||||
:
|
||||
log(
|
||||
title,
|
||||
getCurrentTime(),
|
||||
ReportIS::Type::EVENT,
|
||||
level,
|
||||
ReportIS::LogLevel::INFO,
|
||||
_audience,
|
||||
getAudienceTeam(),
|
||||
_severity,
|
||||
_priority,
|
||||
std::chrono::seconds(0),
|
||||
LogField("agentId", Singleton::Consume<I_AgentDetails>::by<LogGen>()->getAgentId()),
|
||||
std::forward<Args>(args)...
|
||||
)
|
||||
{
|
||||
loadBaseLogFields();
|
||||
}
|
||||
|
||||
~LogGen();
|
||||
|
||||
LogGen & operator<<(const LogField &field);
|
||||
|
||||
template <typename Error>
|
||||
LogGen & operator<<(const Maybe<LogField, Error> &field) { log << field; return *this; }
|
||||
|
||||
void addToOrigin(const LogField &field);
|
||||
|
||||
void serialize(cereal::JSONOutputArchive &ar) const;
|
||||
|
||||
ReportIS::AudienceTeam getAudienceTeam() const;
|
||||
|
||||
private:
|
||||
std::chrono::microseconds getCurrentTime() const;
|
||||
void loadBaseLogFields();
|
||||
|
||||
Report log;
|
||||
};
|
||||
|
||||
#endif // __LOG_GENERATOR_H__
|
42
core/include/services_sdk/resources/memory_consumption.h
Executable file
42
core/include/services_sdk/resources/memory_consumption.h
Executable file
@@ -0,0 +1,42 @@
|
||||
// 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 __MEMORY_CONSUMPTION_H__
|
||||
#define __MEMORY_CONSUMPTION_H__
|
||||
|
||||
#include "i_mainloop.h"
|
||||
#include "i_environment.h"
|
||||
#include "debug.h"
|
||||
#include "common.h"
|
||||
#include "component.h"
|
||||
|
||||
class MemoryCalculator
|
||||
:
|
||||
public Component,
|
||||
Singleton::Consume<I_MainLoop>,
|
||||
Singleton::Consume<I_Environment>
|
||||
{
|
||||
public:
|
||||
MemoryCalculator();
|
||||
~MemoryCalculator();
|
||||
|
||||
void preload();
|
||||
|
||||
void init();
|
||||
|
||||
private:
|
||||
class Impl;
|
||||
std::unique_ptr<Impl> pimpl;
|
||||
};
|
||||
|
||||
#endif // __MEMORY_CONSUMPTION_H__
|
Some files were not shown because too many files have changed in this diff Show More
Reference in New Issue
Block a user