arpadboda commented on a change in pull request #970: URL: https://github.com/apache/nifi-minifi-cpp/pull/970#discussion_r552056509
########## File path: extensions/aws/processors/FetchS3Object.cpp ########## @@ -0,0 +1,122 @@ +/** + * @file FetchS3Object.cpp + * FetchS3Object 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 "FetchS3Object.h" + +#include <set> +#include <memory> + +namespace org { +namespace apache { +namespace nifi { +namespace minifi { +namespace aws { +namespace processors { + +const core::Property FetchS3Object::Version( + core::PropertyBuilder::createProperty("Version") + ->withDescription("The Version of the Object to download") + ->supportsExpressionLanguage(true) + ->build()); +const core::Property FetchS3Object::RequesterPays( + core::PropertyBuilder::createProperty("Requester Pays") + ->isRequired(true) + ->withDefaultValue<bool>(false) + ->withDescription("If true, indicates that the requester consents to pay any charges associated with retrieving " + "objects from the S3 bucket. This sets the 'x-amz-request-payer' header to 'requester'.") + ->build()); + +const core::Relationship FetchS3Object::Success("success", "FlowFiles are routed to success relationship"); +const core::Relationship FetchS3Object::Failure("failure", "FlowFiles are routed to failure relationship"); + +void FetchS3Object::initialize() { + // Add new supported properties + updateSupportedProperties({Version, RequesterPays}); + // Set the supported relationships + setSupportedRelationships({Failure, Success}); +} + +void FetchS3Object::onSchedule(const std::shared_ptr<core::ProcessContext> &context, const std::shared_ptr<core::ProcessSessionFactory> &sessionFactory) { + S3Processor::onSchedule(context, sessionFactory); + + context->getProperty(RequesterPays.getName(), get_object_params_.requester_pays); + logger_->log_debug("FetchS3Object: RequesterPays [%s]", get_object_params_.requester_pays ? "true" : "false"); +} + +bool FetchS3Object::getExpressionLanguageSupportedProperties( + const std::shared_ptr<core::ProcessContext> &context, + const std::shared_ptr<core::FlowFile> &flow_file) { + if (!S3Processor::getExpressionLanguageSupportedProperties(context, flow_file)) { + return false; + } + get_object_params_.bucket = std::move(bucket_); + get_object_params_.object_key = std::move(object_key_); + + context->getProperty(Version, get_object_params_.version, flow_file); + logger_->log_debug("FetchS3Object: Version [%s]", get_object_params_.version); + return true; +} + +void FetchS3Object::onTrigger(const std::shared_ptr<core::ProcessContext> &context, const std::shared_ptr<core::ProcessSession> &session) { + logger_->log_debug("FetchS3Object onTrigger"); + std::shared_ptr<core::FlowFile> flow_file = session->get(); + if (!flow_file) { + context->yield(); + return; + } + + if (!getExpressionLanguageSupportedProperties(context, flow_file)) { + session->transfer(flow_file, Failure); + return; + } + + WriteCallback callback(flow_file->getSize(), get_object_params_, s3_wrapper_.get()); + session->write(flow_file, &callback); Review comment: Okay, thanks. ########## File path: extensions/aws/s3/S3WrapperBase.cpp ########## @@ -32,6 +33,17 @@ namespace minifi { namespace aws { namespace s3 { +void GetObjectResult::setFilePaths(const std::string& key) { + const auto last_slash = key.find_last_of('/'); + absolute_path = key; + if (last_slash != std::string::npos) { + path = key.substr(0, last_slash); + filename = key.substr(last_slash + 1); + } else { + filename = key; Review comment: I think some of our such util functions already have a "force posix" bool argument to address this, I think we can apply that for this specific function and use it here. ---------------------------------------------------------------- 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: [email protected]
