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



##########
File path: extensions/aws/AWSCredentialsProvider.cpp
##########
@@ -0,0 +1,94 @@
+/**
+ * @file AWSCredentialsProvider.cpp
+ * AWSCredentialsProvider class implementation
+ *
+ * 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 "AWSCredentialsProvider.h"
+
+#include "aws/core/auth/AWSCredentialsProviderChain.h"
+#include "properties/Properties.h"
+
+namespace org {
+namespace apache {
+namespace nifi {
+namespace minifi {
+namespace aws {
+
+AWSCredentialsProvider::AWSCredentialsProvider(
+    bool use_default_credentials,
+    const std::string &access_key,
+    const std::string &secret_key,
+    const std::string &credentials_file)
+  : use_default_credentials_(use_default_credentials)
+  , access_key_(access_key)
+  , secret_key_(secret_key)
+  , credentials_file_(credentials_file) {
+}
+
+void AWSCredentialsProvider::setUseDefaultCredentials(bool 
use_default_credentials) {
+  use_default_credentials_ = use_default_credentials;
+}
+
+void AWSCredentialsProvider::setAccessKey(const std::string &access_key) {
+  access_key_ = access_key;
+}
+
+void AWSCredentialsProvider::setSecretKey(const std::string &secret_key) {
+  secret_key_ = secret_key;
+}
+
+void AWSCredentialsProvider::setCredentialsFile(const std::string 
&credentials_file) {
+  credentials_file_ = credentials_file;
+}
+
+minifi::utils::optional<Aws::Auth::AWSCredentials> 
AWSCredentialsProvider::getAWSCredentials() {
+  if (use_default_credentials_) {
+    logger_->log_debug("Trying to use default AWS credentials provider 
chain.");

Review comment:
       How often is this function called?  If not too frequently, maybe these 
logs could be on info level.

##########
File path: extensions/aws/processors/PutS3Object.cpp
##########
@@ -220,57 +227,29 @@ minifi::utils::optional<Aws::Auth::AWSCredentials> 
PutS3Object::getAWSCredential
   return minifi::utils::nullopt;
 }
 
-minifi::utils::optional<Aws::Auth::AWSCredentials> 
PutS3Object::getAWSCredentialsFromProperties(
-    const std::shared_ptr<core::ProcessContext> &context,
-    const std::shared_ptr<core::FlowFile> &flow_file) const {
-  std::string access_key;
-  context->getProperty(AccessKey, access_key, flow_file);
-  std::string secret_key;
-  context->getProperty(SecretKey, secret_key, flow_file);
-  if (!access_key.empty() && !secret_key.empty()) {
-    Aws::Auth::AWSCredentials creds(access_key, secret_key);
-    return minifi::utils::make_optional<Aws::Auth::AWSCredentials>(creds);
-  }
-  return minifi::utils::nullopt;
-}
-
-minifi::utils::optional<Aws::Auth::AWSCredentials> 
PutS3Object::getAWSCredentialsFromFile(const 
std::shared_ptr<core::ProcessContext> &context) const {
-  std::string credential_file;
-  if (context->getProperty(CredentialsFile.getName(), credential_file) && 
!credential_file.empty()) {
-    auto properties = std::make_shared<minifi::Properties>();
-    properties->loadConfigureFile(credential_file.c_str());
-    std::string access_key;
-    std::string secret_key;
-    if (properties->getString("accessKey", access_key) && !access_key.empty() 
&& properties->getString("secretKey", secret_key) && !secret_key.empty()) {
-      Aws::Auth::AWSCredentials creds(access_key, secret_key);
-      return minifi::utils::make_optional<Aws::Auth::AWSCredentials>(creds);
-    }
-  }
-  return minifi::utils::nullopt;
-}
-
 minifi::utils::optional<Aws::Auth::AWSCredentials> 
PutS3Object::getAWSCredentials(
     const std::shared_ptr<core::ProcessContext> &context,
-    const std::shared_ptr<core::FlowFile> &flow_file) const {
-  auto prop_cred = getAWSCredentialsFromProperties(context, flow_file);
-  if (prop_cred) {
-    logger_->log_info("AWS Credentials successfully set from properties");
-    return prop_cred.value();
-  }
-
-  auto file_cred = getAWSCredentialsFromFile(context);
-  if (file_cred) {
-    logger_->log_info("AWS Credentials successfully set from file");
-    return file_cred.value();
-  }
-
+    const std::shared_ptr<core::FlowFile> &flow_file) {

Review comment:
       why is this no longer const?




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