szaszm commented on a change in pull request #937:
URL: https://github.com/apache/nifi-minifi-cpp/pull/937#discussion_r528782733



##########
File path: encrypt-config/CommandException.h
##########
@@ -0,0 +1,44 @@
+/**
+ * Licensed to the Apache Software Foundation (ASF) under one or more
+ * contributor license agreements.  See the NOTICE file distributed with
+ * this work for additional information regarding copyright ownership.
+ * The ASF licenses this file to You under the Apache License, Version 2.0
+ * (the "License"); you may not use this file except in compliance with
+ * the License.  You may obtain a copy of the License at
+ *
+ *     http://www.apache.org/licenses/LICENSE-2.0
+ *
+ * Unless required by applicable law or agreed to in writing, software
+ * distributed under the License is distributed on an "AS IS" BASIS,
+ * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
+ * See the License for the specific language governing permissions and
+ * limitations under the License.
+ */
+#pragma once
+
+#include <exception>
+#include <string>
+
+namespace org {
+namespace apache {
+namespace nifi {
+namespace minifi {
+namespace encrypt_config {
+
+struct CommandException : std::exception {
+  CommandException(const std::string& err) : error_(err) {}
+  CommandException(const char* err) : error_(err) {}

Review comment:
       These should be `explicit`.
   https://isocpp.github.io/CppCoreGuidelines/CppCoreGuidelines#Rc-explicit

##########
File path: encrypt-config/ArgParser.cpp
##########
@@ -0,0 +1,187 @@
+/**
+ * Licensed to the Apache Software Foundation (ASF) under one or more
+ * contributor license agreements.  See the NOTICE file distributed with
+ * this work for additional information regarding copyright ownership.
+ * The ASF licenses this file to You under the Apache License, Version 2.0
+ * (the "License"); you may not use this file except in compliance with
+ * the License.  You may obtain a copy of the License at
+ *
+ *     http://www.apache.org/licenses/LICENSE-2.0
+ *
+ * Unless required by applicable law or agreed to in writing, software
+ * distributed under the License is distributed on an "AS IS" BASIS,
+ * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
+ * See the License for the specific language governing permissions and
+ * limitations under the License.
+ */
+
+#include <string>
+#include <set>
+#include <iostream>
+#include <algorithm>
+#include "ArgParser.h"
+#include "utils/OptionalUtils.h"
+#include "utils/StringUtils.h"
+
+namespace org {
+namespace apache {
+namespace nifi {
+namespace minifi {
+namespace encrypt_config {
+
+const std::vector<Argument> Arguments::simple_arguments_{
+    {std::vector<std::string>{"--minifi-home", "-m"},
+     true,
+     "minifi home",
+     "Specifies the home directory used by the minifi agent"}
+};
+
+const std::vector<FlagArgument> Arguments::flag_arguments_{
+    {std::vector<std::string>{"--help", "-h"},
+     "Prints this help message"},
+    {std::vector<std::string>{"--encrypt-flow-config"},
+     "If set, the flow configuration file (as specified in minifi.properties) 
is also encrypted."}
+};
+
+std::string Arguments::getHelp() {
+  std::stringstream ss;
+  ss << "Usage: " << "encrypt-config";
+  for (const auto& simple_arg : simple_arguments_) {
+    ss << " ";
+    if (!simple_arg.required) {
+      ss << "[";
+    }
+    ss << utils::StringUtils::join("|", simple_arg.names)
+        << " <" << simple_arg.value_name << ">";
+    if (!simple_arg.required) {
+      ss << "]";
+    }
+  }
+  for (const auto& flag : flag_arguments_) {
+    ss << " [" << utils::StringUtils::join("|", flag.names) << "]";
+  }
+  ss << std::endl;
+  for (const auto& simple_arg : simple_arguments_) {
+    ss << "\t";
+    ss << utils::StringUtils::join("|", simple_arg.names) << " : ";
+    if (simple_arg.required) {
+      ss << "(required)";
+    } else {
+      ss << "(optional)";
+    }
+    ss << " " << simple_arg.description;
+    ss << std::endl;
+  }
+  for (const auto& flag : flag_arguments_) {
+    ss << "\t" << utils::StringUtils::join("|", flag.names) << " : "
+        << flag.description << std::endl;

Review comment:
       https://isocpp.github.io/CppCoreGuidelines/CppCoreGuidelines#Rio-endl

##########
File path: libminifi/include/c2/C2Payload.h
##########
@@ -164,10 +161,9 @@ class C2Payload : public state::Update {
   bool isContainer() const noexcept { return is_container_; }
   void setContainer(bool is_container) noexcept { is_container_ = 
is_container; }
 
-  /**
-   * Get nested payloads.
-   */
-  const std::vector<C2Payload> &getNestedPayloads() const noexcept { return 
payloads_; }
+  const std::vector<C2Payload> &getNestedPayloads() const & noexcept { return 
payloads_; }

Review comment:
       lvalue ref qualification is unnecessary
   
   http://eel.is/c++draft/over.match.funcs#general-4
   

##########
File path: encrypt-config/CommandException.h
##########
@@ -0,0 +1,44 @@
+/**
+ * Licensed to the Apache Software Foundation (ASF) under one or more
+ * contributor license agreements.  See the NOTICE file distributed with
+ * this work for additional information regarding copyright ownership.
+ * The ASF licenses this file to You under the Apache License, Version 2.0
+ * (the "License"); you may not use this file except in compliance with
+ * the License.  You may obtain a copy of the License at
+ *
+ *     http://www.apache.org/licenses/LICENSE-2.0
+ *
+ * Unless required by applicable law or agreed to in writing, software
+ * distributed under the License is distributed on an "AS IS" BASIS,
+ * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
+ * See the License for the specific language governing permissions and
+ * limitations under the License.
+ */
+#pragma once
+
+#include <exception>
+#include <string>
+
+namespace org {
+namespace apache {
+namespace nifi {
+namespace minifi {
+namespace encrypt_config {
+
+struct CommandException : std::exception {
+  CommandException(const std::string& err) : error_(err) {}
+  CommandException(const char* err) : error_(err) {}
+
+  const char* what() const noexcept override {
+    return error_.c_str();
+  }
+
+ private:
+  std::string error_;
+};

Review comment:
       
https://wiki.sei.cmu.edu/confluence/display/cplusplus/ERR60-CPP.+Exception+objects+must+be+nothrow+copy+constructible
   
   I recommend implementing in terms of one of the more specific standard 
exception types that store a string. `minifi::Exception` is implemented in 
terms of `std::runtime_error`.

##########
File path: libminifi/include/utils/file/FileSystem.h
##########
@@ -0,0 +1,57 @@
+/**
+ * Licensed to the Apache Software Foundation (ASF) under one or more
+ * contributor license agreements.  See the NOTICE file distributed with
+ * this work for additional information regarding copyright ownership.
+ * The ASF licenses this file to You under the Apache License, Version 2.0
+ * (the "License"); you may not use this file except in compliance with
+ * the License.  You may obtain a copy of the License at
+ *
+ *     http://www.apache.org/licenses/LICENSE-2.0
+ *
+ * Unless required by applicable law or agreed to in writing, software
+ * distributed under the License is distributed on an "AS IS" BASIS,
+ * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
+ * See the License for the specific language governing permissions and
+ * limitations under the License.
+ */
+
+#pragma once
+
+#include <string>
+#include <memory>
+#include "utils/OptionalUtils.h"
+#include "utils/EncryptionProvider.h"
+#include "core/logging/LoggerConfiguration.h"
+
+namespace org {
+namespace apache {
+namespace nifi {
+namespace minifi {
+namespace utils {
+namespace file {
+
+class FileSystem {
+ public:
+  explicit FileSystem(bool should_encrypt = false, 
utils::optional<utils::crypto::EncryptionProvider> encryptor = {});
+
+  FileSystem(const FileSystem&) = delete;
+  FileSystem(FileSystem&&) = delete;
+  FileSystem& operator=(const FileSystem&) = delete;
+  FileSystem& operator=(FileSystem&&) = delete;
+
+  utils::optional<std::string> read(const std::string& file_name);
+
+  bool write(const std::string& file_name, const std::string& file_content);
+
+ private:
+  bool should_encrypt_on_write_;
+  utils::optional<utils::crypto::EncryptionProvider> encryptor_;
+  std::shared_ptr<logging::Logger> 
logger_{logging::LoggerFactory<FileSystem>::getLogger()};
+};

Review comment:
       The `FileSystem` name and the utils::file namespace is most likely too 
general here, because a real filesystem can not be modeled by a boolean and 
optional EncryptionProvider structure. 

##########
File path: libminifi/include/utils/StringViewUtils.h
##########
@@ -0,0 +1,68 @@
+/**
+ * Licensed to the Apache Software Foundation (ASF) under one or more
+ * contributor license agreements.  See the NOTICE file distributed with
+ * this work for additional information regarding copyright ownership.
+ * The ASF licenses this file to You under the Apache License, Version 2.0
+ * (the "License"); you may not use this file except in compliance with
+ * the License.  You may obtain a copy of the License at
+ *
+ *     http://www.apache.org/licenses/LICENSE-2.0
+ *
+ * Unless required by applicable law or agreed to in writing, software
+ * distributed under the License is distributed on an "AS IS" BASIS,
+ * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
+ * See the License for the specific language governing permissions and
+ * limitations under the License.
+ */
+
+#pragma once
+
+#include <cctype>
+#include <algorithm>
+#include "StringView.h"
+#include "utils/OptionalUtils.h"
+
+namespace org {
+namespace apache {
+namespace nifi {
+namespace minifi {
+namespace utils {
+
+struct StringViewUtils {
+  static inline bool equalsIgnoreCase(StringView left, StringView right) {

Review comment:
       String views are essentially strings so I would rather move these utils 
to StringUtils.h. 

##########
File path: encrypt-config/EncryptConfig.h
##########
@@ -18,7 +18,8 @@
 
 #include <string>
 
-#include "utils/EncryptionUtils.h"
+#include "utils/OptionalUtils.h"

Review comment:
       Redundant include, optional is not referenced in this file.

##########
File path: libminifi/include/utils/StringView.h
##########
@@ -0,0 +1,151 @@
+/**
+ * Licensed to the Apache Software Foundation (ASF) under one or more
+ * contributor license agreements.  See the NOTICE file distributed with
+ * this work for additional information regarding copyright ownership.
+ * The ASF licenses this file to You under the Apache License, Version 2.0
+ * (the "License"); you may not use this file except in compliance with
+ * the License.  You may obtain a copy of the License at
+ *
+ *     http://www.apache.org/licenses/LICENSE-2.0
+ *
+ * Unless required by applicable law or agreed to in writing, software
+ * distributed under the License is distributed on an "AS IS" BASIS,
+ * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
+ * See the License for the specific language governing permissions and
+ * limitations under the License.
+ */
+
+#pragma once
+
+#include <string>
+#include <iterator>
+#include <algorithm>
+
+namespace org {
+namespace apache {
+namespace nifi {
+namespace minifi {
+namespace utils {
+
+class StringView {

Review comment:
       I would opt for `string_view` and a using declaration for 
`std::string_view` instead of the implementation when it's available. That 
would also require at least partial compatibility with `std::string_view`.




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


Reply via email to