You are viewing a plain text version of this content. The canonical link for it is here.
Posted to commits@nifi.apache.org by sz...@apache.org on 2022/04/26 14:39:28 UTC

[nifi-minifi-cpp] 01/03: MINIFICPP-1802 Do not make EC2 HTTP calls when AWS extension is not used

This is an automated email from the ASF dual-hosted git repository.

szaszm pushed a commit to branch main
in repository https://gitbox.apache.org/repos/asf/nifi-minifi-cpp.git

commit 1a521323eb2e72d468bf113931570c19302be2f2
Author: Gabor Gyimesi <ga...@gmail.com>
AuthorDate: Tue Apr 26 16:03:20 2022 +0200

    MINIFICPP-1802 Do not make EC2 HTTP calls when AWS extension is not used
    
    Closes #1306
    Signed-off-by: Marton Szasz <sz...@apache.org>
---
 extensions/aws/processors/DeleteS3Object.cpp | 3 ++-
 extensions/aws/processors/FetchS3Object.cpp  | 3 ++-
 extensions/aws/processors/ListS3.cpp         | 4 +++-
 extensions/aws/processors/PutS3Object.cpp    | 3 ++-
 extensions/aws/processors/S3Processor.cpp    | 7 ++++---
 extensions/aws/processors/S3Processor.h      | 2 +-
 6 files changed, 14 insertions(+), 8 deletions(-)

diff --git a/extensions/aws/processors/DeleteS3Object.cpp b/extensions/aws/processors/DeleteS3Object.cpp
index 873346eef..05d4f1468 100644
--- a/extensions/aws/processors/DeleteS3Object.cpp
+++ b/extensions/aws/processors/DeleteS3Object.cpp
@@ -60,7 +60,8 @@ std::optional<aws::s3::DeleteObjectRequestParameters> DeleteS3Object::buildDelet
     const std::shared_ptr<core::ProcessContext> &context,
     const std::shared_ptr<core::FlowFile> &flow_file,
     const CommonProperties &common_properties) const {
-  aws::s3::DeleteObjectRequestParameters params(common_properties.credentials, client_config_);
+  gsl_Expects(client_config_);
+  aws::s3::DeleteObjectRequestParameters params(common_properties.credentials, *client_config_);
   context->getProperty(ObjectKey, params.object_key, flow_file);
   if (params.object_key.empty() && (!flow_file->getAttribute("filename", params.object_key) || params.object_key.empty())) {
     logger_->log_error("No Object Key is set and default object key 'filename' attribute could not be found!");
diff --git a/extensions/aws/processors/FetchS3Object.cpp b/extensions/aws/processors/FetchS3Object.cpp
index 7667d52e2..e6c7abe2e 100644
--- a/extensions/aws/processors/FetchS3Object.cpp
+++ b/extensions/aws/processors/FetchS3Object.cpp
@@ -74,7 +74,8 @@ std::optional<aws::s3::GetObjectRequestParameters> FetchS3Object::buildFetchS3Re
     const std::shared_ptr<core::ProcessContext> &context,
     const std::shared_ptr<core::FlowFile> &flow_file,
     const CommonProperties &common_properties) const {
-  minifi::aws::s3::GetObjectRequestParameters get_object_params(common_properties.credentials, client_config_);
+  gsl_Expects(client_config_);
+  minifi::aws::s3::GetObjectRequestParameters get_object_params(common_properties.credentials, *client_config_);
   get_object_params.bucket = common_properties.bucket;
   get_object_params.requester_pays = requester_pays_;
 
diff --git a/extensions/aws/processors/ListS3.cpp b/extensions/aws/processors/ListS3.cpp
index 61410ed1f..1ffd420c9 100644
--- a/extensions/aws/processors/ListS3.cpp
+++ b/extensions/aws/processors/ListS3.cpp
@@ -99,7 +99,9 @@ void ListS3::onSchedule(const std::shared_ptr<core::ProcessContext> &context, co
   if (!common_properties) {
     throw Exception(PROCESS_SCHEDULE_EXCEPTION, "Required property is not set or invalid");
   }
-  list_request_params_ = std::make_unique<aws::s3::ListRequestParameters>(common_properties->credentials, client_config_);
+
+  gsl_Expects(client_config_);
+  list_request_params_ = std::make_unique<aws::s3::ListRequestParameters>(common_properties->credentials, *client_config_);
   list_request_params_->setClientConfig(common_properties->proxy, common_properties->endpoint_override_url);
   list_request_params_->bucket = common_properties->bucket;
 
diff --git a/extensions/aws/processors/PutS3Object.cpp b/extensions/aws/processors/PutS3Object.cpp
index 937094737..4027b5a6a 100644
--- a/extensions/aws/processors/PutS3Object.cpp
+++ b/extensions/aws/processors/PutS3Object.cpp
@@ -210,7 +210,8 @@ std::optional<aws::s3::PutObjectRequestParameters> PutS3Object::buildPutS3Reques
     const std::shared_ptr<core::ProcessContext> &context,
     const std::shared_ptr<core::FlowFile> &flow_file,
     const CommonProperties &common_properties) const {
-  aws::s3::PutObjectRequestParameters params(common_properties.credentials, client_config_);
+  gsl_Expects(client_config_);
+  aws::s3::PutObjectRequestParameters params(common_properties.credentials, *client_config_);
   params.setClientConfig(common_properties.proxy, common_properties.endpoint_override_url);
   params.bucket = common_properties.bucket;
   params.user_metadata_map = user_metadata_map_;
diff --git a/extensions/aws/processors/S3Processor.cpp b/extensions/aws/processors/S3Processor.cpp
index ff44a8966..3b22ef2f7 100644
--- a/extensions/aws/processors/S3Processor.cpp
+++ b/extensions/aws/processors/S3Processor.cpp
@@ -193,19 +193,20 @@ std::optional<aws::s3::ProxyOptions> S3Processor::getProxy(const std::shared_ptr
 }
 
 void S3Processor::onSchedule(const std::shared_ptr<core::ProcessContext>& context, const std::shared_ptr<core::ProcessSessionFactory>& /*sessionFactory*/) {
+  client_config_ = Aws::Client::ClientConfiguration();
   std::string value;
   if (!context->getProperty(Bucket.getName(), value) || value.empty()) {
     throw Exception(PROCESS_SCHEDULE_EXCEPTION, "Bucket property missing or invalid");
   }
 
-  if (!context->getProperty(Region.getName(), client_config_.region) || client_config_.region.empty() || REGIONS.count(client_config_.region) == 0) {
+  if (!context->getProperty(Region.getName(), client_config_->region) || client_config_->region.empty() || REGIONS.count(client_config_->region) == 0) {
     throw Exception(PROCESS_SCHEDULE_EXCEPTION, "Region property missing or invalid");
   }
-  logger_->log_debug("S3Processor: Region [%s]", client_config_.region);
+  logger_->log_debug("S3Processor: Region [%s]", client_config_->region);
 
   if (auto communications_timeout = context->getProperty<core::TimePeriodValue>(CommunicationsTimeout)) {
     logger_->log_debug("S3Processor: Communications Timeout %" PRId64 " ms", communications_timeout->getMilliseconds().count());
-    client_config_.connectTimeoutMs = gsl::narrow<int64_t>(communications_timeout->getMilliseconds().count());
+    client_config_->connectTimeoutMs = gsl::narrow<int64_t>(communications_timeout->getMilliseconds().count());
   } else {
     throw Exception(PROCESS_SCHEDULE_EXCEPTION, "Communications Timeout missing or invalid");
   }
diff --git a/extensions/aws/processors/S3Processor.h b/extensions/aws/processors/S3Processor.h
index c22738f5b..2957d0d0c 100644
--- a/extensions/aws/processors/S3Processor.h
+++ b/extensions/aws/processors/S3Processor.h
@@ -115,7 +115,7 @@ class S3Processor : public core::Processor {
 
   std::shared_ptr<core::logging::Logger> logger_;
   aws::s3::S3Wrapper s3_wrapper_;
-  Aws::Client::ClientConfiguration client_config_;
+  std::optional<Aws::Client::ClientConfiguration> client_config_;
 };
 
 }  // namespace processors