| 727 | } |
| 728 | |
| 729 | utils::optional<std::string> C2Agent::fetchFlow(const std::string& uri) const { |
| 730 | if (!utils::StringUtils::startsWith(uri, "http") || protocol_.load() == nullptr) { |
| 731 | // try to open the file |
| 732 | utils::optional<std::string> content = filesystem_->read(uri); |
| 733 | if (content) { |
| 734 | return content; |
| 735 | } |
| 736 | } |
| 737 | // couldn't open as file and we have no protocol to request the file from |
| 738 | if (protocol_.load() == nullptr) { |
| 739 | return {}; |
| 740 | } |
| 741 | |
| 742 | std::string resolved_url = uri; |
| 743 | if (!utils::StringUtils::startsWith(uri, "http")) { |
| 744 | std::stringstream adjusted_url; |
| 745 | std::string base; |
| 746 | if (configuration_->get(minifi::Configure::nifi_c2_flow_base_url, base)) { |
| 747 | adjusted_url << base; |
| 748 | if (!utils::StringUtils::endsWith(base, "/")) { |
| 749 | adjusted_url << "/"; |
| 750 | } |
| 751 | adjusted_url << uri; |
| 752 | resolved_url = adjusted_url.str(); |
| 753 | } else if (configuration_->get("c2.rest.url", base)) { |
| 754 | std::string host, protocol; |
| 755 | int port = -1; |
| 756 | utils::parse_url(&base, &host, &port, &protocol); |
| 757 | adjusted_url << protocol << host; |
| 758 | if (port > 0) { |
| 759 | adjusted_url << ":" << port; |
| 760 | } |
| 761 | adjusted_url << "/c2/api/" << uri; |
| 762 | resolved_url = adjusted_url.str(); |
| 763 | } |
| 764 | } |
| 765 | |
| 766 | C2Payload payload(Operation::TRANSFER, true); |
| 767 | C2Payload &&response = protocol_.load()->consumePayload(resolved_url, payload, RECEIVE, false); |
| 768 | |
| 769 | auto raw_data = response.getRawData(); |
| 770 | return std::string(raw_data.data(), raw_data.size()); |
| 771 | } |
| 772 | |
| 773 | bool C2Agent::handleConfigurationUpdate(const C2ContentResponse &resp) { |
| 774 | auto url = resp.operation_arguments.find("location"); |
nothing calls this directly
no test coverage detected