diff options
Diffstat (limited to 'src/components/policy/policy_regular/src/policy_manager_impl.cc')
-rw-r--r-- | src/components/policy/policy_regular/src/policy_manager_impl.cc | 46 |
1 files changed, 46 insertions, 0 deletions
diff --git a/src/components/policy/policy_regular/src/policy_manager_impl.cc b/src/components/policy/policy_regular/src/policy_manager_impl.cc index f4b6f0ae03..8c70437bfc 100644 --- a/src/components/policy/policy_regular/src/policy_manager_impl.cc +++ b/src/components/policy/policy_regular/src/policy_manager_impl.cc @@ -143,6 +143,51 @@ void PolicyManagerImpl::CheckTriggers() { } } +/** + * @brief FilterInvalidFunctions filter functions that are not present in schema + * @param rpcs list of functions to filter + */ +void FilterInvalidFunctions(policy_table::Rpc& rpcs) { + policy_table::Rpc valid_rpcs; + for (const auto& rpc : rpcs) { + const std::string& rpc_name = rpc.first; + policy_table::FunctionID function_id; + if (policy_table::EnumFromJsonString(rpc_name, &function_id)) { + valid_rpcs.insert(rpc); + } + } + rpcs.swap(valid_rpcs); +} + +/** + * @brief FilterInvalidParameters filter parameters that not present in schema + * @param rpc_parameters parameters to filter + */ +void FilterInvalidParameters(policy_table::RpcParameters& rpc_parameters) { + policy_table::Parameters valid_params; + for (auto& param : *(rpc_parameters.parameters)) { + if (param.is_valid()) { + valid_params.push_back(param); + } + } + rpc_parameters.parameters->swap(valid_params); +} + +/** + * @brief FilterPolicyTable filter values that not present in schema + * @param pt policy table to filter + */ +void FilterPolicyTable(policy_table::PolicyTable& pt) { + for (auto& group : pt.functional_groupings) { + policy_table::Rpc& rpcs = group.second.rpcs; + FilterInvalidFunctions(rpcs); + + for (auto& func : rpcs) { + FilterInvalidParameters(func.second); + } + } +} + bool PolicyManagerImpl::LoadPT(const std::string& file, const BinaryMessage& pt_content) { LOG4CXX_INFO(logger_, "LoadPT of size " << pt_content.size()); @@ -168,6 +213,7 @@ bool PolicyManagerImpl::LoadPT(const std::string& file, file_system::DeleteFile(file); + FilterPolicyTable(pt_update->policy_table); if (!IsPTValid(pt_update, policy_table::PT_UPDATE)) { wrong_ptu_update_received_ = true; update_status_manager_.OnWrongUpdateReceived(); |