martinzink commented on code in PR #1297: URL: https://github.com/apache/nifi-minifi-cpp/pull/1297#discussion_r874709728
########## extensions/gcp/processors/ListGCSBucket.cpp: ########## @@ -0,0 +1,80 @@ +/** + * 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 "ListGCSBucket.h" + +#include "core/Resource.h" +#include "core/FlowFile.h" +#include "core/ProcessContext.h" +#include "core/ProcessSession.h" +#include "utils/OptionalUtils.h" +#include "../GCPAttributes.h" + +namespace gcs = ::google::cloud::storage; + +namespace org::apache::nifi::minifi::extensions::gcp { +const core::Property ListGCSBucket::Bucket( + core::PropertyBuilder::createProperty("Bucket") + ->withDescription("Bucket of the object.") + ->isRequired(true) + ->supportsExpressionLanguage(true) + ->build()); + +const core::Property ListGCSBucket::UseVersions( + core::PropertyBuilder::createProperty("List all versions") + ->withDescription("Set this option to `true` to get all the previous versions separately.") + ->withDefaultValue<bool>(false) + ->build()); + +const core::Relationship ListGCSBucket::Success("success", "FlowFiles are routed to this relationship after a successful Google Cloud Storage operation."); + +void ListGCSBucket::initialize() { + setSupportedProperties({GCPCredentials, + Bucket, + NumberOfRetries, + EndpointOverrideURL, + UseVersions}); + setSupportedRelationships({Success}); +} + + +void ListGCSBucket::onSchedule(const std::shared_ptr<core::ProcessContext>& context, const std::shared_ptr<core::ProcessSessionFactory>& session_factory) { + GCSProcessor::onSchedule(context, session_factory); + gsl_Expects(context); + context->getProperty(Bucket.getName(), bucket_); +} + +void ListGCSBucket::onTrigger(const std::shared_ptr<core::ProcessContext>& context, const std::shared_ptr<core::ProcessSession>& session) { + gsl_Expects(context && session && gcp_credentials_); + + gcs::Client client = getClient(); + auto use_generations = context->getProperty<bool>(UseVersions); + gcs::Versions versions = (use_generations && *use_generations) ? gcs::Versions(true) : gcs::Versions(false); + auto objects_in_bucket = client.ListObjects(bucket_, versions); + for (auto& object_in_bucket : objects_in_bucket) { + if (object_in_bucket.ok()) { Review Comment: Good idea, I've added logging in https://github.com/apache/nifi-minifi-cpp/pull/1297/commits/06a5830f0fd949971083251aa638d944ecfbd9c9#diff-05c08d4812b33cf156d63951c94a76801eea61c820a64db990d6c1c4ee66a272R74-R75 -- 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. To unsubscribe, e-mail: [email protected] For queries about this service, please contact Infrastructure at: [email protected]
