[GitHub] [nifi-minifi-cpp] arpadboda commented on a change in pull request #937: MINIFICPP-1402 - Encrypt flow configuration and change encryption key

2020-12-02 Thread GitBox


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



##
File path: libminifi/include/utils/CollectionUtils.h
##
@@ -0,0 +1,40 @@
+/**
+ * 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 
+#include 
+#include 
+
+namespace org {
+namespace apache {
+namespace nifi {
+namespace minifi {
+namespace utils {
+
+bool haveCommonItem(const std::set& a, const 
std::set& b) {

Review comment:
   I think the filename itself screams for generalisation. :)





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




[GitHub] [nifi-minifi-cpp] arpadboda commented on a change in pull request #937: MINIFICPP-1402 - Encrypt flow configuration and change encryption key

2020-12-02 Thread GitBox


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



##
File path: libminifi/include/utils/CollectionUtils.h
##
@@ -0,0 +1,40 @@
+/**
+ * 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 
+#include 
+#include 
+
+namespace org {
+namespace apache {
+namespace nifi {
+namespace minifi {
+namespace utils {
+
+bool haveCommonItem(const std::set& a, const 
std::set& b) {

Review comment:
   This is specialised for set and string with no reason. 
   
   In case this just requries two iterables with the same underlying type and 
you use find instead of count, this is going to work with vectors, lists, etc, 
while keeping the log(N) efficiency for sets. 
   
   Not to mention unordered sets as well. 





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




[GitHub] [nifi-minifi-cpp] arpadboda commented on a change in pull request #937: MINIFICPP-1402 - Encrypt flow configuration and change encryption key

2020-12-02 Thread GitBox


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



##
File path: libminifi/include/utils/CollectionUtils.h
##
@@ -0,0 +1,40 @@
+/**
+ * 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 
+#include 
+#include 
+
+namespace org {
+namespace apache {
+namespace nifi {
+namespace minifi {
+namespace utils {
+
+bool haveCommonItem(const std::set& a, const 
std::set& b) {

Review comment:
   This is specialised for set with no reason. 
   
   In case this just requries two iterables with the same underlying type and 
you use find instead of count, this is going to work with vectors, lists, etc, 
while keeping the log(N) efficiency for sets. 
   
   Not to mention unordered sets as well. 





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




[GitHub] [nifi-minifi-cpp] arpadboda commented on a change in pull request #937: MINIFICPP-1402 - Encrypt flow configuration and change encryption key

2020-12-02 Thread GitBox


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



##
File path: libminifi/include/utils/CollectionUtils.h
##
@@ -0,0 +1,40 @@
+/**
+ * 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 
+#include 
+#include 
+
+namespace org {
+namespace apache {
+namespace nifi {
+namespace minifi {
+namespace utils {
+
+bool haveCommonItem(const std::set& a, const 
std::set& b) {

Review comment:
   This is specialised for set with no reason. 
   
   In case this just requries two iterables with the same underlying type and 
you use find instead of count, this is going to work with vectors, lists, etc, 
while keeping the log(N) efficiency for sets. 





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




[GitHub] [nifi-minifi-cpp] arpadboda commented on a change in pull request #937: MINIFICPP-1402 - Encrypt flow configuration and change encryption key

2020-11-23 Thread GitBox


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



##
File path: encrypt-config/ArgParser.h
##
@@ -0,0 +1,72 @@
+/**
+ * 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 
+#include 
+#include 
+#include 
+#include "utils/OptionalUtils.h"
+
+namespace org {
+namespace apache {
+namespace nifi {
+namespace minifi {
+namespace encrypt_config {
+
+struct Argument {
+  std::vector names;

Review comment:
   I wonder if we can assume these to be unique and use set instad.
   That would help making other parts of the code simple (use count instead of 
iterator-based search for eg.)

##
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 
+#include 
+#include 
+#include 
+#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 Arguments::simple_arguments_{
+{std::vector{"--minifi-home", "-m"},
+ true,
+ "minifi home",
+ "Specifies the home directory used by the minifi agent"}
+};
+
+const std::vector Arguments::flag_arguments_{
+{std::vector{"--help", "-h"},
+ "Prints this help message"},
+{std::vector{"--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;
+  }
+  return ss.str();
+}
+
+void Arguments::set(const std::string& key, const std::string& value) {
+  if (get(key)) {
+std::cerr << "Key is specified more than once \"" << key << "\"" << 
std::endl;
+std::cerr << getHelp();
+std::exit(1);
+  }
+  simple_args_[key] = value;
+}
+
+void Arguments::set(const std::string& flag) {
+  if (isSet(flag)) {
+std::cerr << "Flag is specified more than once \"" << flag << "\"" << 
std::endl;
+std::cerr << getHelp();
+std::exit(1);
+  }
+  flag_args_.insert(flag);
+}
+
+utils::optional Arguments::get(const std::string &key) const {
+  utils::optional opt_arg = getSimpleArg(key);
+  if (!opt_arg) {
+return {};
+  }
+  for (const auto& name : opt_arg->names) {
+auto it = simple_args_.find(name);
+if (it != simple_args_.end()) {
+  return it->second;
+}
+  }
+  return {};
+}
+
+bool Arguments::isSet(const std::s