Skip to content
Draft
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
1 change: 1 addition & 0 deletions src/modules/complianceengine/src/lib/CMakeLists.txt
Original file line number Diff line number Diff line change
Expand Up @@ -28,6 +28,7 @@ add_library(complianceenginelib STATIC
CommonContext.cpp
ComplianceEngineInterface.cpp
ContextInterface.cpp
DirectoryEntry.cpp
Engine.cpp
Evaluator.cpp
KernelModuleTools.cpp
Expand Down
17 changes: 17 additions & 0 deletions src/modules/complianceengine/src/lib/CommonContext.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -36,4 +36,21 @@ Result<std::string> CommonContext::GetFileContents(const std::string& filePath)
return result;
}

Result<DirectoryEntries> CommonContext::GetDirectoryEntries(const std::string& directoryPath, bool recursive) const
{
try
{
auto entries = mDirectoryIterator->GetEntries(directoryPath, recursive);
return entries;
}
catch (const std::exception& e)
{
return Error("Failed to get directory entries: " + std::string(e.what()));
}
catch (...)
{
return Error("Failed to get directory entries: unknown error");
}
}

} // namespace ComplianceEngine
7 changes: 6 additions & 1 deletion src/modules/complianceengine/src/lib/CommonContext.h
Original file line number Diff line number Diff line change
Expand Up @@ -5,9 +5,11 @@
#define COMPLIANCEENGINE_COMMONCONTEXT_H

#include "ContextInterface.h"
#include "DirectoryEntry.h"
#include "Logging.h"
#include "Result.h"

#include <memory>
#include <sstream>
#include <string>

Expand All @@ -17,20 +19,23 @@ class CommonContext : public ContextInterface
{
public:
CommonContext(OsConfigLogHandle log)
: mLog(log)
: mLog(log),
mDirectoryIterator(new FtsDirectoryIterator())
{
}
~CommonContext() override;

Result<std::string> ExecuteCommand(const std::string& cmd) const override;
Result<std::string> GetFileContents(const std::string& filePath) const override;
Result<DirectoryEntries> GetDirectoryEntries(const std::string& directoryPath, bool recursive) const override;
OsConfigLogHandle GetLogHandle() const override
{
return mLog;
}

private:
OsConfigLogHandle mLog;
std::unique_ptr<DirectoryIteratorInterface> mDirectoryIterator;
};
} // namespace ComplianceEngine
#endif // COMPLIANCEENGINE_COMMONCONTEXT_H
4 changes: 4 additions & 0 deletions src/modules/complianceengine/src/lib/ContextInterface.h
Original file line number Diff line number Diff line change
Expand Up @@ -4,19 +4,23 @@
#ifndef COMPLIANCEENGINE_CONTEXTINTERFACE_H
#define COMPLIANCEENGINE_CONTEXTINTERFACE_H

#include "DirectoryEntry.h"
#include "Logging.h"
#include "Result.h"

#include <memory>
#include <string>

namespace ComplianceEngine
{

class ContextInterface
{
public:
virtual ~ContextInterface() = 0;
virtual Result<std::string> ExecuteCommand(const std::string& cmd) const = 0;
virtual Result<std::string> GetFileContents(const std::string& filePath) const = 0;
virtual Result<DirectoryEntries> GetDirectoryEntries(const std::string& directoryPath, bool recursive) const = 0;

virtual OsConfigLogHandle GetLogHandle() const = 0;
};
Expand Down
Loading
Loading