Skip to content

Commit dc121c5

Browse files
committed
refactor: move YAML load function to policy parser
1 parent 18035f2 commit dc121c5

File tree

3 files changed

+6
-13
lines changed

3 files changed

+6
-13
lines changed

src/modules/sca/src/sca_policy_loader.cpp

Lines changed: 2 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -5,8 +5,6 @@
55
#include <logger.hpp>
66
#include <sca_policy_parser.hpp>
77

8-
#include <yaml-cpp/yaml.h>
9-
108
#include <algorithm>
119

1210
SCAPolicyLoader::SCAPolicyLoader(std::shared_ptr<IFileSystemWrapper> fileSystemWrapper,
@@ -65,14 +63,9 @@ std::vector<SCAPolicy> SCAPolicyLoader::GetPolicies(const CreateEventsFunc& crea
6563
{
6664
LogDebug("Loading policy from {}", path.string());
6765

68-
auto loadFunc = [](const std::filesystem::path& filename) -> YAML::Node
69-
{
70-
return YAML::LoadFile(filename.string());
71-
};
66+
const PolicyParser parser(path);
7267

73-
const PolicyParser parser(path, loadFunc);
74-
auto policy = parser.ParsePolicy(policiesAndChecks);
75-
if (policy)
68+
if (auto policy = parser.ParsePolicy(policiesAndChecks); policy)
7669
{
7770
policies.emplace_back(std::move(policy.value()));
7871
}

src/modules/sca/src/sca_policy_parser.cpp

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -71,15 +71,15 @@ namespace
7171
}
7272
} // namespace
7373

74-
PolicyParser::PolicyParser(const std::filesystem::path& filename, const LoadFileFunc& loadFile)
74+
PolicyParser::PolicyParser(const std::filesystem::path& filename, LoadFileFunc loadFileFunc)
7575
{
7676
try
7777
{
7878
if (!isValidYamlFile(filename))
7979
{
8080
throw std::runtime_error("The file does not contain a valid YAML structure.");
8181
}
82-
m_node = loadFile(filename);
82+
m_node = loadFileFunc ? loadFileFunc(filename) : YAML::LoadFile(filename.string());
8383
auto variables = m_node["variables"];
8484
if (variables)
8585
{

src/modules/sca/src/sca_policy_parser.hpp

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -37,8 +37,8 @@ class PolicyParser
3737
public:
3838
/// @brief Constructs a PolicyParser and loads the YAML file.
3939
/// @param filename Path to the YAML policy file.
40-
/// @param loadFile Function to load the YAML file.
41-
explicit PolicyParser(const std::filesystem::path& filename, const LoadFileFunc& loadFile);
40+
/// @param loadFileFunc Function to load the YAML file.
41+
explicit PolicyParser(const std::filesystem::path& filename, LoadFileFunc loadFileFunc = {});
4242

4343
/// @brief Checks if the specified YAML file is valid.
4444
///

0 commit comments

Comments
 (0)