| 771 | } |
| 772 | |
| 773 | bool C2Agent::handleConfigurationUpdate(const C2ContentResponse &resp) { |
| 774 | auto url = resp.operation_arguments.find("location"); |
| 775 | |
| 776 | std::string file_uri; |
| 777 | std::string configuration_str; |
| 778 | |
| 779 | if (url != resp.operation_arguments.end()) { |
| 780 | file_uri = url->second.to_string(); |
| 781 | utils::optional<std::string> optional_configuration_str = fetchFlow(file_uri); |
| 782 | if (!optional_configuration_str) { |
| 783 | logger_->log_debug("Couldn't load new flow configuration from: \"%s\"", file_uri); |
| 784 | C2Payload response(Operation::ACKNOWLEDGE, state::UpdateState::SET_ERROR, resp.ident, true); |
| 785 | response.setRawData("Error while applying flow. Couldn't load flow configuration."); |
| 786 | enqueue_c2_response(std::move(response)); |
| 787 | return false; |
| 788 | } |
| 789 | configuration_str = optional_configuration_str.value(); |
| 790 | } else { |
| 791 | logger_->log_debug("Did not have location within %s", resp.ident); |
| 792 | auto update_text = resp.operation_arguments.find("configuration_data"); |
| 793 | if (update_text == resp.operation_arguments.end()) { |
| 794 | logger_->log_debug("Neither the config file location nor the data is provided"); |
| 795 | C2Payload response(Operation::ACKNOWLEDGE, state::UpdateState::SET_ERROR, resp.ident, true); |
| 796 | response.setRawData("Error while applying flow. Neither the config file location nor the data is provided."); |
| 797 | enqueue_c2_response(std::move(response)); |
| 798 | return false; |
| 799 | } |
| 800 | configuration_str = update_text->second.to_string(); |
| 801 | } |
| 802 | |
| 803 | bool should_persist = [&] { |
| 804 | auto persist = resp.operation_arguments.find("persist"); |
| 805 | if (persist == resp.operation_arguments.end()) { |
| 806 | return false; |
| 807 | } |
| 808 | return utils::StringUtils::equalsIgnoreCase(persist->second.to_string(), "true"); |
| 809 | }(); |
| 810 | |
| 811 | int16_t err = {update_sink_->applyUpdate(file_uri, configuration_str, should_persist)}; |
| 812 | if (err != 0) { |
| 813 | logger_->log_debug("Flow configuration update failed with error code %" PRIi16, err); |
| 814 | C2Payload response(Operation::ACKNOWLEDGE, state::UpdateState::SET_ERROR, resp.ident, true); |
| 815 | response.setRawData("Error while applying flow. Likely missing processors"); |
| 816 | enqueue_c2_response(std::move(response)); |
| 817 | return false; |
| 818 | } |
| 819 | |
| 820 | C2Payload response(Operation::ACKNOWLEDGE, state::UpdateState::FULLY_APPLIED, resp.ident, true); |
| 821 | enqueue_c2_response(std::move(response)); |
| 822 | |
| 823 | if (should_persist) { |
| 824 | // update the flow id |
| 825 | configuration_->persistProperties(); |
| 826 | } |
| 827 | |
| 828 | return true; |
| 829 | } |
| 830 |
nothing calls this directly
no test coverage detected