adamdebreceni commented on a change in pull request #975: URL: https://github.com/apache/nifi-minifi-cpp/pull/975#discussion_r561717467
########## File path: extensions/aws/processors/ListS3.cpp ########## @@ -0,0 +1,294 @@ +/** + * @file ListS3.cpp + * ListS3 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 "ListS3.h" + +#include <tuple> +#include <algorithm> +#include <set> +#include <utility> +#include <memory> + +#include "utils/StringUtils.h" + +namespace org { +namespace apache { +namespace nifi { +namespace minifi { +namespace aws { +namespace processors { + +const std::string ListS3::LATEST_LISTED_KEY_PREFIX = "listed_key."; +const std::string ListS3::LATEST_LISTED_KEY_TIMESTAMP = "listed_key.timestamp"; + +const core::Property ListS3::Delimiter( + core::PropertyBuilder::createProperty("Delimiter") + ->withDescription("The string used to delimit directories within the bucket. Please consult the AWS documentation for the correct use of this field.") + ->build()); +const core::Property ListS3::Prefix( + core::PropertyBuilder::createProperty("Prefix") + ->withDescription("The prefix used to filter the object list. In most cases, it should end with a forward slash ('/').") + ->build()); +const core::Property ListS3::UseVersions( + core::PropertyBuilder::createProperty("Use Versions") + ->isRequired(true) + ->withDefaultValue<bool>(false) + ->withDescription("Specifies whether to use S3 versions, if applicable. If false, only the latest version of each object will be returned.") + ->build()); +const core::Property ListS3::MinimumObjectAge( + core::PropertyBuilder::createProperty("Minimum Object Age") + ->isRequired(true) + ->withDefaultValue<core::TimePeriodValue>("0 sec") + ->withDescription("The minimum age that an S3 object must be in order to be considered; any object younger than this amount of time (according to last modification date) will be ignored.") + ->build()); +const core::Property ListS3::WriteObjectTags( + core::PropertyBuilder::createProperty("Write Object Tags") + ->isRequired(true) + ->withDefaultValue<bool>(false) + ->withDescription("If set to 'true', the tags associated with the S3 object will be written as FlowFile attributes.") + ->build()); +const core::Property ListS3::WriteUserMetadata( + core::PropertyBuilder::createProperty("Write User Metadata") + ->isRequired(true) + ->withDefaultValue<bool>(false) + ->withDescription("If set to 'true', the user defined metadata associated with the S3 object will be added to FlowFile attributes/records.") + ->build()); +const core::Property ListS3::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 listing the S3 bucket. This sets the 'x-amz-request-payer' header to 'requester'. " + "Note that this setting is only used if Write User Metadata is true.") + ->build()); + +const core::Relationship ListS3::Success("success", "FlowFiles are routed to success relationship"); + +void ListS3::initialize() { + // Add new supported properties + updateSupportedProperties({Delimiter, Prefix, UseVersions, MinimumObjectAge, WriteObjectTags, WriteUserMetadata, RequesterPays}); + // Set the supported relationships + setSupportedRelationships({Success}); +} + +void ListS3::onSchedule(const std::shared_ptr<core::ProcessContext> &context, const std::shared_ptr<core::ProcessSessionFactory> &sessionFactory) { + S3Processor::onSchedule(context, sessionFactory); + + state_manager_ = context->getStateManager(); + if (state_manager_ == nullptr) { + throw Exception(PROCESSOR_EXCEPTION, "Failed to get StateManager"); + } + + auto common_properties = getCommonELSupportedProperties(context, nullptr); Review comment: passing `nullptr` will call a possible expression script with `nullptr`, will that properly throw an exception? e.g. it seems like `Bucket` property supports expression language, what happens if the user accidentally supplies a script value for that property that tries to access the null flowFile? ---------------------------------------------------------------- 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