-
Notifications
You must be signed in to change notification settings - Fork 0
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Adds support for NanoTDF: #3 Pending upstream [java-sdk Nano PR](opentdf/java-sdk#46)
- Loading branch information
1 parent
56e22ed
commit dfa5f52
Showing
15 changed files
with
664 additions
and
169 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
76 changes: 76 additions & 0 deletions
76
nifi-tdf-processors/src/main/java/io/opentdf/nifi/AbstractToProcessor.java
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,76 @@ | ||
package io.opentdf.nifi; | ||
|
||
import io.opentdf.platform.sdk.Config; | ||
import org.apache.nifi.components.PropertyDescriptor; | ||
import org.apache.nifi.expression.ExpressionLanguageScope; | ||
import org.apache.nifi.flowfile.FlowFile; | ||
import org.apache.nifi.processor.ProcessContext; | ||
import org.apache.nifi.processor.util.StandardValidators; | ||
|
||
import java.util.Arrays; | ||
import java.util.Collections; | ||
import java.util.List; | ||
import java.util.Set; | ||
import java.util.stream.Collectors; | ||
|
||
/** | ||
* Common utilities for a processor converting content to one of the TDF formats | ||
*/ | ||
public abstract class AbstractToProcessor extends AbstractTDFProcessor{ | ||
static final String KAS_URL_ATTRIBUTE = "kas_url"; | ||
static final String TDF_ATTRIBUTE = "tdf_attribute"; | ||
|
||
public static final PropertyDescriptor KAS_URL = new org.apache.nifi.components.PropertyDescriptor.Builder() | ||
.name("KAS URL") | ||
.expressionLanguageSupported(ExpressionLanguageScope.VARIABLE_REGISTRY) | ||
.description("The KAS Url to use for encryption; this is a default if the kas_url attribute is not present in the flow file") | ||
.required(false) | ||
.addValidator(StandardValidators.NON_BLANK_VALIDATOR) | ||
.build(); | ||
|
||
@Override | ||
public List<PropertyDescriptor> getSupportedPropertyDescriptors() { | ||
return Collections.unmodifiableList(Arrays.asList(SSL_CONTEXT_SERVICE, OPENTDF_CONFIG_SERVICE, FLOWFILE_PULL_SIZE, KAS_URL)); | ||
} | ||
|
||
/**{ | ||
* Get the kas urls from a flowfile attribute or if none present fallback to processor configuration KAS URL; | ||
* format is a comma separated list | ||
* @param flowFile | ||
* @param processContext | ||
* @return | ||
* @throws Exception | ||
*/ | ||
List<String> getKasUrl(FlowFile flowFile, ProcessContext processContext) throws Exception{ | ||
String kasUrlAttribute = flowFile.getAttribute(KAS_URL_ATTRIBUTE); | ||
//check kas url | ||
if (!processContext.getProperty(KAS_URL).isSet() && kasUrlAttribute == null) { | ||
throw new Exception("no " + KAS_URL_ATTRIBUTE + " flowfile attribute and no default KAS URL configured"); | ||
} | ||
String kasUrlValues = kasUrlAttribute != null ? kasUrlAttribute : getPropertyValue(processContext.getProperty(KAS_URL)).getValue(); | ||
List<String> kasUrls = Arrays.stream(kasUrlValues.split(",")).filter(x->!x.isEmpty()).collect(Collectors.toList()); | ||
if (kasUrlValues.isEmpty()){ | ||
throw new Exception("no KAS Urls provided"); | ||
} | ||
return kasUrls; | ||
} | ||
|
||
List<Config.KASInfo> getKASInfoFromKASURLs(List<String> kasUrls){ | ||
return kasUrls.stream().map(x->{ var ki = new Config.KASInfo(); ki.URL=x; return ki;}).collect(Collectors.toList()); | ||
} | ||
|
||
/** | ||
* Get data attributes on a FlowFile from attribute value | ||
* @param flowFile | ||
* @return | ||
* @throws Exception | ||
*/ | ||
Set<String> getDataAttributes(FlowFile flowFile) throws Exception{ | ||
Set<String> dataAttributes = Arrays.stream((flowFile.getAttribute(TDF_ATTRIBUTE) == null ? "" : | ||
flowFile.getAttribute(TDF_ATTRIBUTE)).split(",")).filter(x -> !x.isEmpty()).collect(Collectors.toSet()); | ||
if (dataAttributes.isEmpty()) { | ||
throw new Exception("no data attributes provided via " + TDF_ATTRIBUTE + " flowfile attribute"); | ||
} | ||
return dataAttributes; | ||
} | ||
} |
40 changes: 40 additions & 0 deletions
40
nifi-tdf-processors/src/main/java/io/opentdf/nifi/ConvertFromNanoTDF.java
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,40 @@ | ||
package io.opentdf.nifi; | ||
|
||
import io.opentdf.platform.sdk.SDK; | ||
import org.apache.nifi.annotation.documentation.CapabilityDescription; | ||
import org.apache.nifi.annotation.documentation.Tags; | ||
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 java.io.IOException; | ||
import java.nio.ByteBuffer; | ||
import java.util.List; | ||
|
||
@CapabilityDescription("Decrypts NanoTDF flow file content") | ||
@Tags({"NanoTDF", "OpenTDF", "Decrypt", "Data Centric Security"}) | ||
public class ConvertFromNanoTDF extends AbstractTDFProcessor { | ||
|
||
@Override | ||
public void processFlowFiles(ProcessContext processContext, ProcessSession processSession, List<FlowFile> flowFiles) throws ProcessException { | ||
SDK sdk = getTDFSDK(processContext); | ||
for (FlowFile flowFile : flowFiles) { | ||
try { | ||
byte[] nanoTDFBytes = readEntireFlowFile(flowFile, processSession); | ||
FlowFile updatedFlowFile = processSession.write(flowFile, outputStream -> { | ||
try { | ||
getNanoTDF().readNanoTDF(ByteBuffer.wrap(nanoTDFBytes), outputStream, sdk.getServices().kas()); | ||
} catch (Exception e) { | ||
getLogger().error("error decrypting NanoTDF", e); | ||
throw new IOException(e); | ||
} | ||
}); | ||
processSession.transfer(updatedFlowFile, REL_SUCCESS); | ||
} catch (Exception e) { | ||
getLogger().error(flowFile.getId() + ": error decrypting flowfile", e); | ||
processSession.transfer(flowFile, REL_FAILURE); | ||
} | ||
} | ||
} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Oops, something went wrong.