File tree 3 files changed +6
-13
lines changed 3 files changed +6
-13
lines changed Original file line number Diff line number Diff line change 5
5
#include < logger.hpp>
6
6
#include < sca_policy_parser.hpp>
7
7
8
- #include < yaml-cpp/yaml.h>
9
-
10
8
#include < algorithm>
11
9
12
10
SCAPolicyLoader::SCAPolicyLoader (std::shared_ptr<IFileSystemWrapper> fileSystemWrapper,
@@ -65,14 +63,9 @@ std::vector<SCAPolicy> SCAPolicyLoader::GetPolicies(const CreateEventsFunc& crea
65
63
{
66
64
LogDebug (" Loading policy from {}" , path.string ());
67
65
68
- auto loadFunc = [](const std::filesystem::path& filename) -> YAML::Node
69
- {
70
- return YAML::LoadFile (filename.string ());
71
- };
66
+ const PolicyParser parser (path);
72
67
73
- const PolicyParser parser (path, loadFunc);
74
- auto policy = parser.ParsePolicy (policiesAndChecks);
75
- if (policy)
68
+ if (auto policy = parser.ParsePolicy (policiesAndChecks); policy)
76
69
{
77
70
policies.emplace_back (std::move (policy.value ()));
78
71
}
Original file line number Diff line number Diff line change @@ -71,15 +71,15 @@ namespace
71
71
}
72
72
} // namespace
73
73
74
- PolicyParser::PolicyParser (const std::filesystem::path& filename, const LoadFileFunc& loadFile )
74
+ PolicyParser::PolicyParser (const std::filesystem::path& filename, LoadFileFunc loadFileFunc )
75
75
{
76
76
try
77
77
{
78
78
if (!isValidYamlFile (filename))
79
79
{
80
80
throw std::runtime_error (" The file does not contain a valid YAML structure." );
81
81
}
82
- m_node = loadFile (filename);
82
+ m_node = loadFileFunc ? loadFileFunc (filename) : YAML::LoadFile (filename. string () );
83
83
auto variables = m_node[" variables" ];
84
84
if (variables)
85
85
{
Original file line number Diff line number Diff line change @@ -37,8 +37,8 @@ class PolicyParser
37
37
public:
38
38
// / @brief Constructs a PolicyParser and loads the YAML file.
39
39
// / @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 = {} );
42
42
43
43
// / @brief Checks if the specified YAML file is valid.
44
44
// /
You can’t perform that action at this time.
0 commit comments