mirror of
https://github.com/openappsec/openappsec.git
synced 2025-09-29 19:24:26 +03:00
My 11th 2023 update
This commit is contained in:
@@ -68,6 +68,19 @@ makeDir(const string &path, mode_t permission)
|
||||
return true;
|
||||
}
|
||||
|
||||
/// @brief Get basename of a path
|
||||
/// @param path path to a file
|
||||
/// @return base file name
|
||||
string
|
||||
getFileName(const string &path)
|
||||
{
|
||||
dbgFlow(D_INFRA_UTILS) << "Trying to extract file name from path: " << path;
|
||||
size_t pos = path.rfind("/");
|
||||
if (pos != string::npos) return path.substr(pos+1, path.length() - pos);
|
||||
|
||||
return path;
|
||||
}
|
||||
|
||||
bool
|
||||
makeDirRecursive(const string &path, mode_t permission)
|
||||
{
|
||||
|
@@ -77,6 +77,7 @@ TEST_F(AgentCoreUtilUT, directoryTest)
|
||||
EXPECT_TRUE(NGEN::Filesystem::deleteDirectory("/tmp/1", true));
|
||||
EXPECT_FALSE(NGEN::Filesystem::exists("/tmp/1"));
|
||||
}
|
||||
|
||||
TEST_F(AgentCoreUtilUT, printTest)
|
||||
{
|
||||
EXPECT_EQ(NGEN::Filesystem::convertToHumanReadable(0), "0 Bytes");
|
||||
@@ -96,3 +97,9 @@ TEST_F(AgentCoreUtilUT, printTest)
|
||||
EXPECT_EQ(NGEN::Filesystem::convertToHumanReadable(1000*gigabyte), "1000.00 GB");
|
||||
EXPECT_EQ(NGEN::Filesystem::convertToHumanReadable(1024*gigabyte), "1024.00 GB");
|
||||
}
|
||||
|
||||
|
||||
TEST_F(AgentCoreUtilUT, fileBasenameTest)
|
||||
{
|
||||
EXPECT_EQ(NGEN::Filesystem::getFileName("/test/base/file/name"), "name");
|
||||
}
|
||||
|
@@ -150,6 +150,8 @@ private:
|
||||
bool commitFailure(const string &error);
|
||||
bool reloadConfigurationImpl(const string &version, bool is_async);
|
||||
void reloadConfigurationContinuesWrapper(const string &version, uint id);
|
||||
vector<string> fillMultiTenantConfigFiles(const map<string, set<string>> &tenants);
|
||||
vector<string> fillMultiTenantExpectedConfigFiles(const map<string, set<string>> &tenants);
|
||||
|
||||
string
|
||||
getActiveTenant() const
|
||||
@@ -274,7 +276,7 @@ private:
|
||||
map<string, set<ConfigFileType>> expected_configuration_files;
|
||||
set<string> config_file_paths;
|
||||
|
||||
I_TenantManager *tenant_mananger = nullptr;
|
||||
I_TenantManager *tenant_manager = nullptr;
|
||||
|
||||
vector<ConfigCb> configuration_prepare_cbs;
|
||||
vector<ConfigCb> configuration_commit_cbs;
|
||||
@@ -322,7 +324,7 @@ void
|
||||
ConfigComponent::Impl::init()
|
||||
{
|
||||
reloadFileSystemPaths();
|
||||
tenant_mananger = Singleton::Consume<I_TenantManager>::by<ConfigComponent>();
|
||||
tenant_manager = Singleton::Consume<I_TenantManager>::by<ConfigComponent>();
|
||||
|
||||
if (!Singleton::exists<I_MainLoop>()) return;
|
||||
auto mainloop = Singleton::Consume<I_MainLoop>::by<ConfigComponent>();
|
||||
@@ -338,7 +340,7 @@ ConfigComponent::Impl::init()
|
||||
|
||||
mainloop->addRecurringRoutine(
|
||||
I_MainLoop::RoutineType::System,
|
||||
tenant_mananger->getTimeoutVal(),
|
||||
tenant_manager->getTimeoutVal(),
|
||||
[this] () { clearOldTenants(); },
|
||||
"Config comp old tenant cleanup"
|
||||
);
|
||||
@@ -681,7 +683,7 @@ bool
|
||||
ConfigComponent::Impl::areTenantAndProfileActive(const TenantProfilePair &tenant_profile) const
|
||||
{
|
||||
return (tenant_profile.getTenantId() == default_tenant_id && tenant_profile.getProfileId() == default_profile_id)
|
||||
|| tenant_mananger->areTenantAndProfileActive(tenant_profile.getTenantId(), tenant_profile.getProfileId());
|
||||
|| tenant_manager->areTenantAndProfileActive(tenant_profile.getTenantId(), tenant_profile.getProfileId());
|
||||
}
|
||||
|
||||
void
|
||||
@@ -817,6 +819,45 @@ ConfigComponent::Impl::commitFailure(const string &error)
|
||||
return false;
|
||||
}
|
||||
|
||||
vector<string>
|
||||
ConfigComponent::Impl::fillMultiTenantConfigFiles(const map<string, set<string>> &active_tenants)
|
||||
{
|
||||
vector<string> files;
|
||||
for (const auto &tenant_profiles : active_tenants) {
|
||||
const string &tenant = tenant_profiles.first;
|
||||
const set<string> &profile_ids = tenant_profiles.second;
|
||||
for (const auto &profile_id : profile_ids) {
|
||||
string settings_path =
|
||||
config_directory_path + "tenant_" + tenant + "_profile_" + profile_id + "_settings.json";
|
||||
files.push_back(settings_path);
|
||||
}
|
||||
}
|
||||
return files;
|
||||
}
|
||||
|
||||
vector<string>
|
||||
ConfigComponent::Impl::fillMultiTenantExpectedConfigFiles(const map<string, set<string>> &active_tenants)
|
||||
{
|
||||
vector<string> files;
|
||||
for (const auto &config_file : expected_configuration_files) {
|
||||
for (const auto &type : config_file.second) {
|
||||
if (type == ConfigFileType::RawData) continue;
|
||||
auto global_path = getPolicyConfigPath(config_file.first, type);
|
||||
auto it = find(files.begin(), files.end(), global_path);
|
||||
if (it == files.end()) files.push_back(global_path);
|
||||
for (const pair<string, set<string>> &tenant_profiles : active_tenants) {
|
||||
const string &tenant = tenant_profiles.first;
|
||||
const set<string> &profile_ids = tenant_profiles.second;
|
||||
for (const auto &profile_id : profile_ids) {
|
||||
auto tenant_path = getPolicyConfigPath(config_file.first, type, tenant, profile_id);
|
||||
files.push_back(tenant_path);
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
return files;
|
||||
}
|
||||
|
||||
bool
|
||||
ConfigComponent::Impl::reloadConfigurationImpl(const string &version, bool is_async)
|
||||
{
|
||||
@@ -831,38 +872,20 @@ ConfigComponent::Impl::reloadConfigurationImpl(const string &version, bool is_as
|
||||
files.emplace(fullpath, make_shared<ifstream>(fullpath));
|
||||
}
|
||||
|
||||
const auto &active_tenants = tenant_mananger ? tenant_mananger->fetchAllActiveTenants() : vector<string>();
|
||||
map<string, set<string>> active_tenants =
|
||||
tenant_manager ? tenant_manager->fetchActiveTenantsAndProfiles() : map<string, set<string>>();
|
||||
|
||||
dbgTrace(D_CONFIG) << "Number of active tenants found while reloading configuration: " << active_tenants.size();
|
||||
|
||||
for (const auto &config_file : expected_configuration_files) {
|
||||
for (const auto &type : config_file.second) {
|
||||
if (type == ConfigFileType::RawData) continue;
|
||||
auto global_path = getPolicyConfigPath(config_file.first, type);
|
||||
if (files.find(global_path) == files.end()) {
|
||||
files.emplace(global_path, make_shared<ifstream>(global_path));
|
||||
}
|
||||
|
||||
for (auto &tenant : active_tenants) {
|
||||
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));
|
||||
}
|
||||
}
|
||||
}
|
||||
const vector<string> &config_files = fillMultiTenantConfigFiles(active_tenants);
|
||||
const vector<string> &expected_config_files = fillMultiTenantExpectedConfigFiles(active_tenants);
|
||||
for (const string &file : config_files) {
|
||||
dbgTrace(D_CONFIG) << "Inserting " << file << " to the list of files to be handled";
|
||||
files.emplace(file, make_shared<ifstream>(file));
|
||||
}
|
||||
|
||||
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_"+ profile_id + "_settings.json";
|
||||
dbgTrace(D_CONFIG) << "Inserting a settings path: " << settings_path;
|
||||
files.emplace(settings_path, make_shared<ifstream>(settings_path));
|
||||
}
|
||||
for (const string &file : expected_config_files) {
|
||||
dbgTrace(D_CONFIG) << "Inserting " << file << " to the list of files to be handled";
|
||||
files.emplace(file, make_shared<ifstream>(file));
|
||||
}
|
||||
|
||||
vector<shared_ptr<JSONInputArchive>> archives;
|
||||
@@ -883,6 +906,7 @@ ConfigComponent::Impl::reloadConfigurationImpl(const string &version, bool is_as
|
||||
void
|
||||
ConfigComponent::Impl::reloadConfigurationContinuesWrapper(const string &version, uint id)
|
||||
{
|
||||
dbgFlow(D_CONFIG) << "Running reloadConfigurationContinuesWrapper. Version: " << version << ", Id: " << id;
|
||||
auto mainloop = Singleton::Consume<I_MainLoop>::by<ConfigComponent>();
|
||||
|
||||
LoadNewConfigurationStatus in_progress(id, false, false);
|
||||
|
@@ -22,7 +22,7 @@
|
||||
class I_Socket
|
||||
{
|
||||
public:
|
||||
enum class SocketType { UNIX, TCP, UDP };
|
||||
enum class SocketType { UNIX, UNIXDG, TCP, UDP };
|
||||
using socketFd = int;
|
||||
|
||||
virtual Maybe<socketFd>
|
||||
|
@@ -16,6 +16,8 @@
|
||||
|
||||
#include <string>
|
||||
#include <vector>
|
||||
#include <set>
|
||||
#include <map>
|
||||
#include <chrono>
|
||||
#include <functional>
|
||||
|
||||
@@ -27,13 +29,14 @@ public:
|
||||
virtual void uponNewTenants(const newTenantCB &cb) = 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> fetchAllActiveTenants() const = 0;
|
||||
virtual std::vector<std::string> getInstances(
|
||||
virtual std::set<std::string> fetchAllActiveTenants() const = 0;
|
||||
virtual std::set<std::string> fetchActiveTenants() const = 0;
|
||||
virtual std::set<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 std::map<std::string, std::set<std::string>> fetchActiveTenantsAndProfiles() const = 0;
|
||||
virtual std::set<std::string> fetchProfileIds(const std::string &tenant_id) const = 0;
|
||||
|
||||
virtual void deactivateTenant(const std::string &tenant_id, const std::string &profile_id) = 0;
|
||||
|
||||
@@ -41,7 +44,7 @@ public:
|
||||
|
||||
virtual std::chrono::microseconds getTimeoutVal() const = 0;
|
||||
|
||||
virtual std::vector<std::string> getProfileId(
|
||||
virtual std::set<std::string> getProfileIdsForRegionAccount(
|
||||
const std::string &tenant_id,
|
||||
const std::string ®ion,
|
||||
const std::string &account_id = ""
|
||||
|
@@ -81,6 +81,7 @@ IntelligenceQuery<UserSerializableReplyAttr>::load(cereal::JSONInputArchive &ar)
|
||||
unsigned int valid_idx = 0;
|
||||
const auto &valid_response = bulk_response.getValid();
|
||||
const auto &errors = bulk_response.getErrors();
|
||||
responses.clear();
|
||||
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++) {
|
||||
|
@@ -15,19 +15,20 @@ class MockTenantManager : public Singleton::Provide<I_TenantManager>::From<MockP
|
||||
public:
|
||||
MOCK_METHOD1(uponNewTenants, void(const I_TenantManager::newTenantCB &cb));
|
||||
|
||||
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_METHOD0(fetchActiveTenantsAndProfiles, std::map<std::string, std::set<std::string>>());
|
||||
MOCK_CONST_METHOD0(fetchActiveTenants, std::set<std::string>());
|
||||
MOCK_CONST_METHOD0(fetchAllActiveTenants, std::set<std::string>());
|
||||
MOCK_CONST_METHOD1(fetchProfileIds, std::set<std::string>(const std::string &));
|
||||
MOCK_CONST_METHOD2(
|
||||
getInstances,
|
||||
std::vector<std::string>(const std::string &, const std::string &)
|
||||
std::set<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_CONST_METHOD3(
|
||||
getProfileId,
|
||||
std::vector<std::string>(const std::string &, const std::string &, const std::string &)
|
||||
getProfileIdsForRegionAccount,
|
||||
std::set<std::string>(const std::string &, const std::string &, const std::string &)
|
||||
);
|
||||
|
||||
MOCK_CONST_METHOD0(getTimeoutVal, std::chrono::microseconds());
|
||||
|
@@ -137,6 +137,7 @@ DEFINE_FLAG(D_COMPONENT, D_ALL)
|
||||
DEFINE_FLAG(D_NGINX_MESSAGE_READER, D_REVERSE_PROXY)
|
||||
DEFINE_FLAG(D_ERROR_REPORTER, D_REVERSE_PROXY)
|
||||
DEFINE_FLAG(D_UPSTREAM_KEEPALIVE, D_REVERSE_PROXY)
|
||||
DEFINE_FLAG(D_FORWARD_PROXY, D_REVERSE_PROXY)
|
||||
|
||||
DEFINE_FLAG(D_IDA, D_COMPONENT)
|
||||
|
||||
@@ -166,6 +167,7 @@ DEFINE_FLAG(D_COMPONENT, D_ALL)
|
||||
DEFINE_FLAG(D_URL_FILTERING, D_COMPONENT)
|
||||
DEFINE_FLAG(D_L7_ACCESS_CONTROL, D_COMPONENT)
|
||||
DEFINE_FLAG(D_IOT_ACCESS_CONTROL, D_COMPONENT)
|
||||
DEFINE_FLAG(D_HORIZON_TELEMETRY, D_COMPONENT)
|
||||
|
||||
DEFINE_FLAG(D_FLOW, D_ALL)
|
||||
DEFINE_FLAG(D_DROP, D_FLOW)
|
||||
|
@@ -62,6 +62,7 @@ enum class Tags {
|
||||
DEPLOYMENT_EMBEDDED,
|
||||
DEPLOYMENT_K8S,
|
||||
LAYER_7_ACCESS_CONTROL,
|
||||
HORIZON_TELEMETRY_METRICS,
|
||||
|
||||
COUNT
|
||||
};
|
||||
@@ -76,6 +77,7 @@ enum class AudienceTeam
|
||||
SIGNATURE_DEVELOPERS,
|
||||
FILE_UPLOAD,
|
||||
IDENTITY_AWARENESS,
|
||||
HORIZON_TELEMETRY,
|
||||
NONE,
|
||||
|
||||
COUNT
|
||||
@@ -147,7 +149,8 @@ enum class IssuingEngine {
|
||||
IOT_NEXT,
|
||||
SDWAN,
|
||||
FILE_UPLOAD,
|
||||
IDA_NEXT
|
||||
IDA_NEXT,
|
||||
HORIZON_TELEMETRY_METRICS
|
||||
};
|
||||
|
||||
} // namespace ReportIS
|
||||
|
@@ -42,6 +42,8 @@ bool deleteFile(const std::string &path);
|
||||
|
||||
std::string convertToHumanReadable(uint64_t size_in_bytes);
|
||||
|
||||
std::string getFileName(const std::string &path);
|
||||
|
||||
}// namespace Filesystem
|
||||
|
||||
namespace Regex
|
||||
|
@@ -104,7 +104,8 @@ TagAndEnumManagement::convertStringToTag(const string &tag)
|
||||
{"Kong Server", ReportIS::Tags::WEB_SERVER_KONG},
|
||||
{"Embedded Deployment", ReportIS::Tags::DEPLOYMENT_EMBEDDED},
|
||||
{"Kubernetes Deployment", ReportIS::Tags::DEPLOYMENT_K8S},
|
||||
{"Layer 7 Access Control", ReportIS::Tags::LAYER_7_ACCESS_CONTROL}
|
||||
{"Layer 7 Access Control", ReportIS::Tags::LAYER_7_ACCESS_CONTROL},
|
||||
{"Horizon Telemetry Metrics", ReportIS::Tags::HORIZON_TELEMETRY_METRICS}
|
||||
};
|
||||
|
||||
auto report_is_tag = strings_to_tags.find(tag);
|
||||
@@ -264,6 +265,7 @@ TagAndEnumManagement::convertToString(const IssuingEngine &issuing_engine)
|
||||
case IssuingEngine::SDWAN: return "sdwanGwSharing";
|
||||
case IssuingEngine::FILE_UPLOAD: return "fileUpload";
|
||||
case IssuingEngine::IDA_NEXT: return "quantumMetaNotifyIdn";
|
||||
case IssuingEngine::HORIZON_TELEMETRY_METRICS: return "horizonTelemetryMetrics";
|
||||
}
|
||||
|
||||
dbgAssert(false) << "Reached impossible engine value of: " << static_cast<int>(issuing_engine);
|
||||
@@ -302,7 +304,8 @@ EnumArray<Tags, string> TagAndEnumManagement::tags_translation_arr {
|
||||
"Kong Server",
|
||||
"Embedded Deployment",
|
||||
"Kubernetes Deployment",
|
||||
"Layer 7 Access Control"
|
||||
"Layer 7 Access Control",
|
||||
"Horizon Telemetry Metrics"
|
||||
};
|
||||
|
||||
EnumArray<AudienceTeam, string> TagAndEnumManagement::audience_team_translation {
|
||||
@@ -312,5 +315,6 @@ EnumArray<AudienceTeam, string> TagAndEnumManagement::audience_team_translation
|
||||
"Agent Intelligence",
|
||||
"cpviewMonitoring",
|
||||
"Signature Developers",
|
||||
"Identity Awareness"
|
||||
"Identity Awareness",
|
||||
"unifiedMonitoring"
|
||||
};
|
||||
|
@@ -489,6 +489,109 @@ private:
|
||||
struct sockaddr_un server;
|
||||
};
|
||||
|
||||
class UnixDGSocket : public SocketInternal
|
||||
{
|
||||
public:
|
||||
static Maybe<unique_ptr<UnixDGSocket>>
|
||||
connectSock(bool _is_blocking, bool _is_server, const string &_address)
|
||||
{
|
||||
unique_ptr<UnixDGSocket> unix_socket(make_unique<UnixDGSocket>(_is_blocking, _is_server));
|
||||
if (unix_socket->getSocket() <= 0) return genError("Failed to create socket");
|
||||
|
||||
unix_socket->server.sun_family = AF_UNIX;
|
||||
strncpy(unix_socket->server.sun_path, _address.c_str(), sizeof(unix_socket->server.sun_path) - 1);
|
||||
|
||||
if (!unix_socket->isServerSock()) {
|
||||
if (connect(
|
||||
unix_socket->getSocket(),
|
||||
reinterpret_cast<struct sockaddr *>(&unix_socket->server),
|
||||
sizeof(struct sockaddr_un)
|
||||
) == -1
|
||||
) {
|
||||
return genError("Failed to connect socket");
|
||||
}
|
||||
return move(unix_socket);
|
||||
}
|
||||
|
||||
static const int on = 1;
|
||||
if (setsockopt(unix_socket->getSocket(), SOL_SOCKET, SO_REUSEADDR, (char *)&on, sizeof(on)) < 0) {
|
||||
dbgWarning(D_SOCKET) << "Failed to set the socket descriptor as reusable";
|
||||
return genError("Failed to set the socket descriptor as reusable");
|
||||
}
|
||||
|
||||
const int priority = 6;
|
||||
if (setsockopt(unix_socket->getSocket(), SOL_SOCKET, SO_PRIORITY, (char *)&priority, sizeof(priority)) < 0) {
|
||||
dbgWarning(D_SOCKET) << "Failed to set the socket priority to highest";
|
||||
return genError("Failed to set the socket priority to highest");
|
||||
}
|
||||
|
||||
if (ioctl(unix_socket->getSocket(), FIONBIO, (char *)&on) < 0) {
|
||||
dbgWarning(D_SOCKET) << "Failed to set the socket as non-blocking";
|
||||
return genError("Failed to set the socket as non-blocking");
|
||||
}
|
||||
|
||||
unlink(unix_socket->server.sun_path);
|
||||
if (bind(
|
||||
unix_socket->getSocket(),
|
||||
reinterpret_cast<struct sockaddr *>(&unix_socket->server),
|
||||
sizeof(struct sockaddr_un)
|
||||
) == -1) {
|
||||
dbgWarning(D_SOCKET) << "Failed to bind the socket: " << strerror(errno);
|
||||
return genError("Failed to bind the socket");
|
||||
}
|
||||
|
||||
chmod(unix_socket->server.sun_path, 0666);
|
||||
|
||||
return move(unix_socket);
|
||||
}
|
||||
|
||||
void cleanServer() override
|
||||
{
|
||||
unlink(server.sun_path);
|
||||
}
|
||||
|
||||
Maybe<vector<char>>
|
||||
receiveDataBlocking(uint data_size) override
|
||||
{
|
||||
return receiveDGData(data_size, MSG_DONTWAIT);
|
||||
}
|
||||
|
||||
Maybe<vector<char>>
|
||||
receiveDataNonBlocking(uint data_size) override
|
||||
{
|
||||
return receiveDGData(data_size, 0);
|
||||
}
|
||||
|
||||
Maybe<vector<char>>
|
||||
receiveDGData(uint data_size, int flag)
|
||||
{
|
||||
if (data_size == 0) data_size = udp_max_packet_size;
|
||||
dbgDebug(D_SOCKET) << "data_size: " << data_size;
|
||||
vector<char> param_to_read(data_size, 0);
|
||||
int res = recv(socket_int, param_to_read.data(), data_size, flag);
|
||||
|
||||
if (res == -1) {
|
||||
string error_message = strerror(errno);
|
||||
dbgWarning(D_SOCKET) << "Failed to read data, Error: " + error_message;
|
||||
return genError(
|
||||
"Failed to read data, Error: " + error_message
|
||||
);
|
||||
}
|
||||
param_to_read.resize(res);
|
||||
return param_to_read;
|
||||
}
|
||||
|
||||
UnixDGSocket(bool _is_blocking, bool _is_server_socket)
|
||||
:
|
||||
SocketInternal(_is_blocking, _is_server_socket)
|
||||
{
|
||||
socket_int = socket(AF_UNIX, SOCK_DGRAM, 0);
|
||||
}
|
||||
|
||||
private:
|
||||
struct sockaddr_un server;
|
||||
};
|
||||
|
||||
class SocketIS::Impl
|
||||
:
|
||||
Singleton::Provide<I_Socket>::From<SocketIS>
|
||||
@@ -527,6 +630,11 @@ SocketIS::Impl::genSocket(
|
||||
if (!unix_sock.ok()) return unix_sock.passErr();
|
||||
new_sock = unix_sock.unpackMove();
|
||||
socketTypeName = "UNIX";
|
||||
} else if (type == SocketType::UNIXDG) {
|
||||
Maybe<unique_ptr<SocketInternal>> unix_dg_sock = UnixDGSocket::connectSock(is_blocking, is_server, address);
|
||||
if (!unix_dg_sock.ok()) return unix_dg_sock.passErr();
|
||||
new_sock = unix_dg_sock.unpackMove();
|
||||
socketTypeName = "UNIXDG";
|
||||
} else if (type == SocketType::TCP) {
|
||||
Maybe<unique_ptr<SocketInternal>> tcp_sock = TCPSocket::connectSock(is_blocking, is_server, address);
|
||||
if (!tcp_sock.ok()) return tcp_sock.passErr();
|
||||
|
@@ -78,10 +78,11 @@ public:
|
||||
void uponNewTenants(const newTenantCB &cb) 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 string &profile_id) const override;
|
||||
vector<string> fetchProfileIds(const string &tenant_id) const override;
|
||||
map<string, set<string>> fetchActiveTenantsAndProfiles() const override;
|
||||
set<string> fetchAllActiveTenants() const override;
|
||||
set<string> fetchActiveTenants() const override;
|
||||
set<string> getInstances(const string &tenant_id, const string &profile_id) const override;
|
||||
set<string> fetchProfileIds(const string &tenant_id) const override;
|
||||
|
||||
void addActiveTenantAndProfile(const string &tenant_id, const string &profile_id) override;
|
||||
|
||||
@@ -89,7 +90,11 @@ public:
|
||||
|
||||
chrono::microseconds getTimeoutVal() const override;
|
||||
|
||||
vector<string> getProfileId(const string &tenant_id, const string ®ion, const string &account) const override;
|
||||
set<string> getProfileIdsForRegionAccount(
|
||||
const string &tenant_id,
|
||||
const string ®ion,
|
||||
const string &account
|
||||
) const override;
|
||||
|
||||
void
|
||||
addInstance(const string &tenant_id, const string &profile_id, const string &instace_id)
|
||||
@@ -111,9 +116,9 @@ public:
|
||||
private:
|
||||
void runUponNewTenants(const vector<string> &new_tenants);
|
||||
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;
|
||||
set<string> getAllTenants() const;
|
||||
set<string> fetchAllProfileIds(const string &tenant_id) const;
|
||||
set<string> getProfileIds(const string &tenant_id) const;
|
||||
bool sendWithCustomPort(const string &tenant_id, const string &profile_id, const uint16_t port);
|
||||
|
||||
TemporaryCache<TenantProfilePair, void> active_tenants;
|
||||
@@ -169,7 +174,7 @@ public:
|
||||
active_tenants = Singleton::Consume<I_TenantManager>::from<TenantManager>()->fetchAllActiveTenants();
|
||||
}
|
||||
|
||||
S2C_PARAM(std::vector<std::string>, active_tenants);
|
||||
S2C_PARAM(set<string>, active_tenants);
|
||||
};
|
||||
|
||||
class GetActiveTenants : public ClientRest
|
||||
@@ -179,7 +184,7 @@ public:
|
||||
|
||||
Maybe<string> genJson() const { return string("{}"); };
|
||||
|
||||
S2C_PARAM(vector<string>, active_tenants);
|
||||
S2C_PARAM(set<string>, active_tenants);
|
||||
};
|
||||
|
||||
class FetchProfileIds : public ServerRest
|
||||
@@ -191,7 +196,7 @@ public:
|
||||
profile_ids = Singleton::Consume<I_TenantManager>::from<TenantManager>()->fetchProfileIds(tenant_id);
|
||||
}
|
||||
|
||||
S2C_PARAM(vector<string>, profile_ids);
|
||||
S2C_PARAM(set<string>, profile_ids);
|
||||
C2S_PARAM(string, tenant_id);
|
||||
};
|
||||
|
||||
@@ -200,7 +205,7 @@ class GetProfileIds : public ClientRest
|
||||
public:
|
||||
GetProfileIds(const string &_tenant_id) : profile_ids(), tenant_id(_tenant_id) {};
|
||||
|
||||
S2C_PARAM(vector<string>, profile_ids);
|
||||
S2C_PARAM(set<string>, profile_ids);
|
||||
C2S_PARAM(string, tenant_id);
|
||||
};
|
||||
|
||||
@@ -318,7 +323,7 @@ TenantManager::Impl::sendTenantAndProfile(const string &tenant_id, const string
|
||||
}
|
||||
}
|
||||
|
||||
vector<string>
|
||||
set<string>
|
||||
TenantManager::Impl::getAllTenants() const
|
||||
{
|
||||
dbgFlow(D_TENANT_MANAGER) << "Tenant Manager is a client. Requesting the active tenants";
|
||||
@@ -348,7 +353,7 @@ TenantManager::Impl::getAllTenants() const
|
||||
return active_tenant.active_tenants.get();
|
||||
}
|
||||
|
||||
vector<string>
|
||||
set<string>
|
||||
TenantManager::Impl::getProfileIds(const string &_tenant_id) const
|
||||
{
|
||||
dbgFlow(D_TENANT_MANAGER) << "Tenant Manager is a client. Requesting the active profiles";
|
||||
@@ -379,22 +384,25 @@ TenantManager::Impl::getProfileIds(const string &_tenant_id) const
|
||||
}
|
||||
|
||||
|
||||
vector<string>
|
||||
TenantManager::Impl::getProfileId(const string &tenant_id, const string ®ion, const string &account_id = "") const
|
||||
set<string>
|
||||
TenantManager::Impl::getProfileIdsForRegionAccount(
|
||||
const string &tenant_id,
|
||||
const string ®ion,
|
||||
const string &account_id = "") const
|
||||
{
|
||||
if (region.empty()) {
|
||||
dbgWarning(D_TENANT_MANAGER) << "Can't find the profile ID. Region is empty";
|
||||
return vector<string>();
|
||||
return set<string>();
|
||||
}
|
||||
|
||||
vector<string> profile_ids = fetchProfileIds(tenant_id);
|
||||
set<string> profile_ids = fetchProfileIds(tenant_id);
|
||||
|
||||
dbgTrace(D_TENANT_MANAGER) << "Fetched " << profile_ids.size() << " profiles";
|
||||
|
||||
auto i_env = Singleton::Consume<I_Environment>::by<TenantManager>();
|
||||
auto unset_tenant_on_exit = make_scope_exit([&]() { i_env->unsetActiveTenantAndProfile(); });
|
||||
|
||||
vector<string> profiles_to_return;
|
||||
set<string> profiles_to_return;
|
||||
for (const string &profile_id : profile_ids) {
|
||||
string account_dbg = account_id.empty() ? "" : (" in the account " + account_id);
|
||||
dbgDebug(D_TENANT_MANAGER)
|
||||
@@ -413,20 +421,20 @@ TenantManager::Impl::getProfileId(const string &tenant_id, const string ®ion,
|
||||
auto account_region_set = maybe_account_region_set.unpack().getAccoutRegionPairs();
|
||||
if (account_region_set.empty()) {
|
||||
dbgTrace(D_TENANT_MANAGER) << "Old profile with new hook. Resolving to profile ID: " << profile_id;
|
||||
profiles_to_return.push_back(profile_id);
|
||||
profiles_to_return.insert(profile_id);
|
||||
return profiles_to_return;
|
||||
}
|
||||
for (const AccountRegionPair &account : account_region_set) {
|
||||
if (region == account.getRegion() && (account_id.empty() || account_id == account.getAccountID())) {
|
||||
dbgTrace(D_TENANT_MANAGER) << "Found a corresponding profile ID: " << profile_id;
|
||||
profiles_to_return.push_back(profile_id);
|
||||
profiles_to_return.insert(profile_id);
|
||||
}
|
||||
}
|
||||
} else {
|
||||
auto maybe_region = getSetting<string>("region");
|
||||
if (maybe_region.ok() && region == maybe_region.unpack()) {
|
||||
dbgDebug(D_TENANT_MANAGER) << "The region corresponds to profile ID " << profile_id;
|
||||
profiles_to_return.push_back(profile_id);
|
||||
profiles_to_return.insert(profile_id);
|
||||
return profiles_to_return;
|
||||
} else {
|
||||
if (maybe_region.ok()) {
|
||||
@@ -448,7 +456,7 @@ TenantManager::Impl::getProfileId(const string &tenant_id, const string ®ion,
|
||||
}
|
||||
|
||||
dbgWarning(D_TENANT_MANAGER) << "Found no corresponding profile ID";
|
||||
return vector<string>();
|
||||
return set<string>();
|
||||
}
|
||||
|
||||
void
|
||||
@@ -490,58 +498,69 @@ TenantManager::Impl::deactivateTenant(const string &tenant_id, const string &pro
|
||||
active_tenants.deleteEntry(TenantProfilePair(tenant_id, profile_id));
|
||||
}
|
||||
|
||||
vector<string>
|
||||
map<string, set<string>>
|
||||
TenantManager::Impl::fetchActiveTenantsAndProfiles() const
|
||||
{
|
||||
dbgFlow(D_TENANT_MANAGER) << "Fetching active teants and profiles map";
|
||||
map<string, set<string>> active_tenants_and_profiles;
|
||||
set<string> tenants = fetchAllActiveTenants();
|
||||
for (const string &tenant : tenants) {
|
||||
active_tenants_and_profiles[tenant] = fetchProfileIds(tenant);
|
||||
}
|
||||
|
||||
return active_tenants_and_profiles;
|
||||
}
|
||||
|
||||
set<string>
|
||||
TenantManager::Impl::fetchAllActiveTenants() const
|
||||
{
|
||||
dbgFlow(D_TENANT_MANAGER) << "Fetching all active tenants";
|
||||
return (type == TenantManagerType::CLIENT) ? getAllTenants() : fetchActiveTenants();
|
||||
}
|
||||
|
||||
vector<string>
|
||||
set<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++) {
|
||||
dbgDebug(D_TENANT_MANAGER) << "Found a tenant to return. Tenant ID: " << iter->first.getTenantId();
|
||||
tenants.push_back(iter->first.getTenantId());
|
||||
set<string> tenants;
|
||||
for (const auto &iter : active_tenants) {
|
||||
dbgDebug(D_TENANT_MANAGER) << "Found a tenant to return. Tenant ID: " << iter.first.getTenantId();
|
||||
tenants.insert(iter.first.getTenantId());
|
||||
}
|
||||
|
||||
return tenants;
|
||||
}
|
||||
|
||||
vector<string>
|
||||
set<string>
|
||||
TenantManager::Impl::getInstances(const string &tenant_id, const string &profile_id) const
|
||||
{
|
||||
vector<string> instances;
|
||||
set<string> instances;
|
||||
auto tenant_profile_pair = TenantProfilePair(tenant_id, profile_id);
|
||||
auto tenant_instance_cache = mapper.find(tenant_profile_pair);
|
||||
|
||||
if (tenant_instance_cache == mapper.end()) return instances;
|
||||
|
||||
instances.reserve(tenant_instance_cache->second.size());
|
||||
for (auto iter = begin(tenant_instance_cache->second); iter != end(tenant_instance_cache->second); iter++) {
|
||||
instances.push_back(iter->first);
|
||||
instances.insert(iter->first);
|
||||
}
|
||||
return instances;
|
||||
}
|
||||
|
||||
vector<string>
|
||||
set<string>
|
||||
TenantManager::Impl::fetchAllProfileIds(const string &tenant_id) const
|
||||
{
|
||||
vector<string> tenant_profile_ids;
|
||||
set<string> tenant_profile_ids;
|
||||
|
||||
for (auto iter = begin(active_tenants); iter != end(active_tenants); iter++) {
|
||||
if (iter->first.getTenantId() == tenant_id) {
|
||||
dbgTrace(D_TENANT_MANAGER) << "Returning a fetched profile ID: " << iter->first.getProfileId();
|
||||
tenant_profile_ids.push_back(iter->first.getProfileId());
|
||||
tenant_profile_ids.insert(iter->first.getProfileId());
|
||||
}
|
||||
}
|
||||
return tenant_profile_ids;
|
||||
}
|
||||
|
||||
vector<string>
|
||||
set<string>
|
||||
TenantManager::Impl::fetchProfileIds(const string &tenant_id) const
|
||||
{
|
||||
dbgFlow(D_TENANT_MANAGER) << "Fetching all profile IDs for tenant " << tenant_id;
|
||||
|
Reference in New Issue
Block a user