-
Notifications
You must be signed in to change notification settings - Fork 44
Handle agent centralized configuration commands #223
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Merged
cborla
merged 18 commits into
master
from
enhancement/32-agent-centralized-configuration-class-mvp
Oct 18, 2024
Merged
Changes from 17 commits
Commits
Show all changes
18 commits
Select commit
Hold shift + click to select a range
dda6c02
feat: add boilerplate files for CentralizedConfiguration
jr0me c28f302
feat: add module wrapper interface methods to CentralizedConfiguration
jr0me 8c36877
feat: implement CentralizedConfiguration::Setup
jr0me 0b85dc5
fix: toml and Logger are public dependencies of ConfigurationParser
jr0me 079723b
feat: introduce ExecuteCommand in CentralizedConfiguration
jr0me c0fdbf2
feat: add basic handling of CentralizedConfiguration commands
jr0me a547707
feat: add SetGroupIdFunction to CentralizedConfiguration
jr0me b28ba08
refactor: CentralizedConfiguration tests for better readability and m…
jr0me c0fd320
feat: test failure when SetGroupIdFunction is not set
jr0me 964a82d
feat: catch json parsing errors
jr0me 7ff5e34
feat: add function setter to configure how to download group configur…
jr0me 1e903e4
refactor: use type alias to improve readability
jr0me 021499b
feat: use download group config files and udpate tests
jr0me c87707e
feat: GetGroupIdFunction and update tests
jr0me c4d0b6b
feat: add SetMessageQueue method to CentralizedConfiguration
jr0me e6d4b49
feat: add CentralizedConfiguration module to ModuleManager
jr0me 9e3bc20
feat: set CentralizedConfiguration functions to set and get groups an…
jr0me 32dc10f
feat: add documentation to the CentralizedConfiguration
jr0me File filter
Filter by extension
Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
There are no files selected for viewing
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,20 @@ | ||
cmake_minimum_required(VERSION 3.22) | ||
|
||
project(CentralizedConfiguration) | ||
|
||
include(../../cmake/CommonSettings.cmake) | ||
set_common_settings() | ||
|
||
include_directories(${CMAKE_SOURCE_DIR}/common/logger/include) | ||
|
||
add_library(CentralizedConfiguration src/centralized_configuration.cpp) | ||
target_include_directories(CentralizedConfiguration PUBLIC ${CMAKE_CURRENT_SOURCE_DIR}/include) | ||
target_link_libraries(CentralizedConfiguration PUBLIC ConfigurationParser ModuleManager MultiTypeQueue) | ||
|
||
include(../../cmake/ConfigureTarget.cmake) | ||
configure_target(CentralizedConfiguration) | ||
|
||
if(BUILD_TESTS) | ||
enable_testing() | ||
add_subdirectory(tests) | ||
endif() |
37 changes: 37 additions & 0 deletions
37
src/modules/centralized_configuration/include/centralized_configuration.hpp
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,37 @@ | ||
#pragma once | ||
|
||
#include <configuration_parser.hpp> | ||
#include <moduleWrapper.hpp> | ||
#include <multitype_queue.hpp> | ||
|
||
#include <filesystem> | ||
#include <functional> | ||
#include <string> | ||
#include <vector> | ||
|
||
namespace centralized_configuration | ||
{ | ||
class CentralizedConfiguration | ||
{ | ||
public: | ||
using SetGroupIdFunctionType = std::function<void(const std::vector<std::string>&)>; | ||
using GetGroupIdFunctionType = std::function<std::vector<std::string>()>; | ||
using DownloadGroupFilesFunctionType = std::function<bool(const std::string&, const std::string&)>; | ||
|
||
void Start() const; | ||
void Setup(const configuration::ConfigurationParser&) const; | ||
void Stop() const; | ||
Co_CommandExecutionResult ExecuteCommand(std::string command); | ||
std::string Name() const; | ||
void SetMessageQueue(const std::shared_ptr<IMultiTypeQueue>); | ||
|
||
void SetGroupIdFunction(SetGroupIdFunctionType setGroupIdFunction); | ||
void GetGroupIdFunction(GetGroupIdFunctionType getGroupIdFunction); | ||
void SetDownloadGroupFilesFunction(DownloadGroupFilesFunctionType downloadGroupFilesFunction); | ||
|
||
private: | ||
SetGroupIdFunctionType m_setGroupIdFunction; | ||
GetGroupIdFunctionType m_getGroupIdFunction; | ||
DownloadGroupFilesFunctionType m_downloadGroupFilesFunction; | ||
}; | ||
} // namespace centralized_configuration |
128 changes: 128 additions & 0 deletions
128
src/modules/centralized_configuration/src/centralized_configuration.cpp
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,128 @@ | ||
#include <centralized_configuration.hpp> | ||
|
||
#include <module_command/command_entry.hpp> | ||
|
||
#include <nlohmann/json.hpp> | ||
|
||
#include <filesystem> | ||
|
||
namespace centralized_configuration | ||
{ | ||
void CentralizedConfiguration::Start() const | ||
{ | ||
} | ||
|
||
void CentralizedConfiguration::Setup(const configuration::ConfigurationParser&) const | ||
{ | ||
} | ||
|
||
void CentralizedConfiguration::Stop() const | ||
{ | ||
} | ||
|
||
// NOLINTNEXTLINE(performance-unnecessary-value-param) | ||
Co_CommandExecutionResult CentralizedConfiguration::ExecuteCommand(const std::string command) | ||
{ | ||
try | ||
{ | ||
const auto commnandAsJson = nlohmann::json::parse(command); | ||
|
||
if (commnandAsJson["command"] == "set-group") | ||
{ | ||
if (m_setGroupIdFunction && m_downloadGroupFilesFunction) | ||
{ | ||
const auto groupIds = commnandAsJson["groups"].get<std::vector<std::string>>(); | ||
|
||
m_setGroupIdFunction(groupIds); | ||
|
||
for (const auto& groupId : groupIds) | ||
{ | ||
m_downloadGroupFilesFunction( | ||
groupId, | ||
std::filesystem::temp_directory_path().string() | ||
); | ||
} | ||
|
||
// TODO validate groupFiles, apply configuration | ||
|
||
co_return module_command::CommandExecutionResult{ | ||
module_command::Status::SUCCESS, | ||
"CentralizedConfiguration group set" | ||
}; | ||
} | ||
else | ||
{ | ||
co_return module_command::CommandExecutionResult{ | ||
module_command::Status::FAILURE, | ||
"CentralizedConfiguration group set failed, no function set" | ||
}; | ||
} | ||
} | ||
else if (commnandAsJson["command"] == "update-group") | ||
{ | ||
if (m_getGroupIdFunction && m_downloadGroupFilesFunction) | ||
{ | ||
const auto groupIds = m_getGroupIdFunction(); | ||
|
||
for (const auto& groupId : groupIds) | ||
{ | ||
m_downloadGroupFilesFunction( | ||
groupId, | ||
std::filesystem::temp_directory_path().string() | ||
); | ||
} | ||
|
||
// TODO validate groupFiles, apply configuration | ||
|
||
co_return module_command::CommandExecutionResult{ | ||
module_command::Status::SUCCESS, | ||
"CentralizedConfiguration group updated" | ||
}; | ||
} | ||
else | ||
{ | ||
co_return module_command::CommandExecutionResult{ | ||
module_command::Status::FAILURE, | ||
"CentralizedConfiguration group set failed, no function set" | ||
}; | ||
} | ||
} | ||
} | ||
catch (const nlohmann::json::exception&) | ||
{ | ||
co_return module_command::CommandExecutionResult{ | ||
module_command::Status::FAILURE, | ||
"CentralizedConfiguration error while parsing command" | ||
}; | ||
} | ||
|
||
co_return module_command::CommandExecutionResult{ | ||
module_command::Status::FAILURE, | ||
"CentralizedConfiguration command not recognized" | ||
}; | ||
} | ||
|
||
std::string CentralizedConfiguration::Name() const | ||
{ | ||
return "CentralizedConfiguration"; | ||
} | ||
|
||
void CentralizedConfiguration::SetMessageQueue(const std::shared_ptr<IMultiTypeQueue>) | ||
{ | ||
} | ||
|
||
void CentralizedConfiguration::SetGroupIdFunction(SetGroupIdFunctionType setGroupIdFunction) | ||
{ | ||
m_setGroupIdFunction = std::move(setGroupIdFunction); | ||
} | ||
|
||
void CentralizedConfiguration::GetGroupIdFunction(GetGroupIdFunctionType getGroupIdFunction) | ||
{ | ||
m_getGroupIdFunction = std::move(getGroupIdFunction); | ||
} | ||
|
||
void CentralizedConfiguration::SetDownloadGroupFilesFunction(DownloadGroupFilesFunctionType downloadGroupFilesFunction) | ||
{ | ||
m_downloadGroupFilesFunction = std::move(downloadGroupFilesFunction); | ||
} | ||
} // namespace centralized_configuration |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,7 @@ | ||
find_package(GTest CONFIG REQUIRED) | ||
|
||
add_executable(centralized_configuration_test centralized_configuration_tests.cpp) | ||
configure_target(centralized_configuration_test) | ||
target_include_directories(centralized_configuration_test PRIVATE ${CMAKE_CURRENT_SOURCE_DIR}/../include) | ||
target_link_libraries(centralized_configuration_test PRIVATE CentralizedConfiguration GTest::gtest GTest::gmock) | ||
add_test(NAME CentralizedConfiguration COMMAND centralized_configuration_test) |
Oops, something went wrong.
Oops, something went wrong.
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
Uh oh!
There was an error while loading. Please reload this page.