alopresto commented on a change in pull request #4077: NIFI-5346 Introduces new PGP controller service and PGP processors. URL: https://github.com/apache/nifi/pull/4077#discussion_r384859709
########## File path: nifi-nar-bundles/nifi-standard-bundle/nifi-standard-processors/src/main/java/org/apache/nifi/processors/standard/pgp/DecryptContentPGP.java ########## @@ -0,0 +1,81 @@ +/* + * 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. + */ +package org.apache.nifi.processors.standard.pgp; + +import org.apache.nifi.annotation.behavior.InputRequirement; +import org.apache.nifi.annotation.behavior.SystemResource; +import org.apache.nifi.annotation.behavior.SystemResourceConsideration; +import org.apache.nifi.annotation.documentation.CapabilityDescription; +import org.apache.nifi.annotation.documentation.Tags; +import org.apache.nifi.components.PropertyDescriptor; +import org.apache.nifi.flowfile.FlowFile; +import org.apache.nifi.processor.ProcessContext; +import org.apache.nifi.processor.ProcessSession; +import org.apache.nifi.processor.exception.ProcessException; +import org.apache.nifi.util.StopWatch; + +import java.util.ArrayList; +import java.util.List; +import java.util.concurrent.TimeUnit; + +/** + * The DecryptContentPGP processor attempts to decrypt flow file contents when triggered. The processor uses a + * {@link PGPControllerService} to provide decryption operations. + * + * The PGP libraries do all of the lifting for decrypt operations, including content detection. This is is why there + * is no need to select an algorithm or encoding. + * + */ +@InputRequirement(InputRequirement.Requirement.INPUT_REQUIRED) +@Tags({"decryption", "OpenPGP", "PGP", "GPG"}) +@CapabilityDescription("Decrypts a FlowFile using a PGP key.") +@SystemResourceConsideration(resource = SystemResource.CPU) + +public class DecryptContentPGP extends AbstractProcessorPGP { + public static final PropertyDescriptor PGP_KEY_SERVICE = + AbstractProcessorPGP.buildControllerServiceProperty("PGP Key Material Controller Service that provides the private key or passphrase for decryption."); + + @Override + public void onTrigger(final ProcessContext context, final ProcessSession session) { + final FlowFile flowFile = session.get(); + if (flowFile == null) { + return; + } + + final PGPService service = context.getProperty(PGP_KEY_SERVICE).asControllerService(PGPService.class); + final StopWatch stopWatch = new StopWatch(true); + + try { + final FlowFile finalFlow = session.write(flowFile, (in, out) -> { + service.decrypt(in, out, service.optionsForDecrypt()); + }); + getLogger().debug("Called to decrypt flow {}", new Object[]{flowFile}); Review comment: Given that we have the timing information available from the stopwatch, I suggest putting it in the debug log as well. ---------------------------------------------------------------- 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 With regards, Apache Git Services