fgerlits commented on a change in pull request #885:
URL: https://github.com/apache/nifi-minifi-cpp/pull/885#discussion_r480137667



##########
File path: libminifi/src/core/FlowConfiguration.cpp
##########
@@ -67,33 +67,24 @@ std::shared_ptr<core::Processor> 
FlowConfiguration::createProvenanceReportTask()
   return processor;
 }
 
-std::unique_ptr<core::ProcessGroup> FlowConfiguration::updateFromPayload(const 
std::string &source, const std::string &yamlConfigPayload) {
+std::unique_ptr<core::ProcessGroup> FlowConfiguration::updateFromPayload(const 
std::string& url, const std::string& yamlConfigPayload) {
   auto old_services = controller_services_;
   auto old_provider = service_provider_;
   controller_services_ = 
std::make_shared<core::controller::ControllerServiceMap>();
   service_provider_ = 
std::make_shared<core::controller::StandardControllerServiceProvider>(controller_services_,
 nullptr, configuration_);
   auto payload = getRootFromPayload(yamlConfigPayload);
-  if (!source.empty() && payload != nullptr) {
-    std::string host, protocol, path, query, url = source;
-    int port = -1;
-    utils::parse_url(&url, &host, &port, &protocol, &path, &query);
-
+  if (!url.empty() && payload != nullptr) {
     std::string flow_id, bucket_id;
-    auto path_split = utils::StringUtils::split(path, "/");
-    for (size_t i = 0; i < path_split.size(); i++) {
-      const std::string &str = path_split.at(i);
-      if (str == "flows") {
-        if (i + 1 < path_split.size()) {
-          flow_id = path_split.at(i + 1);
-          i++;
-        }
-      }
-
-      if (str == "bucket") {
-        if (i + 1 < path_split.size()) {
-          bucket_id = path_split.at(i + 1);
-          i++;
-        }
+    auto path_split = utils::StringUtils::split(url, "/");
+    // This function might not do what the original implementater expected 
from it (https://issues.apache.org/jira/browse/MINIFICPP-1344)
+    // Registry API docs: 
nifi.apache.org/docs/nifi-registry-docs/rest-api/index.html
+    // GET /buckets/{bucketId}/flows/{flowId}: Gets a flow
+    const auto bucket_token_found = std::find(path_split.cbegin(), 
path_split.cend(), "buckets");
+    if (bucket_token_found != path_split.cend() && 
std::next(bucket_token_found) != path_split.cend()) {
+      bucket_id = *std::next(bucket_token_found);
+      const auto flows_token_found = std::find(std::next(bucket_token_found, 
2), path_split.cend(), "flows");

Review comment:
       Do we need this `find` here?  This will accept things like 
`.../buckets/JACKnJILLs/colors/RED/animals/ANT/flows/DANUBE` -- do we want to 
allow this?
   
   I would do
   ```c++
         if (std::next(buckets_token_found) != path_split.end() &&
             *std::next(buckets_token_found) == "flows" &&
             std::next(buckets_token_found, 2) != path_split.end()) {
           flow_id = *std::next(buckets_token_found, 2);
         }
   ```




----------------------------------------------------------------
This is an automated message from the Apache Git Service.
To respond to the message, please log on to GitHub and use the
URL above to go to the specific comment.

For queries about this service, please contact Infrastructure at:
[email protected]


Reply via email to