You are viewing a plain text version of this content. The canonical link for it is here.
Posted to issues@nifi.apache.org by GitBox <gi...@apache.org> on 2020/08/31 13:40:46 UTC

[GitHub] [nifi-minifi-cpp] fgerlits commented on a change in pull request #885: MINIFICPP-1344 - Correct rest endpoint for buckets on updateFromPayload

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



##########
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)

Review comment:
       I don't understand this comment; I think it can be deleted.  (Just line 79; lines 80-81 are useful.)

##########
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 a `find` here?  This will accept things like `.../buckets/JACKnJILLs/colors/RED/animals/ANT/flows/DANUBE` -- do we want to allow this?




----------------------------------------------------------------
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:
users@infra.apache.org