Skip to content

Commit

Permalink
Merge pull request #556 from wazuh/enhancement/514-checks-centralized…
Browse files Browse the repository at this point in the history
…-configuration-files

Check access and validation of centralized configuration files
  • Loading branch information
TomasTurina authored Jan 29, 2025
2 parents b8c1d36 + 9ccf5de commit 706733c
Showing 1 changed file with 22 additions and 1 deletion.
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,27 @@
#include <config.h>
#include <logger.hpp>

#include <chrono>
#include <filesystem>
#include <random>

namespace
{
std::string CreateTmpFilename()
{
constexpr int MIN_VALUE = 1000;
constexpr int MAX_VALUE = 9999;
std::random_device rd;
std::mt19937 generator(rd());
std::uniform_int_distribution<int> distribution(MIN_VALUE, MAX_VALUE);
int random = distribution(generator);

auto now = std::chrono::high_resolution_clock::now();
auto timestamp = now.time_since_epoch().count();

return std::to_string(timestamp) + "_" + std::to_string(random);
}
} // namespace

namespace centralized_configuration
{
Expand Down Expand Up @@ -90,7 +110,8 @@ namespace centralized_configuration
for (const auto& groupId : groupIds)
{
const std::filesystem::path tmpGroupFile =
m_fileSystemWrapper->temp_directory_path() / (groupId + config::DEFAULT_SHARED_FILE_EXTENSION);
m_fileSystemWrapper->temp_directory_path() /
(groupId + "_" + CreateTmpFilename() + config::DEFAULT_SHARED_FILE_EXTENSION);

const auto dlResult = co_await m_downloadGroupFilesFunction(groupId, tmpGroupFile.string());

Expand Down

0 comments on commit 706733c

Please sign in to comment.