mirror of
https://github.com/openappsec/openappsec.git
synced 2025-11-15 17:02:15 +03:00
Jun 16th update
This commit is contained in:
@@ -20,9 +20,6 @@
|
||||
|
||||
#include "config.h"
|
||||
#include "debug.h"
|
||||
#include "sasal.h"
|
||||
|
||||
SASAL_START // Orchestration - Communication
|
||||
|
||||
using namespace std;
|
||||
|
||||
@@ -303,5 +300,3 @@ AgentDetails::registerMachineType()
|
||||
);
|
||||
dbgInfo(D_ORCHESTRATOR) << "Setting machine type " << static_cast<int>(machine_type.unpack());
|
||||
}
|
||||
|
||||
SASAL_END
|
||||
|
||||
@@ -188,7 +188,7 @@ Maybe<uint>
|
||||
Buffer::findFirstOf(const Buffer &buf, uint start) const
|
||||
{
|
||||
dbgAssert(start <= len) << "Buffer::findFirstOf() returned: Cannot set a start point after buffer's end";
|
||||
|
||||
|
||||
for (; start + buf.size() <= len; ++start) {
|
||||
auto sub_buffer = getSubBuffer(start, start + buf.size());
|
||||
if (sub_buffer == buf) return start;
|
||||
|
||||
@@ -26,6 +26,7 @@
|
||||
#include "include/profile_settings.h"
|
||||
#include "enum_range.h"
|
||||
#include "rest.h"
|
||||
#include "tenant_profile_pair.h"
|
||||
|
||||
using namespace std;
|
||||
using namespace cereal;
|
||||
@@ -103,7 +104,11 @@ public:
|
||||
const string & getFilesystemPathConfig() const override;
|
||||
const string & getLogFilesPathConfig() const override;
|
||||
|
||||
string getPolicyConfigPath(const string &name, ConfigFileType type, const string &tenant = "") const override;
|
||||
string getPolicyConfigPath(
|
||||
const string &name,
|
||||
ConfigFileType type,
|
||||
const string &tenant = "",
|
||||
const string &profile = "") const override;
|
||||
|
||||
bool setConfiguration(TypeWrapper &&value, const std::vector<std::string> &paths) override;
|
||||
bool setResource(TypeWrapper &&value, const std::vector<std::string> &paths) override;
|
||||
@@ -126,7 +131,7 @@ public:
|
||||
|
||||
private:
|
||||
void clearOldTenants();
|
||||
bool isTenantActive(const string &name) const;
|
||||
bool areTenantAndProfileActive(const TenantProfilePair &tenant_profile) const;
|
||||
void periodicRegistrationRefresh();
|
||||
|
||||
bool loadConfiguration(vector<shared_ptr<JSONInputArchive>> &file_archives, bool is_async);
|
||||
@@ -143,6 +148,14 @@ private:
|
||||
return active_id.ok() ? *active_id : default_tenant_id;
|
||||
}
|
||||
|
||||
string
|
||||
getActiveProfile() const
|
||||
{
|
||||
auto active_id = Singleton::Consume<I_Environment>::by<ConfigComponent>()->get<string>("ActiveProfileId");
|
||||
|
||||
return active_id.ok() ? *active_id : default_profile_id;
|
||||
}
|
||||
|
||||
bool
|
||||
sendOrchestatorConfMsg(int env_listening_port)
|
||||
{
|
||||
@@ -234,14 +247,14 @@ private:
|
||||
}
|
||||
}
|
||||
|
||||
unordered_map<string, map<vector<string>, PerContextValue>> configuration_nodes;
|
||||
unordered_map<string, map<vector<string>, TypeWrapper>> settings_nodes;
|
||||
unordered_map<TenantProfilePair, map<vector<string>, PerContextValue>> configuration_nodes;
|
||||
unordered_map<TenantProfilePair, map<vector<string>, TypeWrapper>> settings_nodes;
|
||||
map<string, string> profile_settings;
|
||||
unordered_map<string, string> config_flags;
|
||||
|
||||
map<vector<string>, TypeWrapper> new_resource_nodes;
|
||||
unordered_map<string, map<vector<string>, PerContextValue>> new_configuration_nodes;
|
||||
unordered_map<string, map<vector<string>, TypeWrapper>> new_settings_nodes;
|
||||
unordered_map<TenantProfilePair, map<vector<string>, PerContextValue>> new_configuration_nodes;
|
||||
unordered_map<TenantProfilePair, map<vector<string>, TypeWrapper>> new_settings_nodes;
|
||||
unordered_map<string, string> new_config_flags;
|
||||
|
||||
set<unique_ptr<GenericConfig<true>>> expected_configs;
|
||||
@@ -257,7 +270,8 @@ private:
|
||||
vector<ConfigCb> configuration_abort_cbs;
|
||||
|
||||
bool is_continuous_report = false;
|
||||
const string default_tenant_id = "default_tenant_id_value";
|
||||
const string default_tenant_id = "";
|
||||
const string default_profile_id = "";
|
||||
string executable_name = "";
|
||||
string filesystem_prefix = "/etc/cp";
|
||||
string log_files_prefix = "/var/log";
|
||||
@@ -331,7 +345,7 @@ checkContext(const shared_ptr<EnvironmentEvaluator<bool>> &ctx)
|
||||
const TypeWrapper &
|
||||
ConfigComponent::Impl::getConfiguration(const vector<string> &paths) const
|
||||
{
|
||||
auto curr_configs = configuration_nodes.find(getActiveTenant());
|
||||
auto curr_configs = configuration_nodes.find(TenantProfilePair(getActiveTenant(), getActiveProfile()));
|
||||
|
||||
if (curr_configs != configuration_nodes.end()) {
|
||||
auto requested_config = curr_configs->second.find(paths);
|
||||
@@ -342,7 +356,7 @@ ConfigComponent::Impl::getConfiguration(const vector<string> &paths) const
|
||||
}
|
||||
}
|
||||
|
||||
auto global_config = configuration_nodes.find(default_tenant_id);
|
||||
auto global_config = configuration_nodes.find(TenantProfilePair(default_tenant_id, default_profile_id));
|
||||
if (global_config != configuration_nodes.end()) {
|
||||
auto requested_config = global_config->second.find(paths);
|
||||
if (requested_config != global_config->second.end()) {
|
||||
@@ -358,14 +372,14 @@ ConfigComponent::Impl::getConfiguration(const vector<string> &paths) const
|
||||
vector<pair<shared_ptr<EnvironmentEvaluator<bool>>, TypeWrapper>>
|
||||
ConfigComponent::Impl::getAllConfiguration(const vector<string> &paths) const
|
||||
{
|
||||
auto curr_configs = configuration_nodes.find(getActiveTenant());
|
||||
auto curr_configs = configuration_nodes.find(TenantProfilePair(getActiveTenant(), getActiveProfile()));
|
||||
|
||||
if (curr_configs != configuration_nodes.end()) {
|
||||
auto requested_config = curr_configs->second.find(paths);
|
||||
if (requested_config != curr_configs->second.end()) return requested_config->second;
|
||||
}
|
||||
|
||||
auto global_config = configuration_nodes.find(default_tenant_id);
|
||||
auto global_config = configuration_nodes.find(TenantProfilePair(default_tenant_id, default_profile_id));
|
||||
if (global_config != configuration_nodes.end()) {
|
||||
auto requested_config = global_config->second.find(paths);
|
||||
if (requested_config != global_config->second.end()) return requested_config->second;
|
||||
@@ -386,13 +400,13 @@ ConfigComponent::Impl::getResource(const vector<string> &paths) const
|
||||
const TypeWrapper &
|
||||
ConfigComponent::Impl::getSetting(const vector<string> &paths) const
|
||||
{
|
||||
auto curr_configs = settings_nodes.find(getActiveTenant());
|
||||
auto curr_configs = settings_nodes.find(TenantProfilePair(getActiveTenant(), getActiveProfile()));
|
||||
if (curr_configs != settings_nodes.end()) {
|
||||
auto requested_config = curr_configs->second.find(paths);
|
||||
if (requested_config != curr_configs->second.end()) return requested_config->second;
|
||||
}
|
||||
|
||||
auto global_config = settings_nodes.find(default_tenant_id);
|
||||
auto global_config = settings_nodes.find(TenantProfilePair(default_tenant_id, default_profile_id));
|
||||
if (global_config != settings_nodes.end()) {
|
||||
auto requested_config = global_config->second.find(paths);
|
||||
if (requested_config != global_config->second.end()) return requested_config->second;
|
||||
@@ -448,15 +462,20 @@ ConfigComponent::Impl::getLogFilesPathConfig() const
|
||||
}
|
||||
|
||||
string
|
||||
ConfigComponent::Impl::getPolicyConfigPath(const string &config_name, ConfigFileType type, const string &tenant) const
|
||||
ConfigComponent::Impl::getPolicyConfigPath(
|
||||
const string &config_name,
|
||||
ConfigFileType type,
|
||||
const string &tenant,
|
||||
const string &profile) const
|
||||
{
|
||||
static const string policy_suffix = ".policy";
|
||||
static const string data_suffix = ".data";
|
||||
static const string tenant_prefix = "tenant_";
|
||||
static const string profile_prefix = "_profile_";
|
||||
|
||||
string base_path =
|
||||
getConfigurationWithDefault(config_directory_path, "Config Component", "configuration path") +
|
||||
(tenant.empty() ? "" : tenant_prefix + tenant + "/");
|
||||
(tenant.empty() ? "" : tenant_prefix + tenant + profile_prefix + profile +"/");
|
||||
|
||||
switch (type) {
|
||||
case ConfigFileType::Data: return base_path + "data/" + config_name + data_suffix;
|
||||
@@ -472,13 +491,14 @@ ConfigComponent::Impl::getPolicyConfigPath(const string &config_name, ConfigFile
|
||||
bool
|
||||
ConfigComponent::Impl::setConfiguration(TypeWrapper &&value, const vector<string> &paths)
|
||||
{
|
||||
for (auto &tennant : configuration_nodes) {
|
||||
tennant.second.erase(paths);
|
||||
for (auto &tenant : configuration_nodes) {
|
||||
tenant.second.erase(paths);
|
||||
}
|
||||
|
||||
PerContextValue value_vec;
|
||||
TenantProfilePair default_tenant_profile(default_tenant_id, default_profile_id);
|
||||
value_vec.emplace_back(nullptr, move(value));
|
||||
configuration_nodes[default_tenant_id][paths] = move(value_vec);
|
||||
configuration_nodes[default_tenant_profile][paths] = move(value_vec);
|
||||
return true;
|
||||
}
|
||||
|
||||
@@ -492,7 +512,8 @@ ConfigComponent::Impl::setResource(TypeWrapper &&value, const vector<string> &pa
|
||||
bool
|
||||
ConfigComponent::Impl::setSetting(TypeWrapper &&value, const vector<string> &paths)
|
||||
{
|
||||
settings_nodes[default_tenant_id][paths] = move(value);
|
||||
TenantProfilePair default_tenant_profile(default_tenant_id, default_profile_id);
|
||||
settings_nodes[default_tenant_profile][paths] = move(value);
|
||||
return true;
|
||||
}
|
||||
|
||||
@@ -635,20 +656,21 @@ ConfigComponent::Impl::clearOldTenants()
|
||||
for (
|
||||
auto iter = configuration_nodes.begin();
|
||||
iter != configuration_nodes.end();
|
||||
!isTenantActive(iter->first) ? iter = configuration_nodes.erase(iter) : ++iter
|
||||
!areTenantAndProfileActive(iter->first) ? iter = configuration_nodes.erase(iter) : ++iter
|
||||
);
|
||||
|
||||
for (
|
||||
auto iter = settings_nodes.begin();
|
||||
iter != settings_nodes.end();
|
||||
!isTenantActive(iter->first) ? iter = settings_nodes.erase(iter) : ++iter
|
||||
!areTenantAndProfileActive(iter->first) ? iter = settings_nodes.erase(iter) : ++iter
|
||||
);
|
||||
}
|
||||
|
||||
bool
|
||||
ConfigComponent::Impl::isTenantActive(const string &name) const
|
||||
ConfigComponent::Impl::areTenantAndProfileActive(const TenantProfilePair &tenant_profile) const
|
||||
{
|
||||
return name == default_tenant_id || tenant_mananger->isTenantActive(name);
|
||||
return (tenant_profile.getTenantId() == default_tenant_id && tenant_profile.getPfofileId() == default_profile_id)
|
||||
|| tenant_mananger->areTenantAndProfileActive(tenant_profile.getTenantId(), tenant_profile.getPfofileId());
|
||||
}
|
||||
|
||||
void
|
||||
@@ -697,20 +719,25 @@ ConfigComponent::Impl::loadConfiguration(vector<shared_ptr<JSONInputArchive>> &f
|
||||
}
|
||||
|
||||
for (auto &archive : file_archives) {
|
||||
string curr_tennat = default_tenant_id;
|
||||
string curr_tenant = default_tenant_id;
|
||||
string curr_profile = default_profile_id;
|
||||
try {
|
||||
(*archive)(cereal::make_nvp("tenantID", curr_tennat));
|
||||
(*archive)(cereal::make_nvp("tenantID", curr_tenant));
|
||||
(*archive)(cereal::make_nvp("profileID", curr_profile));
|
||||
} catch (cereal::Exception &e) {
|
||||
}
|
||||
|
||||
dbgTrace(D_CONFIG) <<
|
||||
"Loading configuration for tenant: " << curr_tenant << " and profile: " << curr_profile;
|
||||
TenantProfilePair tenant_profile(curr_tenant, curr_profile);
|
||||
for (auto &config : expected_configs) {
|
||||
auto loaded = config->loadConfiguration(*archive);
|
||||
if (!loaded.empty()) new_configuration_nodes[curr_tennat][config->getPath()] = move(loaded);
|
||||
if (!loaded.empty()) new_configuration_nodes[tenant_profile][config->getPath()] = move(loaded);
|
||||
if (is_async) mainloop->yield();
|
||||
}
|
||||
for (auto &setting : expected_settings) {
|
||||
auto loaded = setting->loadConfiguration(*archive);
|
||||
if (loaded.ok()) new_settings_nodes[curr_tennat][setting->getPath()] = move(loaded);
|
||||
if (loaded.ok()) new_settings_nodes[tenant_profile][setting->getPath()] = move(loaded);
|
||||
if (is_async) mainloop->yield();
|
||||
}
|
||||
}
|
||||
@@ -783,7 +810,8 @@ ConfigComponent::Impl::reloadConfigurationImpl(const string &version, bool is_as
|
||||
files.emplace(fullpath, make_shared<ifstream>(fullpath));
|
||||
}
|
||||
|
||||
const vector<string> &active_tenants = tenant_mananger ? tenant_mananger->fetchActiveTenants() : vector<string>();
|
||||
const auto &active_tenants = tenant_mananger ? tenant_mananger->fetchAllActiveTenants() : vector<string>();
|
||||
|
||||
for (const auto &config_file : expected_configuration_files) {
|
||||
for (const auto &type : config_file.second) {
|
||||
if (type == ConfigFileType::RawData) continue;
|
||||
@@ -793,15 +821,29 @@ ConfigComponent::Impl::reloadConfigurationImpl(const string &version, bool is_as
|
||||
}
|
||||
|
||||
for (auto &tenant : active_tenants) {
|
||||
auto tenant_path = getPolicyConfigPath(config_file.first, type, tenant);
|
||||
files.emplace(tenant_path, make_shared<ifstream>(tenant_path));
|
||||
const vector<string> &profile_ids =
|
||||
tenant_mananger ? tenant_mananger->fetchProfileIds(tenant) : vector<string>();
|
||||
for (auto &profile_id : profile_ids) {
|
||||
auto tenant_path = getPolicyConfigPath(config_file.first, type, tenant, profile_id);
|
||||
files.emplace(tenant_path, make_shared<ifstream>(tenant_path));
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
for (const string &tenant : active_tenants) {
|
||||
const vector<string> &profile_ids =
|
||||
tenant_mananger ? tenant_mananger->fetchProfileIds(tenant) : vector<string>();
|
||||
for (auto &profile_id : profile_ids) {
|
||||
string settings_path = config_directory_path + "tenant_" + tenant + "_" + profile_id + "_settings.json";
|
||||
files.emplace(settings_path, make_shared<ifstream>(settings_path));
|
||||
}
|
||||
}
|
||||
|
||||
vector<shared_ptr<JSONInputArchive>> archives;
|
||||
for (const auto &file : files) {
|
||||
if (file.second->is_open()) {
|
||||
dbgDebug(D_CONFIG) << "Succesfully opened configuration file. File: " << file.first;
|
||||
archives.push_back(make_shared<JSONInputArchive>(*file.second));
|
||||
} else {
|
||||
dbgDebug(D_CONFIG) << "Could not open configuration file. Path: " << file.first;
|
||||
|
||||
@@ -84,9 +84,9 @@ getLogFilesPathConfig()
|
||||
}
|
||||
|
||||
string
|
||||
getPolicyConfigPath(const string &name, ConfigFileType type, const string &tenant)
|
||||
getPolicyConfigPath(const string &name, ConfigFileType type, const string &tenant, const string &profile)
|
||||
{
|
||||
return Singleton::Consume<I_Config>::from<MockConfigProvider>()->getPolicyConfigPath(name, type, tenant);
|
||||
return Singleton::Consume<I_Config>::from<MockConfigProvider>()->getPolicyConfigPath(name, type, tenant, profile);
|
||||
}
|
||||
|
||||
void
|
||||
|
||||
@@ -200,8 +200,8 @@ fromStringToNumeric(const string &value_str, const string &name, const int max_v
|
||||
}
|
||||
return static_cast<Num>(value);
|
||||
} catch (const invalid_argument &e) {
|
||||
dbgError(D_CONFIG) << name << " resived is invalid. Error: " << e.what();
|
||||
return genError(name + " recived is invalid. Error: " + e.what());
|
||||
dbgError(D_CONFIG) << name << " received is invalid. Error: " << e.what();
|
||||
return genError(name + " received is invalid. Error: " + e.what());
|
||||
}
|
||||
return genError("Error in creating numeric value of " + name);
|
||||
}
|
||||
@@ -233,7 +233,7 @@ ConnKeyUtil::fromString(const string &ip_str, IPAddr &ip_address)
|
||||
{
|
||||
Maybe<IPAddr> ip_addr = IPAddr::createIPAddr(ip_str);
|
||||
if (!ip_addr.ok()) {
|
||||
dbgError(D_CONFIG) << "Ip address resived is invalid: " << ip_addr.getErr();
|
||||
dbgError(D_CONFIG) << "Ip address received is invalid: " << ip_addr.getErr();
|
||||
return false;
|
||||
}
|
||||
ip_address = ip_addr.unpack();
|
||||
|
||||
@@ -124,7 +124,7 @@ cptestGenerateHex(const std::vector<u_char> &vec, bool print_offsets)
|
||||
std::string
|
||||
cptestFnameInExeDir(const std::string &name)
|
||||
{
|
||||
auto bin_path = ::testing::internal::GetArgvs()[0]; // Internal ugly API.
|
||||
auto const &bin_path = ::testing::internal::GetArgvs()[0]; // Internal ugly API.
|
||||
auto slash = bin_path.rfind('/');
|
||||
if (slash==string::npos) {
|
||||
// bin_path contains no dir. So return name with no dir
|
||||
|
||||
@@ -245,9 +245,6 @@ DebugFogStream::finishMessage()
|
||||
if (team.ok()) audience_team = *team;
|
||||
}
|
||||
|
||||
string agent_uid =
|
||||
(Report::isPlaygroundEnv() ? "playground-" : "") +
|
||||
Singleton::Consume<I_AgentDetails>::by<DebugFogStream>()->getAgentId();
|
||||
Report message_to_fog(
|
||||
"Debug message",
|
||||
curr_time,
|
||||
@@ -259,7 +256,7 @@ DebugFogStream::finishMessage()
|
||||
getSeverity(),
|
||||
Priority::LOW,
|
||||
chrono::seconds(0),
|
||||
LogField("agentId", agent_uid),
|
||||
LogField("agentId", Singleton::Consume<I_AgentDetails>::by<DebugFogStream>()->getAgentId()),
|
||||
LogField("issuingFunction", func_name),
|
||||
LogField("issuingFile", file_name),
|
||||
LogField("issuingLine", line),
|
||||
@@ -331,9 +328,6 @@ DebugFogStream::handleThresholdReach()
|
||||
if (team.ok()) audience_team = *team;
|
||||
}
|
||||
|
||||
string agent_uid =
|
||||
(Report::isPlaygroundEnv() ? "playground-" : "") +
|
||||
Singleton::Consume<I_AgentDetails>::by<DebugFogStream>()->getAgentId();
|
||||
Report message_to_fog(
|
||||
"Debug message",
|
||||
curr_time,
|
||||
@@ -345,7 +339,7 @@ DebugFogStream::handleThresholdReach()
|
||||
Severity::MEDIUM,
|
||||
Priority::LOW,
|
||||
chrono::seconds(0),
|
||||
LogField("agentId", agent_uid),
|
||||
LogField("agentId", Singleton::Consume<I_AgentDetails>::by<DebugFogStream>()->getAgentId()),
|
||||
LogField("issuingFunction", __FUNCTION__),
|
||||
LogField("issuingFile", "debug_streams.cc"),
|
||||
LogField("issuingLine", __LINE__),
|
||||
|
||||
@@ -35,6 +35,9 @@ class Encryptor::Impl : Singleton::Provide<I_Encryptor>::From<Encryptor>
|
||||
// Obfuscating
|
||||
string obfuscateXor(const string &input) override;
|
||||
string obfuscateXorBase64(const string &input) override;
|
||||
|
||||
|
||||
private:
|
||||
};
|
||||
|
||||
string
|
||||
@@ -68,6 +71,7 @@ Encryptor::Impl::obfuscateXorBase64(const string &input)
|
||||
return base64Encode(obfuscated);
|
||||
}
|
||||
|
||||
|
||||
void
|
||||
Encryptor::preload()
|
||||
{
|
||||
|
||||
@@ -83,3 +83,4 @@ TEST_F(EncryptorTest, XORBase64Encrypt)
|
||||
i_encryptor->obfuscateXorBase64(string("\x0b\x2d\x29\x2f\x24\x70\x18\x26\x3c\x38\x27\x69")), "SGVsbG8gV29ybGQh"
|
||||
);
|
||||
}
|
||||
|
||||
|
||||
@@ -42,8 +42,8 @@ public:
|
||||
|
||||
void preload();
|
||||
|
||||
void setActiveTenant(const string &tenant_id) override;
|
||||
void unsetActiveTenant() override;
|
||||
void setActiveTenantAndProfile(const string &tenant_id, const string &profile_id) override;
|
||||
void unsetActiveTenantAndProfile() override;
|
||||
|
||||
void registerContext(Context *ptr) override;
|
||||
void unregisterContext(Context *ptr) override;
|
||||
@@ -145,17 +145,19 @@ Environment::Impl::fini()
|
||||
}
|
||||
|
||||
void
|
||||
Environment::Impl::setActiveTenant(const string &tenant_id)
|
||||
Environment::Impl::setActiveTenantAndProfile(const string &tenant_id, const string &profile_id)
|
||||
{
|
||||
if (tenant_manager == nullptr) tenant_manager = Singleton::Consume<I_TenantManager>::by<Environment>();
|
||||
tenant_manager->addActiveTenant(tenant_id);
|
||||
tenant_manager->addActiveTenantAndProfile(tenant_id, profile_id);
|
||||
registerValue<string>("ActiveTenantId", tenant_id);
|
||||
registerValue<string>("ActiveProfileId", profile_id);
|
||||
}
|
||||
|
||||
void
|
||||
Environment::Impl::unsetActiveTenant()
|
||||
Environment::Impl::unsetActiveTenantAndProfile()
|
||||
{
|
||||
getConfigurationContext().unregisterKey<string>("ActiveTenantId");
|
||||
getConfigurationContext().unregisterKey<string>("ActiveProfileId");
|
||||
}
|
||||
|
||||
map<string, string>
|
||||
|
||||
@@ -23,6 +23,7 @@ enum AttachmentType
|
||||
{
|
||||
NGINX_ATT_ID,
|
||||
PRELOAD_ATT_ID,
|
||||
SQUID_ATT_ID,
|
||||
#ifdef __cplusplus
|
||||
COUNT
|
||||
#endif
|
||||
|
||||
@@ -53,6 +53,10 @@ enum DccpPacketType {
|
||||
DCCP_PKT_INVALID,
|
||||
};
|
||||
|
||||
struct net_device {
|
||||
int ifindex;
|
||||
};
|
||||
|
||||
struct sk_buff {
|
||||
uint16_t protocol;
|
||||
union {
|
||||
@@ -67,10 +71,13 @@ struct sk_buff {
|
||||
struct sctphdr *sctp_header;
|
||||
struct dccphdr *dccp_header;
|
||||
} transport_header;
|
||||
unsigned char *tail;
|
||||
unsigned char *data;
|
||||
unsigned char *head;
|
||||
unsigned int len;
|
||||
unsigned char *tail;
|
||||
unsigned char *data;
|
||||
unsigned char *head;
|
||||
unsigned int len;
|
||||
struct sock *sk;
|
||||
void (*destructor)(struct sk_buff *);
|
||||
struct net_device *dev;
|
||||
};
|
||||
|
||||
struct geneve_opt {
|
||||
|
||||
@@ -32,13 +32,6 @@ class I_Encryptor;
|
||||
class I_AgentDetails;
|
||||
class I_SignalHandler;
|
||||
|
||||
namespace Config
|
||||
{
|
||||
enum class Errors;
|
||||
}
|
||||
|
||||
std::ostream & operator<<(std::ostream &os, const Config::Errors &err);
|
||||
|
||||
class Debug
|
||||
:
|
||||
Singleton::Consume<I_TimeGet>,
|
||||
|
||||
103
core/include/general/tenant_profile_pair.h
Normal file
103
core/include/general/tenant_profile_pair.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 __TENANT_PROFILE_PAIR_H__
|
||||
#define __TENANT_PROFILE_PAIR_H__
|
||||
|
||||
#include <string>
|
||||
|
||||
#include "hash_combine.h"
|
||||
|
||||
class TenantProfilePair
|
||||
{
|
||||
public:
|
||||
TenantProfilePair(const std::string &_tenant_id, const std::string &_profile_id)
|
||||
:
|
||||
tenant_id(_tenant_id),
|
||||
profile_id(_profile_id)
|
||||
{
|
||||
}
|
||||
|
||||
size_t
|
||||
hash() const
|
||||
{
|
||||
size_t seed = 0;
|
||||
hashCombine(seed, tenant_id);
|
||||
hashCombine(seed, profile_id);
|
||||
return seed;
|
||||
}
|
||||
|
||||
bool
|
||||
operator==(const TenantProfilePair &other) const
|
||||
{
|
||||
return (tenant_id == other.tenant_id && profile_id == other.profile_id);
|
||||
}
|
||||
|
||||
bool
|
||||
operator>(const TenantProfilePair &other) const
|
||||
{
|
||||
if (tenant_id > other.tenant_id) {
|
||||
return true;
|
||||
} else if (tenant_id == other.tenant_id && profile_id > other.profile_id) {
|
||||
return true;
|
||||
}
|
||||
return false;
|
||||
}
|
||||
|
||||
bool
|
||||
operator<(const TenantProfilePair &other) const
|
||||
{
|
||||
return !(*this >= other);
|
||||
}
|
||||
|
||||
bool
|
||||
operator>=(const TenantProfilePair &other) const
|
||||
{
|
||||
return (*this > other) || (*this == other);
|
||||
}
|
||||
|
||||
bool
|
||||
operator<=(const TenantProfilePair &other) const
|
||||
{
|
||||
return !(*this > other);
|
||||
}
|
||||
|
||||
std::string
|
||||
getTenantId() const
|
||||
{
|
||||
return tenant_id;
|
||||
}
|
||||
|
||||
std::string
|
||||
getPfofileId() const
|
||||
{
|
||||
return profile_id;
|
||||
}
|
||||
|
||||
private:
|
||||
std::string tenant_id;
|
||||
std::string profile_id;
|
||||
};
|
||||
|
||||
namespace std
|
||||
{
|
||||
|
||||
template <>
|
||||
struct hash<TenantProfilePair>
|
||||
{
|
||||
size_t operator()(const TenantProfilePair &tenant_profile) const { return tenant_profile.hash(); }
|
||||
};
|
||||
|
||||
}
|
||||
|
||||
#endif // __TENANT_PROFILE_PAIR_H__
|
||||
@@ -37,6 +37,7 @@ public:
|
||||
virtual std::string obfuscateXor(const std::string &input) = 0;
|
||||
virtual std::string obfuscateXorBase64(const std::string &input) = 0;
|
||||
|
||||
|
||||
protected:
|
||||
virtual ~I_Encryptor() {}
|
||||
};
|
||||
|
||||
@@ -74,8 +74,8 @@ public:
|
||||
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 void setActiveTenantAndProfile(const std::string &tenant_id, const std::string &profile_id = "") = 0;
|
||||
virtual void unsetActiveTenantAndProfile() = 0;
|
||||
|
||||
virtual std::string getCurrentTrace() const = 0;
|
||||
virtual std::string getCurrentSpan() const = 0;
|
||||
|
||||
@@ -69,6 +69,44 @@ public:
|
||||
return intelligence_query.getData();
|
||||
}
|
||||
|
||||
template<typename Data>
|
||||
Maybe<std::vector<Maybe<std::vector<AssetReply<Data>>>>>
|
||||
queryIntelligence(std::vector<QueryRequest> &query_requests)
|
||||
{
|
||||
static const uint upper_assets_limit = 50;
|
||||
static const uint upper_confidence_limit = 1000;
|
||||
for (QueryRequest &query_request : query_requests) {
|
||||
uint assets_limit = query_request.getAssetsLimit();
|
||||
if (assets_limit == 0 || assets_limit > upper_assets_limit) {
|
||||
dbgTrace(D_INTELLIGENCE)
|
||||
<< "Assets limit for request is "
|
||||
<< upper_assets_limit
|
||||
<< ", requests assets: "
|
||||
<< assets_limit;
|
||||
return genError("Assets limit valid range is of [1, " + std::to_string(upper_assets_limit) + "]");
|
||||
}
|
||||
|
||||
bool min_conf_res = query_request.checkMinConfidence(upper_confidence_limit);
|
||||
if (!min_conf_res) {
|
||||
dbgTrace(D_INTELLIGENCE) << "Illegal confidence value";
|
||||
return genError(
|
||||
"Minimum confidence value valid range is of [1, " + std::to_string(upper_confidence_limit) + "]"
|
||||
);
|
||||
}
|
||||
}
|
||||
IntelligenceQuery<Data> intelligence_query(query_requests);
|
||||
static const std::string query_uri = "/api/v2/intelligence/assets/queries";
|
||||
|
||||
dbgTrace(D_INTELLIGENCE) << "Sending intelligence bulk request with " << query_requests.size() << " items";
|
||||
bool res = getIsOfflineOnly() ? false : sendQueryObject(intelligence_query, query_uri, upper_assets_limit);
|
||||
if (!res) {
|
||||
dbgTrace(D_INTELLIGENCE) << "Could not message fog, bulk request failed.";
|
||||
return genError("Could not query intelligence");
|
||||
}
|
||||
|
||||
return intelligence_query.getBulkData();
|
||||
}
|
||||
|
||||
private:
|
||||
template<typename Data>
|
||||
bool
|
||||
@@ -138,7 +176,7 @@ private:
|
||||
std::chrono::seconds seconds_since_start = std::chrono::seconds(0);
|
||||
std::chrono::seconds seconds_since_last_lap = std::chrono::seconds(0);
|
||||
|
||||
bool res= true;
|
||||
bool res = true;
|
||||
while (res &&
|
||||
intelligence_query.getResponseStatus() == ResponseStatus::IN_PROGRESS &&
|
||||
seconds_since_start < request_overall_timeout &&
|
||||
|
||||
@@ -92,8 +92,9 @@ public:
|
||||
auto res_json = obj.loadJson(res.unpack());
|
||||
if (!res_json) {
|
||||
dbgWarning(D_COMMUNICATION) << "Failed to parse response body. Content: " << res.unpack();
|
||||
} else {
|
||||
dbgTrace(D_COMMUNICATION) << "Successfully parsed response body";
|
||||
}
|
||||
dbgTrace(D_COMMUNICATION) << "Successfully parsed response body";
|
||||
return res_json;
|
||||
}
|
||||
|
||||
|
||||
@@ -25,22 +25,30 @@ 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 bool areTenantAndProfileActive(const std::string &tenant_id, const std::string &profile_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 std::vector<std::string> fetchAllActiveTenants() const = 0;
|
||||
virtual std::vector<std::string> getInstances(
|
||||
const std::string &tenant_id,
|
||||
const std::string &profile_id
|
||||
) const = 0;
|
||||
virtual std::vector<std::string> fetchProfileIds(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, const std::string &profile_id) = 0;
|
||||
|
||||
virtual void deactivateTenant(const std::string &tenant_id) = 0;
|
||||
virtual void deactivateTenants(const std::vector<std::string> &tenants_id) = 0;
|
||||
virtual void addActiveTenantAndProfile(const std::string &tenant_id, const std::string &profile_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;
|
||||
friend class LoadNewTenantsAndProfiles;
|
||||
virtual void addInstance(
|
||||
const std::string &tenant_id,
|
||||
const std::string &profile_id,
|
||||
const std::string &instace_id
|
||||
) = 0;
|
||||
|
||||
protected:
|
||||
virtual ~I_TenantManager() {}
|
||||
|
||||
@@ -38,8 +38,10 @@ SerializableAssetSource<UserSerializableReplyAttr>::load(cereal::JSONInputArchiv
|
||||
UserSerializableReplyAttr raw_attribute;
|
||||
try {
|
||||
ar(cereal::make_nvp("attributes", raw_attribute));
|
||||
attributes.clear();
|
||||
attributes.push_back(raw_attribute);
|
||||
} catch(const std::exception &e) {}
|
||||
attributes.push_back(raw_attribute);
|
||||
|
||||
}
|
||||
|
||||
#endif //__ASSET_SOURCE_V2_IMPL_H__
|
||||
|
||||
@@ -0,0 +1,94 @@
|
||||
// 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 __BULK_QUERY_RESPONSE_V2_H__
|
||||
#define __BULK_QUERY_RESPONSE_V2_H__
|
||||
|
||||
#include <sstream>
|
||||
#include <vector>
|
||||
#include <string>
|
||||
|
||||
#include "cereal/archives/json.hpp"
|
||||
#include "cereal/types/vector.hpp"
|
||||
|
||||
#include "debug.h"
|
||||
#include "intelligence_types_v2.h"
|
||||
|
||||
USE_DEBUG_FLAG(D_INTELLIGENCE);
|
||||
|
||||
class BulkResponseError
|
||||
{
|
||||
public:
|
||||
void
|
||||
serialize(cereal::JSONInputArchive &ar)
|
||||
{
|
||||
ar(
|
||||
cereal::make_nvp("index", index),
|
||||
cereal::make_nvp("statusCode", status_code),
|
||||
cereal::make_nvp("message", message)
|
||||
);
|
||||
}
|
||||
|
||||
unsigned int getIndex() const { return index; }
|
||||
int getStatusCode() const { return status_code; }
|
||||
const std::string & getMessage() const { return message; }
|
||||
|
||||
private:
|
||||
unsigned int index;
|
||||
int status_code;
|
||||
std::string message;
|
||||
};
|
||||
|
||||
template <typename UserSerializableReplyAttr>
|
||||
class ValidBulkQueryResponse
|
||||
{
|
||||
public:
|
||||
void
|
||||
serialize(cereal::JSONInputArchive &ar)
|
||||
{
|
||||
ar(
|
||||
cereal::make_nvp("index", index),
|
||||
cereal::make_nvp("response", response)
|
||||
);
|
||||
}
|
||||
|
||||
unsigned int getIndex() const { return index; }
|
||||
const IntelligenceQueryResponse<UserSerializableReplyAttr> & getResponse() const { return response; }
|
||||
|
||||
private:
|
||||
unsigned int index;
|
||||
IntelligenceQueryResponse<UserSerializableReplyAttr> response;
|
||||
};
|
||||
|
||||
template <typename UserSerializableReplyAttr>
|
||||
class IntelligenceQueryBulkResponse
|
||||
{
|
||||
public:
|
||||
void
|
||||
serialize(cereal::JSONInputArchive &ar)
|
||||
{
|
||||
ar(cereal::make_nvp("queriesResponse", valid_responses));
|
||||
try {
|
||||
ar(cereal::make_nvp("errors", errors));
|
||||
} catch(...) {}
|
||||
}
|
||||
|
||||
const std::vector<ValidBulkQueryResponse<UserSerializableReplyAttr>> & getValid() { return valid_responses; }
|
||||
const std::vector<BulkResponseError> & getErrors() { return errors; }
|
||||
|
||||
private:
|
||||
std::vector<ValidBulkQueryResponse<UserSerializableReplyAttr>> valid_responses;
|
||||
std::vector<BulkResponseError> errors;
|
||||
};
|
||||
|
||||
#endif // __BULK_QUERY_RESPONSE_V2_H__
|
||||
@@ -14,10 +14,13 @@
|
||||
#ifndef __INTELLIGENCE_QUERY_V2_H__
|
||||
#define __INTELLIGENCE_QUERY_V2_H__
|
||||
|
||||
#include<vector>
|
||||
|
||||
#include "cereal/archives/json.hpp"
|
||||
#include "intelligence_types_v2.h"
|
||||
#include "query_request_v2.h"
|
||||
#include "query_response_v2.h"
|
||||
#include "bulk_query_response_v2.h"
|
||||
#include "rest.h"
|
||||
|
||||
template <typename UserSerializableReplyAttr>
|
||||
@@ -27,7 +30,17 @@ public:
|
||||
IntelligenceQuery(QueryRequest &filter)
|
||||
:
|
||||
request(filter),
|
||||
response()
|
||||
response(),
|
||||
responses(),
|
||||
is_bulk(false)
|
||||
{}
|
||||
|
||||
IntelligenceQuery(std::vector<QueryRequest> &filters)
|
||||
:
|
||||
requests(filters),
|
||||
response(),
|
||||
responses(),
|
||||
is_bulk(true)
|
||||
{}
|
||||
|
||||
Maybe<std::string> genJson() const;
|
||||
@@ -37,7 +50,8 @@ public:
|
||||
void save(cereal::JSONOutputArchive &ar) const;
|
||||
|
||||
std::vector<AssetReply<UserSerializableReplyAttr>> getData();
|
||||
ResponseStatus getResponseStatus() { return response.getResponseStatus(); }
|
||||
std::vector<Maybe<std::vector<AssetReply<UserSerializableReplyAttr>>>> getBulkData();
|
||||
ResponseStatus getResponseStatus();
|
||||
int getResponseAssetCollectionsSize() const { return response.getAssetCollectionsSize(); }
|
||||
const std::string & getResponseCursorVal() const { return response.getCursor(); }
|
||||
|
||||
@@ -46,8 +60,13 @@ public:
|
||||
void setRequestCursor(CursorState state, const std::string &value);
|
||||
|
||||
private:
|
||||
QueryRequest &request;
|
||||
static QueryRequest dummy_query_request;
|
||||
static std::vector<QueryRequest> dummy_query_requests;
|
||||
std::vector<QueryRequest> &requests = dummy_query_requests;
|
||||
QueryRequest &request = dummy_query_request;
|
||||
IntelligenceQueryResponse<UserSerializableReplyAttr> response;
|
||||
std::vector<IntelligenceQueryResponse<UserSerializableReplyAttr>> responses;
|
||||
bool is_bulk;
|
||||
};
|
||||
|
||||
#include "intelligence_query_v2_impl.h"
|
||||
|
||||
@@ -20,6 +20,13 @@
|
||||
|
||||
USE_DEBUG_FLAG(D_INTELLIGENCE);
|
||||
|
||||
template <typename UserSerializableReplyAttr>
|
||||
QueryRequest IntelligenceQuery<UserSerializableReplyAttr>::dummy_query_request = QueryRequest();
|
||||
|
||||
template <typename UserSerializableReplyAttr>
|
||||
std::vector<QueryRequest> IntelligenceQuery<UserSerializableReplyAttr>::dummy_query_requests =
|
||||
std::vector<QueryRequest>();
|
||||
|
||||
template <typename UserSerializableReplyAttr>
|
||||
Maybe<std::string>
|
||||
IntelligenceQuery<UserSerializableReplyAttr>::genJson() const
|
||||
@@ -28,7 +35,16 @@ IntelligenceQuery<UserSerializableReplyAttr>::genJson() const
|
||||
std::stringstream out;
|
||||
{
|
||||
cereal::JSONOutputArchive out_ar(out);
|
||||
request.saveToJson(out_ar);
|
||||
if (is_bulk) {
|
||||
std::vector<BulkQueryRequest> bulk_requests;
|
||||
int index = 0;
|
||||
for (QueryRequest &request : requests) {
|
||||
bulk_requests.push_back(BulkQueryRequest(request, index++));
|
||||
}
|
||||
out_ar(cereal::make_nvp("queries", bulk_requests));
|
||||
} else {
|
||||
request.saveToJson(out_ar);
|
||||
}
|
||||
}
|
||||
return out.str();
|
||||
}
|
||||
@@ -58,14 +74,45 @@ template <typename UserSerializableReplyAttr>
|
||||
void
|
||||
IntelligenceQuery<UserSerializableReplyAttr>::load(cereal::JSONInputArchive &ar)
|
||||
{
|
||||
response.loadFromJson(ar);
|
||||
if (is_bulk) {
|
||||
IntelligenceQueryBulkResponse<UserSerializableReplyAttr> bulk_response;
|
||||
bulk_response.serialize(ar);
|
||||
unsigned int error_idx = 0;
|
||||
unsigned int valid_idx = 0;
|
||||
const auto &valid_response = bulk_response.getValid();
|
||||
const auto &errors = bulk_response.getErrors();
|
||||
responses.reserve(requests.size());
|
||||
dbgTrace(D_INTELLIGENCE) << "Received response for bulk request with " << requests.size() << " items";
|
||||
for (unsigned int query_idx = 0; query_idx < requests.size(); query_idx++) {
|
||||
if (valid_response[valid_idx].getIndex() == query_idx) {
|
||||
responses.push_back(valid_response[valid_idx].getResponse());
|
||||
dbgTrace(D_INTELLIGENCE) << "Item #" << query_idx << " is valid";
|
||||
valid_idx++;
|
||||
} else if (error_idx < errors.size() && errors[error_idx].getIndex() == query_idx) {
|
||||
responses.emplace_back();
|
||||
responses[query_idx].setFailInBulk();
|
||||
dbgTrace(D_INTELLIGENCE) << "Item #" << query_idx << " is invalid";
|
||||
error_idx++;
|
||||
} else {
|
||||
dbgWarning(D_INTELLIGENCE)
|
||||
<< "Query index was not found neither in valid nor error responses, assuming error";
|
||||
responses[query_idx].setFailInBulk();
|
||||
}
|
||||
}
|
||||
} else {
|
||||
response.loadFromJson(ar);
|
||||
}
|
||||
}
|
||||
|
||||
template <typename UserSerializableReplyAttr>
|
||||
void
|
||||
IntelligenceQuery<UserSerializableReplyAttr>::save(cereal::JSONOutputArchive &ar) const
|
||||
{
|
||||
request.saveToJson(ar);
|
||||
if (!is_bulk) {
|
||||
request.saveToJson(ar);
|
||||
} else {
|
||||
ar(cereal::make_nvp("queries", requests));
|
||||
}
|
||||
}
|
||||
|
||||
template <typename UserSerializableReplyAttr>
|
||||
@@ -75,6 +122,27 @@ IntelligenceQuery<UserSerializableReplyAttr>::getData()
|
||||
return response.getData();
|
||||
}
|
||||
|
||||
template <typename UserSerializableReplyAttr>
|
||||
std::vector<Maybe<std::vector<AssetReply<UserSerializableReplyAttr>>>>
|
||||
IntelligenceQuery<UserSerializableReplyAttr>::getBulkData()
|
||||
{
|
||||
std::vector<Maybe<std::vector<AssetReply<UserSerializableReplyAttr>>>> bulk_data;
|
||||
bulk_data.reserve(responses.size());
|
||||
int index = 0;
|
||||
for (const auto &res: responses) {
|
||||
if (!res.isValidInBulk()) {
|
||||
dbgTrace(D_INTELLIGENCE) << "Request #" << index << " in bulk failed";
|
||||
bulk_data.push_back(genError("Received error for request in bulk"));
|
||||
index++;
|
||||
} else {
|
||||
dbgTrace(D_INTELLIGENCE) << "Request #" << index << " in bulk received valid response";
|
||||
bulk_data.push_back(res.getData());
|
||||
index++;
|
||||
}
|
||||
}
|
||||
return bulk_data;
|
||||
}
|
||||
|
||||
template <typename UserSerializableReplyAttr>
|
||||
void
|
||||
IntelligenceQuery<UserSerializableReplyAttr>::activatePaging()
|
||||
@@ -86,10 +154,27 @@ template <typename UserSerializableReplyAttr>
|
||||
Maybe<Intelligence_IS_V2::CursorState>
|
||||
IntelligenceQuery<UserSerializableReplyAttr>::getPagingStatus()
|
||||
{
|
||||
if (is_bulk) return genError("Paging not activated in bulk mode");
|
||||
if (!request.isPagingActivated()) return genError("Paging not activated");
|
||||
return request.getCursorState();
|
||||
}
|
||||
|
||||
template <typename UserSerializableReplyAttr>
|
||||
ResponseStatus
|
||||
IntelligenceQuery<UserSerializableReplyAttr>::getResponseStatus()
|
||||
{
|
||||
if (!is_bulk) return response.getResponseStatus();
|
||||
|
||||
if (responses.size() == 0) return ResponseStatus::IN_PROGRESS;
|
||||
for (const auto &response_itr : responses) {
|
||||
if (response_itr.isValidInBulk() && response_itr.getResponseStatus() == ResponseStatus::IN_PROGRESS) {
|
||||
return ResponseStatus::IN_PROGRESS;
|
||||
}
|
||||
}
|
||||
|
||||
return ResponseStatus::DONE;
|
||||
}
|
||||
|
||||
template <typename UserSerializableReplyAttr>
|
||||
void
|
||||
IntelligenceQuery<UserSerializableReplyAttr>::setRequestCursor(CursorState state, const std::string &value)
|
||||
|
||||
@@ -38,6 +38,7 @@ public:
|
||||
);
|
||||
|
||||
void saveToJson(cereal::JSONOutputArchive &ar) const;
|
||||
void save(cereal::JSONOutputArchive &ar) const;
|
||||
|
||||
uint getAssetsLimit() const;
|
||||
const SerializableQueryFilter & getQuery() const;
|
||||
@@ -89,4 +90,21 @@ private:
|
||||
QueryRequest calcQueryRequestOperator(const QueryRequest &other_query, const Operator &operator_type);
|
||||
};
|
||||
|
||||
class BulkQueryRequest
|
||||
{
|
||||
public:
|
||||
BulkQueryRequest() {}
|
||||
|
||||
BulkQueryRequest(QueryRequest &request, int index);
|
||||
|
||||
void saveToJson(cereal::JSONOutputArchive &ar) const;
|
||||
void save(cereal::JSONOutputArchive &ar) const;
|
||||
|
||||
QueryRequest getQueryRequest() const;
|
||||
|
||||
private:
|
||||
QueryRequest request;
|
||||
int index;
|
||||
};
|
||||
|
||||
#endif // __QUERY_REQUEST_V2_H__
|
||||
|
||||
@@ -102,17 +102,23 @@ public:
|
||||
|
||||
void loadFromJson(cereal::JSONInputArchive &ar);
|
||||
|
||||
template<class Archive>
|
||||
void serialize(Archive &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;
|
||||
bool isValidInBulk() const;
|
||||
void setFailInBulk();
|
||||
|
||||
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;
|
||||
bool partial_fail_in_bulk = false;
|
||||
};
|
||||
|
||||
#include "query_response_v2_impl.h"
|
||||
|
||||
@@ -100,6 +100,24 @@ IntelligenceQueryResponse<UserSerializableReplyAttr>::loadFromJson(cereal::JSONI
|
||||
} catch(...) {}
|
||||
}
|
||||
|
||||
template<typename UserSerializableReplyAttr>
|
||||
template<class Archive>
|
||||
void
|
||||
IntelligenceQueryResponse<UserSerializableReplyAttr>::serialize(Archive &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
|
||||
@@ -135,4 +153,18 @@ IntelligenceQueryResponse<UserSerializableReplyAttr>::getData() const
|
||||
return asset_collections;
|
||||
}
|
||||
|
||||
template <typename UserSerializableReplyAttr>
|
||||
bool
|
||||
IntelligenceQueryResponse<UserSerializableReplyAttr>::isValidInBulk() const
|
||||
{
|
||||
return !partial_fail_in_bulk;
|
||||
}
|
||||
|
||||
template <typename UserSerializableReplyAttr>
|
||||
void
|
||||
IntelligenceQueryResponse<UserSerializableReplyAttr>::setFailInBulk()
|
||||
{
|
||||
partial_fail_in_bulk = true;
|
||||
}
|
||||
|
||||
#endif // __QUERY_RESPONSE_V2_IMPL_H_
|
||||
|
||||
@@ -15,11 +15,6 @@ public:
|
||||
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 &));
|
||||
|
||||
};
|
||||
|
||||
|
||||
@@ -14,36 +14,37 @@ operator<<(std::ostream &os, const Maybe<std::string, Context::Error> &)
|
||||
class MockEnvironment : public Singleton::Provide<I_Environment>::From<MockProvider<I_Environment>>
|
||||
{
|
||||
public:
|
||||
MOCK_METHOD0 (getConfigurationContext, Context &());
|
||||
MOCK_CONST_METHOD0(getActiveContexts, const ActiveContexts &());
|
||||
MOCK_METHOD0 (getConfigurationContext, Context &());
|
||||
MOCK_CONST_METHOD0(getActiveContexts, const ActiveContexts &());
|
||||
|
||||
MOCK_METHOD1 (setActiveTenant, void(const std::string &));
|
||||
MOCK_METHOD0 (unsetActiveTenant, void());
|
||||
MOCK_METHOD2 (setActiveTenantAndProfile, void(const std::string &, const std::string &));
|
||||
MOCK_METHOD0 (unsetActiveTenantAndProfile, void());
|
||||
|
||||
MOCK_METHOD1 (registerContext, void(Context *));
|
||||
MOCK_METHOD1 (unregisterContext, void(Context *));
|
||||
MOCK_METHOD1 (registerContext, void(Context *));
|
||||
MOCK_METHOD1 (unregisterContext, void(Context *));
|
||||
|
||||
MOCK_METHOD0 (createEnvironment, ActiveContexts());
|
||||
MOCK_METHOD0 (saveEnvironment, ActiveContexts());
|
||||
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 &));
|
||||
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 &));
|
||||
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 &));
|
||||
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__
|
||||
|
||||
@@ -13,22 +13,26 @@
|
||||
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_METHOD1(uponNewTenants, void(const I_TenantManager::newTenantCB &cb));
|
||||
|
||||
MOCK_CONST_METHOD0(fetchActiveTenants, std::vector<std::string>());
|
||||
MOCK_CONST_METHOD1(getInstances, std::vector<std::string>(const std::string &));
|
||||
MOCK_CONST_METHOD0(fetchActiveTenants, std::vector<std::string>());
|
||||
MOCK_CONST_METHOD0(fetchAllActiveTenants, std::vector<std::string>());
|
||||
MOCK_CONST_METHOD1(fetchProfileIds, std::vector<std::string>(const std::string &));
|
||||
MOCK_CONST_METHOD2(
|
||||
getInstances,
|
||||
std::vector<std::string>(const std::string &, const std::string &)
|
||||
);
|
||||
MOCK_CONST_METHOD2(areTenantAndProfileActive, bool(const std::string &, const std::string &));
|
||||
MOCK_METHOD2(addActiveTenantAndProfile, void(const std::string &, const std::string &));
|
||||
MOCK_METHOD2(deactivateTenant, void(const 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());
|
||||
MOCK_CONST_METHOD0(getTimeoutVal, std::chrono::microseconds());
|
||||
|
||||
private:
|
||||
MOCK_METHOD2(addInstance, void(const std::string &, const std::string &));
|
||||
MOCK_METHOD3(
|
||||
addInstance,
|
||||
void(const std::string &, const std::string &, const std::string &)
|
||||
);
|
||||
};
|
||||
|
||||
#endif // __MOCK_TENANT_MANAGER_H__
|
||||
|
||||
@@ -91,7 +91,11 @@ std::string getConfigurationFlagWithDefault(const std::string &default_val, cons
|
||||
const std::string & getFilesystemPathConfig();
|
||||
const std::string & getLogFilesPathConfig();
|
||||
|
||||
std::string getPolicyConfigPath(const std::string &name, Config::ConfigFileType type, const std::string &tenant = "");
|
||||
std::string getPolicyConfigPath(
|
||||
const std::string &name,
|
||||
Config::ConfigFileType type,
|
||||
const std::string &tenant = "",
|
||||
const std::string &profile = "");
|
||||
|
||||
void registerExpectedConfigFile(const std::string &config_name, Config::ConfigFileType type);
|
||||
|
||||
|
||||
@@ -50,7 +50,11 @@ public:
|
||||
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 string getPolicyConfigPath(
|
||||
const string &policy,
|
||||
ConfigFileType type,
|
||||
const string &tenant,
|
||||
const string &profile) 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;
|
||||
|
||||
@@ -32,6 +32,7 @@ DEFINE_FLAG(D_INFRA, D_ALL)
|
||||
DEFINE_FLAG(D_METRICS_ACCESS_CONTROL, D_METRICS)
|
||||
DEFINE_FLAG(D_MAINLOOP, D_INFRA)
|
||||
DEFINE_FLAG(D_SIGNAL_HANDLER, D_INFRA)
|
||||
DEFINE_FLAG(D_TENANT_MANAGER, D_INFRA)
|
||||
DEFINE_FLAG(D_MONITORING, D_INFRA)
|
||||
DEFINE_FLAG(D_HEALTH_CHECK_MANAGER, D_INFRA)
|
||||
DEFINE_FLAG(D_REPORT, D_INFRA)
|
||||
@@ -82,6 +83,7 @@ DEFINE_FLAG(D_COMPONENT, D_ALL)
|
||||
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_GQL, 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)
|
||||
@@ -132,21 +134,27 @@ DEFINE_FLAG(D_COMPONENT, D_ALL)
|
||||
DEFINE_FLAG(D_ERROR_REPORTER, D_REVERSE_PROXY)
|
||||
DEFINE_FLAG(D_UPSTREAM_KEEPALIVE, D_REVERSE_PROXY)
|
||||
|
||||
DEFINE_FLAG(D_IDA, D_COMPONENT)
|
||||
|
||||
DEFINE_FLAG(D_IOT_NEXT, D_COMPONENT)
|
||||
DEFINE_FLAG(D_IOT_AUXILIARY, D_IOT_NEXT)
|
||||
DEFINE_FLAG(D_IOT_REPORT_STATUS, D_IOT_AUXILIARY)
|
||||
DEFINE_FLAG(D_IOT_COLLECT_METADATA, D_IOT_AUXILIARY)
|
||||
DEFINE_FLAG(D_IOT_ENFORCE, D_IOT_NEXT)
|
||||
DEFINE_FLAG(D_IOT_ENFORCE_POLICY, D_IOT_ENFORCE)
|
||||
DEFINE_FLAG(D_IOT_ENFORCE_ASSETS, D_IOT_ENFORCE)
|
||||
DEFINE_FLAG(D_IOT_DOCTOR, 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_IOT_DISCOVERY_UTILS, D_IOT_DISCOVERY)
|
||||
DEFINE_FLAG(D_IOT_PROBE, D_IOT_DISCOVERY_UTILS)
|
||||
DEFINE_FLAG(D_IOT_ASSETS_DATA, D_IOT_DISCOVERY_UTILS)
|
||||
DEFINE_FLAG(D_IOT_INTEGRATIONS, D_IOT_DISCOVERY_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_URL_FILTERING, D_COMPONENT)
|
||||
DEFINE_FLAG(D_IOT_ACCESS_CONTROL, D_COMPONENT)
|
||||
|
||||
DEFINE_FLAG(D_FLOW, D_ALL)
|
||||
DEFINE_FLAG(D_DROP, D_FLOW)
|
||||
@@ -154,6 +162,7 @@ DEFINE_FLAG(D_FLOW, D_ALL)
|
||||
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_SQUID_ATTACHMENT, D_ATTACHMENT)
|
||||
DEFINE_FLAG(D_WLP_ATTACHMENT, D_ATTACHMENT)
|
||||
|
||||
#endif // DEFINE_FLAG
|
||||
|
||||
@@ -80,11 +80,7 @@ public:
|
||||
_severity,
|
||||
_priority,
|
||||
std::chrono::seconds(0),
|
||||
LogField(
|
||||
"agentId",
|
||||
(Report::isPlaygroundEnv() ? "playground-" : "") +
|
||||
Singleton::Consume<I_AgentDetails>::by<LogGen>()->getAgentId()
|
||||
),
|
||||
LogField("agentId", Singleton::Consume<I_AgentDetails>::by<LogGen>()->getAgentId()),
|
||||
std::forward<Args>(args)...
|
||||
)
|
||||
{
|
||||
@@ -104,11 +100,14 @@ public:
|
||||
|
||||
ReportIS::AudienceTeam getAudienceTeam() const;
|
||||
|
||||
std::string getLogInsteadOfSending();
|
||||
|
||||
private:
|
||||
std::chrono::microseconds getCurrentTime() const;
|
||||
void loadBaseLogFields();
|
||||
|
||||
Report log;
|
||||
bool send_log = true;
|
||||
};
|
||||
|
||||
#endif // __LOG_GENERATOR_H__
|
||||
|
||||
@@ -16,10 +16,6 @@
|
||||
|
||||
#include <set>
|
||||
#include <chrono>
|
||||
#include <stdlib.h>
|
||||
#include <algorithm>
|
||||
#include <cctype>
|
||||
#include <iostream>
|
||||
|
||||
#include "report/base_field.h"
|
||||
#include "report/report_enums.h"
|
||||
@@ -75,26 +71,6 @@ public:
|
||||
setInstanceAwareness();
|
||||
}
|
||||
|
||||
static bool
|
||||
isPlaygroundEnv()
|
||||
{
|
||||
std::string playground_variable = "PLAYGROUND";
|
||||
const char *env_string = getenv(playground_variable.c_str());
|
||||
|
||||
if (env_string) {
|
||||
std::string env_value = env_string;
|
||||
std::transform(
|
||||
env_value.begin(),
|
||||
env_value.end(),
|
||||
env_value.begin(),
|
||||
[](unsigned char c){ return std::tolower(c); }
|
||||
);
|
||||
return env_value == "true";
|
||||
}
|
||||
|
||||
return false;
|
||||
}
|
||||
|
||||
void serialize(cereal::JSONOutputArchive &ar) const;
|
||||
std::string getSyslog() const;
|
||||
std::string getCef() const;
|
||||
|
||||
@@ -54,6 +54,7 @@ enum class Tags {
|
||||
REVERSE_PROXY,
|
||||
HTTP_GEO_FILTER,
|
||||
FILE_UPLOAD,
|
||||
IDENTITY_AWARENESS,
|
||||
|
||||
COUNT
|
||||
};
|
||||
@@ -66,6 +67,7 @@ enum class AudienceTeam
|
||||
AGENT_INTELLIGENCE,
|
||||
CPVIEW_MONITORING,
|
||||
SIGNATURE_DEVELOPERS,
|
||||
IDENTITY_AWARENESS,
|
||||
NONE,
|
||||
|
||||
COUNT
|
||||
@@ -125,7 +127,6 @@ enum class Notification {
|
||||
POLICY_UPDATE,
|
||||
FIRST_REQUEST_FOR_ASSET,
|
||||
UPSTREAM_STATUS,
|
||||
IOT_POLICY_UPDATE,
|
||||
SYNC_LEARNING,
|
||||
SDWAN_POLICY_UPDATE,
|
||||
SDWAN_POLICY_UPDATE_ERROR,
|
||||
@@ -136,7 +137,8 @@ enum class Notification {
|
||||
enum class IssuingEngine {
|
||||
AGENT_CORE,
|
||||
IOT_NEXT,
|
||||
SDWAN
|
||||
SDWAN,
|
||||
IDA_NEXT
|
||||
};
|
||||
|
||||
} // namespace ReportIS
|
||||
|
||||
@@ -16,6 +16,8 @@ using namespace chrono;
|
||||
using namespace Intelligence_IS_V2;
|
||||
|
||||
USE_DEBUG_FLAG(D_METRICS);
|
||||
USE_DEBUG_FLAG(D_INTELLIGENCE);
|
||||
|
||||
|
||||
class IntelligenceComponentTestV2
|
||||
:
|
||||
@@ -28,6 +30,7 @@ public:
|
||||
debug_output.clear();
|
||||
Debug::setNewDefaultStdout(&debug_output);
|
||||
Debug::setUnitTestFlag(D_METRICS, Debug::DebugLevel::TRACE);
|
||||
Debug::setUnitTestFlag(D_INTELLIGENCE, Debug::DebugLevel::TRACE);
|
||||
setConfiguration<bool>(false, string("metric"), string("fogMetricSendEnable"));
|
||||
|
||||
EXPECT_CALL(
|
||||
@@ -676,3 +679,177 @@ TEST_F(IntelligenceComponentTestV2, offlineIntelligenceTest)
|
||||
EXPECT_EQ(sources_iter->getAttributes().begin()->getUser().toString(), "Max");
|
||||
EXPECT_EQ(sources_iter->getAttributes().begin()->getPhase().toString(), "offline test");
|
||||
}
|
||||
|
||||
TEST_F(IntelligenceComponentTestV2, bulkOnlineIntelligenceTest)
|
||||
{
|
||||
I_Intelligence_IS_V2 *intell = Singleton::Consume<I_Intelligence_IS_V2>::by<IntelligenceComponentTestV2>();
|
||||
vector<QueryRequest> requests;
|
||||
requests.emplace_back(Condition::EQUALS, "category", "whatever", true);
|
||||
requests.emplace_back(Condition::EQUALS, "category", "cloud", true);
|
||||
requests.emplace_back(Condition::EQUALS, "category", "nothing", true);
|
||||
requests.emplace_back(Condition::EQUALS, "category", "iot", true);
|
||||
|
||||
string response_str(
|
||||
"{\n"
|
||||
" \"errors\": [\n"
|
||||
" {\n"
|
||||
" \"index\": 0,\n"
|
||||
" \"statusCode\": 400,\n"
|
||||
" \"message\": \"Bad request. Error: Invalid cursor\"\n"
|
||||
" },"
|
||||
" {\n"
|
||||
" \"index\": 2,\n"
|
||||
" \"statusCode\": 405,\n"
|
||||
" \"message\": \"Bad request. Error: Something else\"\n"
|
||||
" }"
|
||||
" ],\n" // errors
|
||||
" \"queriesResponse\": [\n"
|
||||
" {\n"
|
||||
" \"index\": 1,\n"
|
||||
" \"response\": {\n"
|
||||
" \"assetCollections\": [\n"
|
||||
" {\n"
|
||||
" \"schemaVersion\": 1,\n"
|
||||
" \"assetType\": \"workload-cloud-ip\",\n"
|
||||
" \"assetTypeSchemaVersion\": 1,\n"
|
||||
" \"permissionType\": \"tenant\",\n"
|
||||
" \"permissionGroupId\": \"some-group-id\",\n"
|
||||
" \"name\": \"[1.1.1.1]\",\n"
|
||||
" \"class\": \"workload\",\n"
|
||||
" \"category\": \"cloud\",\n"
|
||||
" \"family\": \"ip\",\n"
|
||||
" \"group\": \"\",\n"
|
||||
" \"order\": \"\",\n"
|
||||
" \"kind\": \"\",\n"
|
||||
" \"mainAttributes\": {\n"
|
||||
" \"ipv4Addresses\": [\n"
|
||||
" \"1.1.1.1\",\n"
|
||||
" \"2.2.2.2\"\n"
|
||||
" ],\n"
|
||||
" \"phase\": \"testing\"\n"
|
||||
" },\n" // mainAttributes
|
||||
" \"sources\": [\n"
|
||||
" {\n"
|
||||
" \"tenantId\": \"175bb55c-e36f-4ac5-a7b1-7afa1229aa00\",\n"
|
||||
" \"sourceId\": \"54d7de10-7b2e-4505-955b-cc2c2c7aaa00\",\n"
|
||||
" \"assetId\": \"50255c3172b4fb7fda93025f0bfaa7abefd1\",\n"
|
||||
" \"ttl\": 120,\n"
|
||||
" \"expirationTime\": \"2020-07-29T11:21:12.253Z\",\n"
|
||||
" \"confidence\": 500,\n"
|
||||
" \"attributes\": {\n"
|
||||
" \"color\": \"red\",\n"
|
||||
" \"user\": \"Omry\",\n"
|
||||
" \"phase\": \"testing\",\n"
|
||||
" \"owners\": { \"names\": [ { \"name1\": \"Bob\", \"name2\": \"Alice\" } ] }\n"
|
||||
" }\n"
|
||||
" },\n" // source 1
|
||||
" {\n"
|
||||
" \"tenantId\": \"175bb55c-e36f-4ac5-a7b1-7afa1229bb11\",\n"
|
||||
" \"sourceId\": \"54d7de10-7b2e-4505-955b-cc2c2c7bbb11\",\n"
|
||||
" \"assetId\": \"cb068860528cb6bfb000cc35e79f11aeefed2\",\n"
|
||||
" \"ttl\": 120,\n"
|
||||
" \"expirationTime\": \"2020-07-29T11:21:12.253Z\",\n"
|
||||
" \"confidence\": 600,\n"
|
||||
" \"attributes\": {\n"
|
||||
" \"color\": \"white\",\n"
|
||||
" \"user\": \"Max\",\n"
|
||||
" \"owners\": { \"names\": [ { \"name1\": \"Bob\", \"name2\": \"Alice\" } ] }\n"
|
||||
" }\n"
|
||||
" }\n" // source 2
|
||||
" ]\n" // sources
|
||||
" }\n" // asset 1
|
||||
" ],\n" // asset collection
|
||||
" \"status\": \"done\",\n"
|
||||
" \"totalNumAssets\": 2,\n"
|
||||
" \"cursor\": \"start\"\n"
|
||||
" }\n" // response
|
||||
" },\n" // queryresponse 1
|
||||
" {\n"
|
||||
" \"index\": 3,\n"
|
||||
" \"response\": {\n"
|
||||
" \"assetCollections\": [\n"
|
||||
" {\n"
|
||||
" \"schemaVersion\": 1,\n"
|
||||
" \"assetType\": \"workload-cloud-ip\",\n"
|
||||
" \"assetTypeSchemaVersion\": 1,\n"
|
||||
" \"permissionType\": \"tenant\",\n"
|
||||
" \"permissionGroupId\": \"some-group-id\",\n"
|
||||
" \"name\": \"[2.2.2.2]\",\n"
|
||||
" \"class\": \"workload\",\n"
|
||||
" \"category\": \"iot\",\n"
|
||||
" \"family\": \"ip\",\n"
|
||||
" \"group\": \"\",\n"
|
||||
" \"order\": \"\",\n"
|
||||
" \"kind\": \"\",\n"
|
||||
" \"mainAttributes\": {\n"
|
||||
" \"ipv4Addresses\": [\n"
|
||||
" \"1.1.1.1\",\n"
|
||||
" \"2.2.2.2\"\n"
|
||||
" ],\n"
|
||||
" \"phase\": \"testing\"\n"
|
||||
" },\n" // mainAttributes
|
||||
" \"sources\": [\n"
|
||||
" {\n"
|
||||
" \"tenantId\": \"175bb55c-e36f-4ac5-a7b1-7afa1229aa00\",\n"
|
||||
" \"sourceId\": \"54d7de10-7b2e-4505-955b-cc2c2c7aaa00\",\n"
|
||||
" \"assetId\": \"50255c3172b4fb7fda93025f0bfaa7abefd1\",\n"
|
||||
" \"ttl\": 120,\n"
|
||||
" \"expirationTime\": \"2020-07-29T11:21:12.253Z\",\n"
|
||||
" \"confidence\": 500,\n"
|
||||
" \"attributes\": {\n"
|
||||
" \"color\": \"red\",\n"
|
||||
" \"user\": \"Omry2\",\n"
|
||||
" \"phase\": \"testing2\",\n"
|
||||
" \"owners\": { \"names\": [ { \"name1\": \"Bob\", \"name2\": \"Alice\" } ] }\n"
|
||||
" }\n"
|
||||
" },\n" // source 1
|
||||
" {\n"
|
||||
" \"tenantId\": \"175bb55c-e36f-4ac5-a7b1-7afa1229bb11\",\n"
|
||||
" \"sourceId\": \"54d7de10-7b2e-4505-955b-cc2c2c7bbb11\",\n"
|
||||
" \"assetId\": \"cb068860528cb6bfb000cc35e79f11aeefed2\",\n"
|
||||
" \"ttl\": 120,\n"
|
||||
" \"expirationTime\": \"2020-07-29T11:21:12.253Z\",\n"
|
||||
" \"confidence\": 600,\n"
|
||||
" \"attributes\": {\n"
|
||||
" \"color\": \"white\",\n"
|
||||
" \"user\": \"Max\",\n"
|
||||
" \"owners\": { \"names\": [ { \"name1\": \"Bob\", \"name2\": \"Alice\" } ] }\n"
|
||||
" }\n"
|
||||
" }\n" // source 2
|
||||
" ]\n" // sources
|
||||
" }\n" // asset 1
|
||||
" ],\n" // asset collection
|
||||
" \"status\": \"done\",\n"
|
||||
" \"totalNumAssets\": 2,\n"
|
||||
" \"cursor\": \"start\"\n"
|
||||
" }\n" // response
|
||||
" }\n" // queryresponse 1
|
||||
" ]\n" // queryresponses
|
||||
"}\n"
|
||||
);
|
||||
Debug::setNewDefaultStdout(&cout);
|
||||
EXPECT_CALL(
|
||||
messaging_mock,
|
||||
sendMessage(true, _, I_Messaging::Method::POST, _, _, _, _, MessageTypeTag::INTELLIGENCE)
|
||||
).WillOnce(Return(response_str));
|
||||
auto maybe_ans = intell->queryIntelligence<Profile>(requests);
|
||||
EXPECT_TRUE(maybe_ans.ok());
|
||||
auto vec = maybe_ans.unpack();
|
||||
EXPECT_EQ(vec.size(), 4u);
|
||||
EXPECT_FALSE(vec[0].ok());
|
||||
EXPECT_TRUE(vec[1].ok());
|
||||
EXPECT_FALSE(vec[2].ok());
|
||||
EXPECT_TRUE(vec[3].ok());
|
||||
|
||||
auto assets1_vec = vec[1].unpack();
|
||||
EXPECT_EQ(assets1_vec.size(), 1u);
|
||||
auto iter = assets1_vec.begin();
|
||||
EXPECT_EQ(iter->getData().begin()->getUser().toString(), "Omry");
|
||||
EXPECT_EQ(iter->getData().begin()->getPhase().toString(), "testing");
|
||||
|
||||
auto assets3_vec = vec[3].unpack();
|
||||
EXPECT_EQ(assets1_vec.size(), 1u);
|
||||
iter = assets3_vec.begin();
|
||||
EXPECT_EQ(iter->getData().begin()->getUser().toString(), "Omry2");
|
||||
EXPECT_EQ(iter->getData().begin()->getPhase().toString(), "testing2");
|
||||
}
|
||||
|
||||
@@ -22,6 +22,27 @@ using namespace Intelligence_IS_V2;
|
||||
|
||||
USE_DEBUG_FLAG(D_INTELLIGENCE);
|
||||
|
||||
BulkQueryRequest::BulkQueryRequest(QueryRequest &_request, int _index)
|
||||
:
|
||||
request(_request),
|
||||
index(_index)
|
||||
{}
|
||||
|
||||
QueryRequest
|
||||
BulkQueryRequest::getQueryRequest() const
|
||||
{
|
||||
return request;
|
||||
}
|
||||
|
||||
void
|
||||
BulkQueryRequest::save(cereal::JSONOutputArchive &ar) const
|
||||
{
|
||||
ar(
|
||||
cereal::make_nvp("query", getQueryRequest()),
|
||||
cereal::make_nvp("index", index)
|
||||
);
|
||||
}
|
||||
|
||||
QueryRequest::QueryRequest(
|
||||
Condition condition_type,
|
||||
const string &key,
|
||||
@@ -48,6 +69,20 @@ QueryRequest::saveToJson(cereal::JSONOutputArchive &ar) const
|
||||
query_types.save(ar);
|
||||
}
|
||||
|
||||
void
|
||||
QueryRequest::save(cereal::JSONOutputArchive &ar) const
|
||||
{
|
||||
ar(
|
||||
cereal::make_nvp("limit", assets_limit),
|
||||
cereal::make_nvp("fullResponse", full_response),
|
||||
cereal::make_nvp("query", query)
|
||||
);
|
||||
|
||||
if (cursor.ok()) ar(cereal::make_nvp("cursor", cursor.unpack().second));
|
||||
requested_attributes.save(ar);
|
||||
query_types.save(ar);
|
||||
}
|
||||
|
||||
uint
|
||||
QueryRequest::getAssetsLimit() const
|
||||
{
|
||||
|
||||
@@ -19,7 +19,7 @@ extern const string unnamed_service;
|
||||
|
||||
LogGen::~LogGen()
|
||||
{
|
||||
Singleton::Consume<I_Logging>::by<LogGen>()->sendLog(log);
|
||||
if (send_log) Singleton::Consume<I_Logging>::by<LogGen>()->sendLog(log);
|
||||
}
|
||||
|
||||
LogGen &
|
||||
@@ -57,6 +57,18 @@ LogGen::getAudienceTeam() const
|
||||
return ReportIS::AudienceTeam::NONE;
|
||||
}
|
||||
|
||||
string
|
||||
LogGen::getLogInsteadOfSending()
|
||||
{
|
||||
send_log = false;
|
||||
stringstream output;
|
||||
{
|
||||
cereal::JSONOutputArchive ar(output);
|
||||
log.serialize(ar);
|
||||
}
|
||||
return output.str();
|
||||
}
|
||||
|
||||
void
|
||||
LogGen::loadBaseLogFields()
|
||||
{
|
||||
|
||||
@@ -312,7 +312,7 @@ LoggingComp::preload()
|
||||
registerExpectedConfiguration<bool>("Logging", "Enable CEF");
|
||||
registerExpectedConfiguration<bool>("Logging", "Enable Log skipping");
|
||||
registerExpectedConfiguration<string>("Logging", "Log file name");
|
||||
registerExpectedConfiguration<string>("Logging", "Log file line seperator");
|
||||
registerExpectedConfiguration<string>("Logging", "Log file line separator");
|
||||
registerExpectedConfiguration<string>("Logging", "Fog Log URI");
|
||||
registerExpectedConfiguration<string>("Logging", "Syslog IP");
|
||||
registerExpectedConfiguration<uint>("Logging", "Syslog port");
|
||||
|
||||
@@ -9,6 +9,7 @@
|
||||
#include "mock/mock_messaging.h"
|
||||
#include "mock/mock_time_get.h"
|
||||
#include "mock/mock_rest_api.h"
|
||||
#include "mock/mock_logging.h"
|
||||
#include "config.h"
|
||||
#include "config_component.h"
|
||||
#include "instance_awareness.h"
|
||||
@@ -1331,3 +1332,57 @@ TEST_F(LogTest, ObfuscationTest)
|
||||
EXPECT_THAT(str, AnyOf(HasSubstr("String='Another string'"), HasSubstr("String=Another string")));
|
||||
}
|
||||
}
|
||||
|
||||
TEST(OfflineLog, OfflineLog)
|
||||
{
|
||||
AgentDetails agent_details;
|
||||
StrictMock<MockTimeGet> mock_timer;
|
||||
StrictMock<MockLogging> mock_logger;
|
||||
|
||||
EXPECT_CALL(mock_timer, getWalltimeStr(_)).WillOnce(Return("0:0:0"));
|
||||
EXPECT_CALL(mock_timer, getWalltime()).WillOnce(Return(chrono::microseconds(0)));
|
||||
EXPECT_CALL(mock_logger, getCurrentLogId()).WillOnce(Return(1));
|
||||
|
||||
LogGen log(
|
||||
"Install policy",
|
||||
Audience::INTERNAL,
|
||||
Severity::INFO,
|
||||
Priority::LOW,
|
||||
Tags::POLICY_INSTALLATION,
|
||||
Tags::ACCESS_CONTROL,
|
||||
Enreachments::BEAUTIFY_OUTPUT
|
||||
);
|
||||
log << LogField("String", "Another string");
|
||||
|
||||
string expected_log(
|
||||
"{\n"
|
||||
" \"eventTime\": \"0:0:0\",\n"
|
||||
" \"eventName\": \"Install policy\",\n"
|
||||
" \"eventSeverity\": \"Info\",\n"
|
||||
" \"eventPriority\": \"Low\",\n"
|
||||
" \"eventType\": \"Event Driven\",\n"
|
||||
" \"eventLevel\": \"Log\",\n"
|
||||
" \"eventLogLevel\": \"info\",\n"
|
||||
" \"eventAudience\": \"Internal\",\n"
|
||||
" \"eventAudienceTeam\": \"\",\n"
|
||||
" \"eventFrequency\": 0,\n"
|
||||
" \"eventTags\": [\n"
|
||||
" \"Access Control\",\n"
|
||||
" \"Policy Installation\"\n"
|
||||
" ],\n"
|
||||
" \"eventSource\": {\n"
|
||||
" \"agentId\": \"Unknown\",\n"
|
||||
" \"eventTraceId\": \"\",\n"
|
||||
" \"eventSpanId\": \"\",\n"
|
||||
" \"issuingEngineVersion\": \"\",\n"
|
||||
" \"serviceName\": \"Unnamed Nano Service\"\n"
|
||||
" },\n"
|
||||
" \"eventData\": {\n"
|
||||
" \"logIndex\": 1,\n"
|
||||
" \"String\": \"Another string\"\n"
|
||||
" }\n"
|
||||
"}"
|
||||
);
|
||||
|
||||
EXPECT_EQ(log.getLogInsteadOfSending(), expected_log);
|
||||
}
|
||||
|
||||
@@ -174,9 +174,6 @@ MainloopComponent::Impl::reportStartupEvent()
|
||||
auto team = i_env->get<ReportIS::AudienceTeam>("Audience Team");
|
||||
if (team.ok()) audience_team = *team;
|
||||
|
||||
string agent_uid =
|
||||
(Report::isPlaygroundEnv() ? "playground-" : "") +
|
||||
Singleton::Consume<I_AgentDetails>::by<MainloopComponent>()->getAgentId();
|
||||
Report startup_message(
|
||||
"Nano service successfully started",
|
||||
curr_time,
|
||||
@@ -188,7 +185,7 @@ MainloopComponent::Impl::reportStartupEvent()
|
||||
ReportIS::Severity::INFO,
|
||||
ReportIS::Priority::HIGH,
|
||||
chrono::seconds(0),
|
||||
LogField("agentId", agent_uid),
|
||||
LogField("agentId", Singleton::Consume<I_AgentDetails>::by<MainloopComponent>()->getAgentId()),
|
||||
ReportIS::Tags::INFORMATIONAL
|
||||
);
|
||||
|
||||
@@ -290,7 +287,7 @@ MainloopComponent::Impl::run()
|
||||
"Ending execution of corutine. Routine named: " <<
|
||||
curr_iter->second.getRoutineName();
|
||||
if (getTimer()->getMonotonicTime() > stop_time + large_exceeding) {
|
||||
dbgError(D_MAINLOOP)
|
||||
dbgWarning(D_MAINLOOP)
|
||||
<< "Routine execution exceeded run time. Routine name: "
|
||||
<< curr_iter->second.getRoutineName();
|
||||
}
|
||||
|
||||
@@ -16,14 +16,10 @@
|
||||
#include <algorithm>
|
||||
#include <iostream>
|
||||
|
||||
#include "sasal.h"
|
||||
|
||||
using namespace std;
|
||||
|
||||
USE_DEBUG_FLAG(D_HTTP_REQUEST);
|
||||
|
||||
SASAL_START // Communication
|
||||
|
||||
HTTPHeaders::HTTPHeaders(const string &http_data)
|
||||
{
|
||||
static const string end_of_headers = "\r\n\r\n";
|
||||
@@ -109,5 +105,3 @@ HTTPHeaders::createHTTPHeader(const string &http_data)
|
||||
// To justify the compiler
|
||||
return HTTPHeaders();
|
||||
}
|
||||
|
||||
SASAL_END
|
||||
|
||||
@@ -13,10 +13,6 @@
|
||||
|
||||
#include "http_decoder.h"
|
||||
|
||||
#include "sasal.h"
|
||||
|
||||
SASAL_START // Communication
|
||||
|
||||
using namespace std;
|
||||
|
||||
USE_DEBUG_FLAG(D_COMMUNICATION);
|
||||
@@ -354,5 +350,3 @@ HTTPResponse::getResponse() const
|
||||
}
|
||||
return genError(string("Request failed, Error: ") + status_code_str + " " + status_code_message->second);
|
||||
}
|
||||
|
||||
SASAL_END
|
||||
|
||||
@@ -13,12 +13,9 @@
|
||||
|
||||
#include "http_encoder.h"
|
||||
#include "debug.h"
|
||||
#include "sasal.h"
|
||||
|
||||
using namespace std;
|
||||
|
||||
SASAL_START // Communication
|
||||
|
||||
USE_DEBUG_FLAG(D_COMMUNICATION);
|
||||
|
||||
HTTPRequest::HTTPRequest(const string &_method_statement, const string &_host, const bool to_proxy)
|
||||
@@ -172,5 +169,3 @@ HTTPEncoder::isOverSSL()
|
||||
over_ssl = true;
|
||||
return *this;
|
||||
};
|
||||
|
||||
SASAL_END
|
||||
|
||||
@@ -46,14 +46,11 @@
|
||||
#include "agent_details.h"
|
||||
#include "messaging_buffer/http_request_event.h"
|
||||
#include "boost/asio.hpp"
|
||||
#include "sasal.h"
|
||||
#include "message_metric.h"
|
||||
#include "smart_bio.h"
|
||||
#include "connkey.h"
|
||||
#include "agent_core_utilities.h"
|
||||
|
||||
SASAL_START // Communication
|
||||
|
||||
using namespace std;
|
||||
using namespace chrono;
|
||||
using namespace smartBIO;
|
||||
@@ -343,6 +340,7 @@ public:
|
||||
}
|
||||
stringstream token_steam;
|
||||
token_steam << token_file.rdbuf();
|
||||
|
||||
auto new_token = token_steam.str();
|
||||
if (access_token != new_token) {
|
||||
access_token = new_token;
|
||||
@@ -2077,5 +2075,3 @@ ProtoMessageComp::preload()
|
||||
registerExpectedConfiguration<string>("message", "Data printout type");
|
||||
registerExpectedConfiguration<uint32_t>("message", "Internal Fog error timeout");
|
||||
}
|
||||
|
||||
SASAL_END
|
||||
|
||||
@@ -170,9 +170,6 @@ string GenericMetric::getListenerName() const { return metric_name; }
|
||||
void
|
||||
GenericMetric::generateLog()
|
||||
{
|
||||
string agent_uid =
|
||||
(Report::isPlaygroundEnv() ? "playground-" : "") +
|
||||
Singleton::Consume<I_AgentDetails>::by<GenericMetric>()->getAgentId();
|
||||
set<ReportIS::Tags> tags;
|
||||
Report metric_to_fog(
|
||||
metric_name,
|
||||
@@ -185,7 +182,7 @@ GenericMetric::generateLog()
|
||||
Severity::INFO,
|
||||
Priority::LOW,
|
||||
report_interval,
|
||||
LogField("agentId", agent_uid),
|
||||
LogField("agentId", Singleton::Consume<I_AgentDetails>::by<GenericMetric>()->getAgentId()),
|
||||
tags,
|
||||
Tags::INFORMATIONAL,
|
||||
issuing_engine
|
||||
|
||||
@@ -97,7 +97,8 @@ TagAndEnumManagement::convertStringToTag(const string &tag)
|
||||
{"CPView Monitoring", ReportIS::Tags::CPVIEW_METRICS},
|
||||
{"Reverse Proxy", ReportIS::Tags::REVERSE_PROXY},
|
||||
{"Http Geo Filter", ReportIS::Tags::HTTP_GEO_FILTER},
|
||||
{"File Upload", ReportIS::Tags::FILE_UPLOAD}
|
||||
{"File Upload", ReportIS::Tags::FILE_UPLOAD},
|
||||
{"Identity Awareness", ReportIS::Tags::IDENTITY_AWARENESS}
|
||||
};
|
||||
|
||||
auto report_is_tag = strings_to_tags.find(tag);
|
||||
@@ -236,7 +237,6 @@ TagAndEnumManagement::convertToString(const Notification ¬ification)
|
||||
case Notification::POLICY_UPDATE: return "c0516360-a0b1-4246-af4c-2b6c586958e0";
|
||||
case Notification::FIRST_REQUEST_FOR_ASSET: return "a53a7091-5d7a-4881-9e64-0fa3a1fc5a93";
|
||||
case Notification::UPSTREAM_STATUS: return "46e5af4e-db29-444a-8f6b-2a6bd8f2e131";
|
||||
case Notification::IOT_POLICY_UPDATE: return "92b57541-77ec-4dc4-8d46-dd9de71a602d";
|
||||
case Notification::SYNC_LEARNING: return "b9b9ab04-2e2a-4cd1-b7e5-2c956861fb69";
|
||||
case Notification::SDWAN_POLICY_UPDATE: return "2b18f5a0-5503-4c6b-967f-aa71dbced1aa";
|
||||
case Notification::SDWAN_POLICY_UPDATE_ERROR: return "8d2db6ea-30b7-11ec-8d3d-0242ac130003";
|
||||
@@ -255,6 +255,7 @@ TagAndEnumManagement::convertToString(const IssuingEngine &issuing_engine)
|
||||
case IssuingEngine::AGENT_CORE: return "Agent Core";
|
||||
case IssuingEngine::IOT_NEXT: return "iotNext";
|
||||
case IssuingEngine::SDWAN: return "sdwanGwSharing";
|
||||
case IssuingEngine::IDA_NEXT: return "quantumMetaNotifyIdn";
|
||||
}
|
||||
|
||||
dbgAssert(false) << "Reached impossible engine value of: " << static_cast<int>(issuing_engine);
|
||||
@@ -305,7 +306,8 @@ EnumArray<Tags, string> TagAndEnumManagement::tags_translation_arr {
|
||||
"CPView Monitoring",
|
||||
"Reverse Proxy",
|
||||
"Http Geo Filter",
|
||||
"File Upload"
|
||||
"File Upload",
|
||||
"Identity Awareness"
|
||||
};
|
||||
|
||||
EnumArray<AudienceTeam, string> TagAndEnumManagement::audience_team_translation {
|
||||
@@ -314,5 +316,6 @@ EnumArray<AudienceTeam, string> TagAndEnumManagement::audience_team_translation
|
||||
"WAAP",
|
||||
"Agent Intelligence",
|
||||
"cpviewMonitoring",
|
||||
"Signature Developers"
|
||||
"Signature Developers",
|
||||
"Identity Awareness"
|
||||
};
|
||||
|
||||
@@ -16,7 +16,6 @@
|
||||
#include <unistd.h>
|
||||
#include <sstream>
|
||||
#include <sys/socket.h>
|
||||
#include <boost/algorithm/string.hpp>
|
||||
|
||||
#include "debug.h"
|
||||
|
||||
@@ -35,6 +34,18 @@ RestConn::~RestConn()
|
||||
{
|
||||
}
|
||||
|
||||
static bool
|
||||
compareStringCaseInsensitive(const string &s1, const string &s2)
|
||||
{
|
||||
if (s1.size() != s2.size()) return false;
|
||||
|
||||
for (size_t index = 0; index < s1.size(); ++index) {
|
||||
if (tolower(s1[index]) != tolower(s2[index])) return false;
|
||||
}
|
||||
|
||||
return true;
|
||||
}
|
||||
|
||||
void
|
||||
RestConn::parseConn() const
|
||||
{
|
||||
@@ -69,7 +80,7 @@ RestConn::parseConn() const
|
||||
os.str(line);
|
||||
string head, data;
|
||||
os >> head >> data;
|
||||
if (boost::iequals(head, "Content-Length:")) {
|
||||
if (compareStringCaseInsensitive(head, "Content-Length:")) {
|
||||
try {
|
||||
len = stoi(data, nullptr);
|
||||
} catch (...) {
|
||||
|
||||
@@ -22,7 +22,6 @@
|
||||
#include "debug.h"
|
||||
#include "rest_conn.h"
|
||||
#include "i_rest_invoke.h"
|
||||
#include "sasal.h"
|
||||
|
||||
#include <syslog.h>
|
||||
|
||||
@@ -33,8 +32,6 @@ USE_DEBUG_FLAG(D_API);
|
||||
static const int listen_limit = 100;
|
||||
static const chrono::milliseconds bind_retry_interval_msec = chrono::milliseconds(500);
|
||||
|
||||
SASAL_START // REST Server
|
||||
|
||||
#include <iostream>
|
||||
|
||||
class RestServer::Impl
|
||||
@@ -257,5 +254,3 @@ RestServer::preload()
|
||||
registerExpectedConfiguration<uint>("connection", "Nano service API Port Range start");
|
||||
registerExpectedConfiguration<uint>("connection", "Nano service API Port Range end");
|
||||
}
|
||||
|
||||
SASAL_END
|
||||
|
||||
@@ -21,7 +21,7 @@ extern void (*debug_int)(int is_error, const char *func, const char *file, int l
|
||||
#define __FILENAME__ (strrchr(__FILE__, '/') ? strrchr(__FILE__, '/') + 1 : __FILE__)
|
||||
#endif
|
||||
|
||||
enum debugLevel { TraceLevel = 0, WarningLevel = 3 };
|
||||
enum debugLevel { TraceLevel = 0, DebugLevel = 1, WarningLevel = 3 };
|
||||
|
||||
#define writeDebug(debug_level, fmt, ...) \
|
||||
{ \
|
||||
|
||||
@@ -140,14 +140,13 @@ createSharedRingQueue(const char *shared_location_name, uint16_t num_of_data_seg
|
||||
|
||||
g_num_of_data_segments = num_of_data_segments;
|
||||
|
||||
fd = shm_open(shared_location_name, shmem_fd_flags, S_IRUSR | S_IWUSR);
|
||||
fd = shm_open(shared_location_name, shmem_fd_flags, S_IRWXU | S_IRWXG | S_IRWXO);
|
||||
if (fd == -1) {
|
||||
writeDebug(
|
||||
WarningLevel,
|
||||
"createSharedRingQueue: Failed to open shared memory for '%s'. Errno: %d (%s)\n",
|
||||
"createSharedRingQueue: Failed to open shared memory for '%s'. Errno: %d\n",
|
||||
shared_location_name,
|
||||
errno,
|
||||
strerror(errno)
|
||||
errno
|
||||
);
|
||||
return NULL;
|
||||
}
|
||||
@@ -384,7 +383,7 @@ pushBuffersToQueue(
|
||||
large_total_elem_size,
|
||||
max_write_size
|
||||
);
|
||||
return -1;
|
||||
return -2;
|
||||
}
|
||||
}
|
||||
total_elem_size = (uint16_t)large_total_elem_size;
|
||||
@@ -400,18 +399,18 @@ pushBuffersToQueue(
|
||||
|
||||
|
||||
if (!isThereEnoughMemoryInQueue(write_pos, read_pos, num_of_segments_to_write)) {
|
||||
writeDebug(WarningLevel, "Cannot write to a full queue\n");
|
||||
return -1;
|
||||
writeDebug(DebugLevel, "Cannot write to a full queue");
|
||||
return -3;
|
||||
}
|
||||
|
||||
if (write_pos >= g_num_of_data_segments) {
|
||||
writeDebug(
|
||||
WarningLevel,
|
||||
DebugLevel,
|
||||
"Cannot write to a location outside the queue. Write index: %u, number of queue elements: %u",
|
||||
write_pos,
|
||||
g_num_of_data_segments
|
||||
);
|
||||
return -1;
|
||||
return -4;
|
||||
}
|
||||
|
||||
if (write_pos + num_of_segments_to_write > g_num_of_data_segments) {
|
||||
@@ -488,16 +487,14 @@ popFromQueue(SharedRingQueue *queue)
|
||||
}
|
||||
num_of_read_segments = getNumOfDataSegmentsNeeded(buffer_mgmt[read_pos]);
|
||||
|
||||
end_pos = read_pos + num_of_read_segments;
|
||||
if (read_pos + num_of_read_segments > g_num_of_data_segments) {
|
||||
for ( ; read_pos < g_num_of_data_segments; ++read_pos ) {
|
||||
buffer_mgmt[read_pos] = empty_buff_mgmt_magic;
|
||||
}
|
||||
read_pos = 0;
|
||||
}
|
||||
|
||||
writeDebug(
|
||||
TraceLevel,
|
||||
"Size of data to remove: %u, number of queue elements to free: %u, current read index: %u, end index: %u",
|
||||
buffer_mgmt[read_pos],
|
||||
num_of_read_segments,
|
||||
read_pos,
|
||||
end_pos
|
||||
);
|
||||
end_pos = read_pos + num_of_read_segments;
|
||||
|
||||
for ( ; read_pos < end_pos; ++read_pos ) {
|
||||
buffer_mgmt[read_pos] = empty_buff_mgmt_magic;
|
||||
@@ -509,6 +506,15 @@ popFromQueue(SharedRingQueue *queue)
|
||||
}
|
||||
}
|
||||
|
||||
writeDebug(
|
||||
TraceLevel,
|
||||
"Size of data to remove: %u, number of queue elements to free: %u, current read index: %u, end index: %u",
|
||||
buffer_mgmt[read_pos],
|
||||
num_of_read_segments,
|
||||
read_pos,
|
||||
end_pos
|
||||
);
|
||||
|
||||
if (read_pos == g_num_of_data_segments) read_pos = 0;
|
||||
|
||||
queue->read_pos = read_pos;
|
||||
|
||||
@@ -50,7 +50,6 @@ debugInitial(int is_error, const char *func, const char *file, int line_num, con
|
||||
va_start(args, fmt);
|
||||
vprintf(fmt, args);
|
||||
va_end(args);
|
||||
printf("\n");
|
||||
}
|
||||
|
||||
void (*debug_int)(int is_error, const char *func, const char *file, int line_num, const char *fmt, ...) = debugInitial;
|
||||
@@ -101,7 +100,7 @@ createOneWayIPCQueue(
|
||||
return NULL;
|
||||
}
|
||||
|
||||
if (is_owner && chown(shmem_path, user_id, group_id) == -1) {
|
||||
if (is_owner && chmod(shmem_path, 0666) == -1) {
|
||||
writeDebug(WarningLevel, "Failed to set the permissions");
|
||||
destroySharedRingQueue(ring_queue, is_owner, isTowardsOwner(is_owner, is_tx_queue));
|
||||
return NULL;
|
||||
|
||||
@@ -6,8 +6,7 @@ using namespace std;
|
||||
using namespace testing;
|
||||
|
||||
const static string bad_shmem_path = "/root/sadsadsadad/444";
|
||||
const static string valid_shmem_file_name = "shmem_ut";
|
||||
const static string valid_shmem_path = "/dev/shm/" + valid_shmem_file_name;
|
||||
const static string valid_shmem_path = "shmem_ut";
|
||||
const uint16_t max_num_of_data_segments = sizeof(DataSegment)/sizeof(uint16_t);
|
||||
const static uint16_t num_of_shmem_elem = 11;
|
||||
|
||||
@@ -16,11 +15,8 @@ class SharedRingQueueTest : public Test
|
||||
public:
|
||||
SharedRingQueueTest()
|
||||
{
|
||||
// remove old fd from prev tests
|
||||
unlink(valid_shmem_path.c_str());
|
||||
|
||||
owners_queue = createSharedRingQueue(valid_shmem_file_name.c_str(), num_of_shmem_elem, 1, 1);
|
||||
users_queue = createSharedRingQueue(valid_shmem_file_name.c_str(), num_of_shmem_elem, 0, 0);
|
||||
owners_queue = createSharedRingQueue(valid_shmem_path.c_str(), num_of_shmem_elem, 1, 1);
|
||||
users_queue = createSharedRingQueue(valid_shmem_path.c_str(), num_of_shmem_elem, 0, 0);
|
||||
}
|
||||
|
||||
~SharedRingQueueTest()
|
||||
@@ -194,7 +190,7 @@ TEST_F(SharedRingQueueTest, write_read_pop_over_multiple_segments)
|
||||
}
|
||||
|
||||
vector<char> no_more_space_data(SHARED_MEMORY_SEGMENT_ENTRY_SIZE*2, '6');
|
||||
EXPECT_EQ(pushToQueue(users_queue, no_more_space_data.data(), no_more_space_data.size()), -1);
|
||||
EXPECT_EQ(pushToQueue(users_queue, no_more_space_data.data(), no_more_space_data.size()), -3);
|
||||
|
||||
const char *read_data = nullptr;
|
||||
uint16_t read_bytes = 0;
|
||||
@@ -217,7 +213,7 @@ TEST_F(SharedRingQueueTest, write_element_that_fills_the_entire_queue)
|
||||
vector<char> long_data(SHARED_MEMORY_SEGMENT_ENTRY_SIZE*(num_of_shmem_elem - 1), '2');
|
||||
|
||||
EXPECT_EQ(pushToQueue(users_queue, long_data.data(), long_data.size()), 0);
|
||||
EXPECT_EQ(pushToQueue(users_queue, short_data.data(), short_data.size()), -1);
|
||||
EXPECT_EQ(pushToQueue(users_queue, short_data.data(), short_data.size()), -3);
|
||||
|
||||
const char *data_to_read = nullptr;
|
||||
uint16_t read_bytes = 0;
|
||||
@@ -225,7 +221,7 @@ TEST_F(SharedRingQueueTest, write_element_that_fills_the_entire_queue)
|
||||
EXPECT_EQ(read_bytes, long_data.size());
|
||||
EXPECT_EQ(popFromQueue(owners_queue), 0);
|
||||
|
||||
EXPECT_EQ(pushToQueue(users_queue, long_data.data(), long_data.size()), -1);
|
||||
EXPECT_EQ(pushToQueue(users_queue, long_data.data(), long_data.size()), -3);
|
||||
EXPECT_EQ(pushToQueue(users_queue, short_data.data(), short_data.size()), 0);
|
||||
|
||||
EXPECT_EQ(peekToQueue(owners_queue, &data_to_read, &read_bytes), 0);
|
||||
@@ -244,11 +240,11 @@ TEST_F(SharedRingQueueTest, not_enought_space_to_push_on_end_but_enought_on_star
|
||||
for (uint i = 0; i < num_of_shmem_elem - 1; i++) {
|
||||
EXPECT_EQ(pushToQueue(users_queue, short_data.data(), short_data.size()), 0);
|
||||
}
|
||||
EXPECT_EQ(pushToQueue(users_queue, long_data.data(), long_data.size()), -1);
|
||||
EXPECT_EQ(pushToQueue(users_queue, long_data.data(), long_data.size()), -3);
|
||||
|
||||
for (uint i = 0; i < 3; i++) {
|
||||
EXPECT_EQ(popFromQueue(owners_queue), 0);
|
||||
EXPECT_EQ(pushToQueue(users_queue, long_data.data(), long_data.size()), -1);
|
||||
EXPECT_EQ(pushToQueue(users_queue, long_data.data(), long_data.size()), -3);
|
||||
}
|
||||
|
||||
EXPECT_EQ(popFromQueue(owners_queue), 0);
|
||||
@@ -264,7 +260,7 @@ TEST_F(SharedRingQueueTest, attempt_write_to_full_queue)
|
||||
for (uint i = 0; i < num_of_shmem_elem - 1; i ++) {
|
||||
EXPECT_EQ(pushToQueue(users_queue, reinterpret_cast<char *>(&data_to_write), sizeof(data_to_write)), 0);
|
||||
}
|
||||
EXPECT_EQ(pushToQueue(users_queue, reinterpret_cast<char *>(&data_to_write), sizeof(data_to_write)), -1);
|
||||
EXPECT_EQ(pushToQueue(users_queue, reinterpret_cast<char *>(&data_to_write), sizeof(data_to_write)), -3);
|
||||
|
||||
const char *data_to_read = nullptr;
|
||||
uint16_t read_bytes = 0;
|
||||
@@ -278,7 +274,7 @@ TEST_F(SharedRingQueueTest, attempt_write_to_full_queue)
|
||||
);
|
||||
EXPECT_EQ(
|
||||
pushToQueue(users_queue, reinterpret_cast<char *>(&data_to_write), sizeof(data_to_write)),
|
||||
-1
|
||||
-3
|
||||
);
|
||||
|
||||
int popped_items_count = 0;
|
||||
@@ -326,14 +322,12 @@ TEST_F(SharedRingQueueTest, ilegal_queue)
|
||||
ASSERT_NE(users_queue, nullptr);
|
||||
|
||||
destroySharedRingQueue(users_queue, 0, 1);
|
||||
users_queue = createSharedRingQueue(valid_shmem_file_name.c_str(), max_num_of_data_segments + 1, 0, 0);
|
||||
users_queue = createSharedRingQueue(valid_shmem_path.c_str(), max_num_of_data_segments + 1, 0, 0);
|
||||
EXPECT_EQ(users_queue, nullptr);
|
||||
|
||||
users_queue = createSharedRingQueue(bad_shmem_path.c_str(), max_num_of_data_segments, 0, 0);
|
||||
EXPECT_EQ(users_queue, nullptr);
|
||||
|
||||
ASSERT_NE(owners_queue, nullptr);
|
||||
destroySharedRingQueue(owners_queue, 1, 1);
|
||||
owners_queue = createSharedRingQueue(valid_shmem_file_name.c_str(), max_num_of_data_segments, 1, 1);
|
||||
owners_queue = createSharedRingQueue(valid_shmem_path.c_str(), max_num_of_data_segments, 1, 1);
|
||||
EXPECT_NE(owners_queue, nullptr);
|
||||
}
|
||||
|
||||
@@ -20,9 +20,13 @@
|
||||
|
||||
#include "cache.h"
|
||||
#include "config.h"
|
||||
#include "tenant_profile_pair.h"
|
||||
#include "hash_combine.h"
|
||||
|
||||
using namespace std;
|
||||
|
||||
USE_DEBUG_FLAG(D_TENANT_MANAGER);
|
||||
|
||||
class TenantManager::Impl
|
||||
:
|
||||
Singleton::Provide<I_TenantManager>::From<TenantManager>
|
||||
@@ -32,25 +36,26 @@ public:
|
||||
void fini();
|
||||
|
||||
void uponNewTenants(const newTenantCB &cb) override;
|
||||
bool isTenantActive(const string &tenant_id) const override;
|
||||
bool areTenantAndProfileActive(const string &tenant_id, const string &profile_id) const override;
|
||||
|
||||
vector<string> fetchAllActiveTenants() const override;
|
||||
vector<string> fetchActiveTenants() const override;
|
||||
vector<string> getInstances(const string &tenant_id) const override;
|
||||
vector<string> getInstances(const string &tenant_id, const string &profile_id) const override;
|
||||
vector<string> fetchProfileIds(const string &tenant_id) const override;
|
||||
|
||||
void addActiveTenant(const string &tenant_id) override;
|
||||
void addActiveTenants(const vector<string> &tenants_id) override;
|
||||
void addActiveTenantAndProfile(const string &tenant_id, const string &profile_id) override;
|
||||
|
||||
void deactivateTenant(const string &tenant_id) override;
|
||||
void deactivateTenants(const vector<string> &tenants_id) override;
|
||||
void deactivateTenant(const string &tenant_id, const string &profile_id) override;
|
||||
|
||||
chrono::microseconds getTimeoutVal() const override;
|
||||
|
||||
void
|
||||
addInstance(const string &tenant_id, const string &instace_id)
|
||||
addInstance(const string &tenant_id, const string &profile_id, const string &instace_id)
|
||||
{
|
||||
auto tenant_cache = mapper.find(tenant_id);
|
||||
auto tenant_profile_pair = TenantProfilePair(tenant_id, profile_id);
|
||||
auto tenant_cache = mapper.find(tenant_profile_pair);
|
||||
if (tenant_cache == mapper.end()) {
|
||||
tenant_cache = mapper.insert(make_pair(tenant_id, TemporaryCache<string, void>())).first;
|
||||
tenant_cache = mapper.insert(make_pair(tenant_profile_pair, TemporaryCache<string, void>())).first;
|
||||
tenant_cache->second.startExpiration(
|
||||
getTimeoutVal(),
|
||||
Singleton::Consume<I_MainLoop>::by<TenantManager>(),
|
||||
@@ -63,11 +68,14 @@ public:
|
||||
|
||||
private:
|
||||
void runUponNewTenants(const vector<string> &new_tenants);
|
||||
void sendTenant(const vector<string> &tenant_id);
|
||||
bool sendWithCustomPort(const vector<string> &tenant_id, const uint16_t port);
|
||||
void sendTenantAndProfile(const string &tenant_id, const string &profile_id);
|
||||
vector<string> getAllTenants() const;
|
||||
vector<string> fetchAllProfileIds(const string &tenant_id) const;
|
||||
vector<string> getProfileIds(const string &profile_id) const;
|
||||
bool sendWithCustomPort(const string &tenant_id, const string &profile_id, const uint16_t port);
|
||||
|
||||
TemporaryCache<string, void> active_tenants;
|
||||
map<string, TemporaryCache<string, void>> mapper;
|
||||
TemporaryCache<TenantProfilePair, void> active_tenants;
|
||||
map<TenantProfilePair, TemporaryCache<string, void>> mapper;
|
||||
vector<I_TenantManager::newTenantCB> upon_cb;
|
||||
|
||||
I_Messaging *i_messaging = nullptr;
|
||||
@@ -82,31 +90,76 @@ public:
|
||||
doCall() override
|
||||
{
|
||||
auto i_tenant_manager = Singleton::Consume<I_TenantManager>::from<TenantManager>();
|
||||
i_tenant_manager->addActiveTenants(tenant_ids.get());
|
||||
for (const auto &tenant_id: tenant_ids.get()) {
|
||||
i_tenant_manager->addInstance(tenant_id, instance_id.get());
|
||||
}
|
||||
i_tenant_manager->addActiveTenantAndProfile(tenant_id.get(), profile_id.get());
|
||||
i_tenant_manager->addInstance(tenant_id.get(), profile_id.get(), instance_id.get());
|
||||
}
|
||||
|
||||
private:
|
||||
C2S_LABEL_PARAM(vector<string>, tenant_ids, "tenantIds");
|
||||
C2S_LABEL_PARAM(string, instance_id, "instanceId");
|
||||
C2S_LABEL_PARAM(string, tenant_id, "tenantId");
|
||||
C2S_LABEL_PARAM(string, profile_id, "profileId");
|
||||
C2S_LABEL_PARAM(string, instance_id, "instanceId");
|
||||
};
|
||||
|
||||
class SendNewTenants : public ClientRest
|
||||
{
|
||||
public:
|
||||
SendNewTenants(const vector<string> &_tenant_ids)
|
||||
SendNewTenants(const string &_tenant_id, const string &_profile_id)
|
||||
:
|
||||
tenant_ids(_tenant_ids)
|
||||
tenant_id(_tenant_id),
|
||||
profile_id(_profile_id)
|
||||
{
|
||||
auto _instance_id = Singleton::Consume<I_InstanceAwareness>::by<TenantManager>()->getUniqueID();
|
||||
instance_id = _instance_id.ok() ? *_instance_id : "default";
|
||||
}
|
||||
|
||||
private:
|
||||
C2S_LABEL_PARAM(vector<string>, tenant_ids, "tenantIds");
|
||||
C2S_LABEL_PARAM(string, instance_id, "instanceId");
|
||||
C2S_LABEL_PARAM(string, tenant_id, "tenantId");
|
||||
C2S_LABEL_PARAM(string, profile_id, "profileId");
|
||||
C2S_LABEL_PARAM(string, instance_id, "instanceId");
|
||||
};
|
||||
|
||||
class FetchActiveTenants : public ServerRest
|
||||
{
|
||||
public:
|
||||
void
|
||||
doCall() override
|
||||
{
|
||||
active_tenants = Singleton::Consume<I_TenantManager>::from<TenantManager>()->fetchAllActiveTenants();
|
||||
}
|
||||
|
||||
S2C_PARAM(std::vector<std::string>, active_tenants);
|
||||
};
|
||||
|
||||
class GetActiveTenants : public ClientRest
|
||||
{
|
||||
public:
|
||||
GetActiveTenants() : active_tenants() {};
|
||||
|
||||
Maybe<string> genJson() const { return string("{}"); };
|
||||
|
||||
S2C_PARAM(vector<string>, active_tenants);
|
||||
};
|
||||
|
||||
class FetchProfileIds : public ServerRest
|
||||
{
|
||||
public:
|
||||
void
|
||||
doCall() override
|
||||
{
|
||||
profile_ids = Singleton::Consume<I_TenantManager>::from<TenantManager>()->fetchProfileIds(tenant_id);
|
||||
}
|
||||
|
||||
S2C_PARAM(vector<string>, profile_ids);
|
||||
C2S_PARAM(string, tenant_id);
|
||||
};
|
||||
|
||||
class GetProfileIds : public ClientRest
|
||||
{
|
||||
public:
|
||||
GetProfileIds(const string &_tenant_id) : profile_ids(), tenant_id(_tenant_id) {};
|
||||
|
||||
S2C_PARAM(vector<string>, profile_ids);
|
||||
C2S_PARAM(string, tenant_id);
|
||||
};
|
||||
|
||||
void
|
||||
@@ -129,6 +182,8 @@ TenantManager::Impl::init()
|
||||
if (type == TenantManagerType::SERVER) {
|
||||
auto rest = Singleton::Consume<I_RestApi>::by<TenantManager>();
|
||||
rest->addRestCall<LoadNewTenants>(RestAction::SET, "tenant-id");
|
||||
rest->addRestCall<FetchActiveTenants>(RestAction::SHOW, "active-tenants");
|
||||
rest->addRestCall<FetchActiveTenants>(RestAction::SHOW, "profile-ids");
|
||||
}
|
||||
|
||||
if (type == TenantManagerType::CLIENT) {
|
||||
@@ -144,8 +199,13 @@ TenantManager::Impl::init()
|
||||
interval,
|
||||
[this] ()
|
||||
{
|
||||
auto tenants_id = fetchActiveTenants();
|
||||
sendTenant(tenants_id);
|
||||
auto tenants_ids = fetchActiveTenants();
|
||||
for (auto tenant_id : tenants_ids) {
|
||||
auto profile_ids = fetchAllProfileIds(tenant_id);
|
||||
for (auto profile_id : profile_ids) {
|
||||
sendTenantAndProfile(tenant_id, profile_id);
|
||||
}
|
||||
}
|
||||
},
|
||||
"Tenant manager client reporter"
|
||||
);
|
||||
@@ -160,21 +220,21 @@ TenantManager::Impl::fini()
|
||||
}
|
||||
|
||||
bool
|
||||
TenantManager::Impl::sendWithCustomPort(const vector<string> &tenants_id, const uint16_t port)
|
||||
TenantManager::Impl::sendWithCustomPort(const string &tenant_id, const string &profile_id, const uint16_t port)
|
||||
{
|
||||
if (i_messaging == nullptr) {
|
||||
i_messaging = Singleton::Consume<I_Messaging>::by<TenantManager>();
|
||||
}
|
||||
|
||||
SendNewTenants new_tenants(tenants_id);
|
||||
SendNewTenants new_tenant_and_profile(tenant_id, profile_id);
|
||||
|
||||
return i_messaging->sendNoReplyObject(
|
||||
new_tenants,
|
||||
new_tenant_and_profile,
|
||||
I_Messaging::Method::POST,
|
||||
"127.0.0.1",
|
||||
port,
|
||||
conn_flags,
|
||||
"set-tenant-id"
|
||||
"/set-tenant-id"
|
||||
);
|
||||
}
|
||||
|
||||
@@ -191,10 +251,11 @@ TenantManager::Impl::runUponNewTenants(const vector<string> &new_tenants)
|
||||
}
|
||||
|
||||
void
|
||||
TenantManager::Impl::sendTenant(const vector<string> &tenants_id)
|
||||
TenantManager::Impl::sendTenantAndProfile(const string &tenant_id, const string &profile_id)
|
||||
{
|
||||
auto res = sendWithCustomPort(
|
||||
tenants_id,
|
||||
tenant_id,
|
||||
profile_id,
|
||||
getConfigurationWithDefault<uint16_t>(
|
||||
7777,
|
||||
"Tenant Manager",
|
||||
@@ -204,7 +265,8 @@ TenantManager::Impl::sendTenant(const vector<string> &tenants_id)
|
||||
|
||||
if (!res) {
|
||||
sendWithCustomPort(
|
||||
tenants_id,
|
||||
tenant_id,
|
||||
profile_id,
|
||||
getConfigurationWithDefault<uint16_t>(
|
||||
7778,
|
||||
"Tenant Manager",
|
||||
@@ -214,6 +276,66 @@ TenantManager::Impl::sendTenant(const vector<string> &tenants_id)
|
||||
}
|
||||
}
|
||||
|
||||
vector<string>
|
||||
TenantManager::Impl::getAllTenants() const
|
||||
{
|
||||
dbgFlow(D_TENANT_MANAGER) << "Tenant Manager is a client. Requesting the active tenants";
|
||||
|
||||
GetActiveTenants active_tenant;
|
||||
|
||||
auto res = i_messaging->sendObject(
|
||||
active_tenant,
|
||||
I_Messaging::Method::POST,
|
||||
"127.0.0.1",
|
||||
7777,
|
||||
conn_flags,
|
||||
"/show-active-tenants"
|
||||
);
|
||||
|
||||
if (!res) {
|
||||
i_messaging->sendObject(
|
||||
active_tenant,
|
||||
I_Messaging::Method::POST,
|
||||
"127.0.0.1",
|
||||
7778,
|
||||
conn_flags,
|
||||
"/show-active-tenants"
|
||||
);
|
||||
}
|
||||
|
||||
return active_tenant.active_tenants.get();
|
||||
}
|
||||
|
||||
vector<string>
|
||||
TenantManager::Impl::getProfileIds(const string &tenant_id) const
|
||||
{
|
||||
dbgFlow(D_TENANT_MANAGER) << "Tenant Manager is a client. Requesting the active tenants";
|
||||
|
||||
GetProfileIds profile_id(tenant_id);
|
||||
|
||||
auto res = i_messaging->sendObject(
|
||||
profile_id,
|
||||
I_Messaging::Method::POST,
|
||||
"127.0.0.1",
|
||||
7777,
|
||||
conn_flags,
|
||||
"/show-profile-ids"
|
||||
);
|
||||
|
||||
if (!res) {
|
||||
i_messaging->sendObject(
|
||||
profile_id,
|
||||
I_Messaging::Method::POST,
|
||||
"127.0.0.1",
|
||||
7778,
|
||||
conn_flags,
|
||||
"/show-profile-ids"
|
||||
);
|
||||
}
|
||||
|
||||
return profile_id.profile_ids.get();
|
||||
}
|
||||
|
||||
void
|
||||
TenantManager::Impl::uponNewTenants(const newTenantCB &cb)
|
||||
{
|
||||
@@ -221,69 +343,84 @@ TenantManager::Impl::uponNewTenants(const newTenantCB &cb)
|
||||
}
|
||||
|
||||
bool
|
||||
TenantManager::Impl::isTenantActive(const string &tenant_id) const
|
||||
TenantManager::Impl::areTenantAndProfileActive(const string &tenant_id, const string &profile_id) const
|
||||
{
|
||||
return active_tenants.doesKeyExists(tenant_id);
|
||||
return active_tenants.doesKeyExists(TenantProfilePair(tenant_id, profile_id));
|
||||
}
|
||||
|
||||
void
|
||||
TenantManager::Impl::addActiveTenant(const string &tenant_id)
|
||||
TenantManager::Impl::addActiveTenantAndProfile(const string &tenant_id, const string &profile_id)
|
||||
{
|
||||
active_tenants.createEntry(tenant_id);
|
||||
auto tenant_profile = TenantProfilePair(tenant_id, profile_id);
|
||||
active_tenants.createEntry(tenant_profile);
|
||||
if (type == TenantManagerType::CLIENT) {
|
||||
sendTenant({tenant_id});
|
||||
sendTenantAndProfile(tenant_id, profile_id);
|
||||
} else {
|
||||
runUponNewTenants({tenant_id});
|
||||
}
|
||||
}
|
||||
|
||||
void
|
||||
TenantManager::Impl::addActiveTenants(const vector<string> &tenants_id)
|
||||
TenantManager::Impl::deactivateTenant(const string &tenant_id, const string &profile_id)
|
||||
{
|
||||
for (const auto &tenant_id: tenants_id) active_tenants.createEntry(tenant_id);
|
||||
if (type == TenantManagerType::CLIENT) {
|
||||
sendTenant(tenants_id);
|
||||
} else {
|
||||
runUponNewTenants(tenants_id);
|
||||
}
|
||||
active_tenants.deleteEntry(TenantProfilePair(tenant_id, profile_id));
|
||||
}
|
||||
|
||||
void
|
||||
TenantManager::Impl::deactivateTenant(const string &tenant_id)
|
||||
vector<string>
|
||||
TenantManager::Impl::fetchAllActiveTenants() const
|
||||
{
|
||||
active_tenants.deleteEntry(tenant_id);
|
||||
}
|
||||
|
||||
void
|
||||
TenantManager::Impl::deactivateTenants(const vector<string> &tenants_id)
|
||||
{
|
||||
for (const auto &tenant_id: tenants_id) deactivateTenant(tenant_id);
|
||||
dbgFlow(D_TENANT_MANAGER) << "Fetching all active tenants";
|
||||
return (type == TenantManagerType::CLIENT) ? getAllTenants() : fetchActiveTenants();
|
||||
}
|
||||
|
||||
vector<string>
|
||||
TenantManager::Impl::fetchActiveTenants() const
|
||||
{
|
||||
dbgFlow(D_TENANT_MANAGER) << "Tenant Manager is a server. Fetching active tenants";
|
||||
vector<string> tenants;
|
||||
tenants.reserve(active_tenants.size());
|
||||
for (auto iter = begin(active_tenants); iter != end(active_tenants); iter++) {
|
||||
tenants.push_back(iter->first);
|
||||
dbgDebug(D_TENANT_MANAGER) << "Found a tenant to return. Tenant ID: " << iter->first.getTenantId();
|
||||
tenants.push_back(iter->first.getTenantId());
|
||||
}
|
||||
|
||||
return tenants;
|
||||
}
|
||||
|
||||
vector<string>
|
||||
TenantManager::Impl::getInstances(const string &tenant_id) const
|
||||
TenantManager::Impl::getInstances(const string &tenant_id, const string &profile_id) const
|
||||
{
|
||||
vector<string> tenants;
|
||||
vector<string> instances;
|
||||
auto tenant_profile_pair = TenantProfilePair(tenant_id, profile_id);
|
||||
auto tenant_instance_cache = mapper.find(tenant_profile_pair);
|
||||
|
||||
auto tenant_instance_cache = mapper.find(tenant_id);
|
||||
if (tenant_instance_cache == mapper.end()) return tenants;
|
||||
if (tenant_instance_cache == mapper.end()) return instances;
|
||||
|
||||
tenants.reserve(tenant_instance_cache->second.size());
|
||||
instances.reserve(tenant_instance_cache->second.size());
|
||||
for (auto iter = begin(tenant_instance_cache->second); iter != end(tenant_instance_cache->second); iter++) {
|
||||
tenants.push_back(iter->first);
|
||||
instances.push_back(iter->first);
|
||||
}
|
||||
return tenants;
|
||||
return instances;
|
||||
}
|
||||
|
||||
vector<string>
|
||||
TenantManager::Impl::fetchAllProfileIds(const string &tenant_id) const
|
||||
{
|
||||
vector<string> tenant_profile_ids;
|
||||
|
||||
for (auto iter = begin(active_tenants); iter != end(active_tenants); iter++) {
|
||||
if (iter->first.getTenantId() == tenant_id) {
|
||||
tenant_profile_ids.push_back(iter->first.getPfofileId());
|
||||
}
|
||||
}
|
||||
return tenant_profile_ids;
|
||||
}
|
||||
|
||||
vector<string>
|
||||
TenantManager::Impl::fetchProfileIds(const string &tenant_id) const
|
||||
{
|
||||
dbgFlow(D_TENANT_MANAGER) << "Fetching all profile ids for tenant " << tenant_id;
|
||||
return (type == TenantManagerType::CLIENT) ? getProfileIds(tenant_id) : fetchAllProfileIds(tenant_id);
|
||||
}
|
||||
|
||||
chrono::microseconds
|
||||
|
||||
Reference in New Issue
Block a user