Tom,

Glad to hear this is working for you. In the future, if the nifi.properties 
file is encrypted, you can do the following:

// Example key used to encrypt properties
def loader = NiFiPropertiesLoader.withKey(“0123456789ABCDEFFEDCBA9876543210”)
NiFiProperties protected = loader.get()

assert niFiProperties instanceof StandardNiFiProperties
assert niFiProperties.getFlowConfigurationFile()

As you can see, the return value of .get() is a StandardNiFiProperties object, 
which extends NiFiProperties (thus providing many bespoke accessors), while 
transparently “unprotecting” (decrypting in this case) the secured values from 
the file. This way you do not have to explicitly access the underlying raw 
properties object that is populated by the load and re-initialize a new 
instance.

You will only need direct access to ProtectedNiFiProperties if you want to 
perform en/decryption operations yourself. The framework abstracts this so it 
is not necessary for standard access.


Andy LoPresto
alopre...@apache.org
alopresto.apa...@gmail.com
PGP Fingerprint: 70EC B3E5 98A6 5A3F D3C4  BACE 3C6E F65B 2F7D EF69

> On Sep 27, 2016, at 5:36 AM, Tom Gullo <tomgu...@gmail.com> wrote:
> 
> Code snippet in my ExecuteScript processor:
> 
> def loader = new NiFiPropertiesLoader()
> def pnp = new ProtectedNiFiProperties(loader.get().getRawProperties())
> log.debug "nifi version: " +  pnp.getProperty("nifi.version")
> 
> On Mon, Sep 26, 2016 at 9:39 AM, Tom Gullo <tomgu...@gmail.com 
> <mailto:tomgu...@gmail.com>> wrote:
> Andy,
> 
> That worked thank you. For any one else following I called the get method and 
> then used the standard and protected classes with the nifiproperries loader.
> 
> 
> On Sep 24, 2016 2:26 AM, "Andy LoPresto" <alopresto.apa...@gmail.com 
> <mailto:alopresto.apa...@gmail.com>> wrote:
> Tom,
> 
> If you are only concerned with the values in the currently-running NiFi 
> instance, you shouldn't need to directly interact with the file system. Just 
> use NiFIPropertiesLoader#get(). Use the static loaders if you want to get an 
> instance from a specific (non-default) file location.
> 
> Andy LoPresto
> alopre...@apache.org <mailto:alopre...@apache.org>
> alopresto.apa...@gmail.com <mailto:alopresto.apa...@gmail.com>
> PGP Fingerprint: 70EC B3E5 98A6 5A3F D3C4  BACE 3C6E F65B 2F7D EF69
> 
> On Sep 23, 2016, at 23:09, Tom Gullo <tomgu...@gmail.com 
> <mailto:tomgu...@gmail.com>> wrote:
> 
>> Andy, I wasn't sure if I would need to read the file in myself but it looks 
>> like I do.  Those unit tests help a lot. Thanks
>> 
>> -Tom
>> 
>> On Fri, Sep 23, 2016 at 10:47 PM, Andy LoPresto <alopre...@apache.org 
>> <mailto:alopre...@apache.org>> wrote:
>> Meant to add that there are Groovy unit tests for those classes so you may 
>> be able to copy the code directly from [1] and [2].
>> 
>> [1] 
>> https://github.com/apache/nifi/blob/master/nifi-nar-bundles/nifi-framework-bundle/nifi-framework/nifi-properties-loader/src/test/groovy/org/apache/nifi/properties/ProtectedNiFiPropertiesGroovyTest.groovy
>>  
>> <https://github.com/apache/nifi/blob/master/nifi-nar-bundles/nifi-framework-bundle/nifi-framework/nifi-properties-loader/src/test/groovy/org/apache/nifi/properties/ProtectedNiFiPropertiesGroovyTest.groovy>
>> [2] 
>> https://github.com/apache/nifi/blob/master/nifi-nar-bundles/nifi-framework-bundle/nifi-framework/nifi-properties-loader/src/test/groovy/org/apache/nifi/properties/NiFiPropertiesLoaderGroovyTest.groovy
>>  
>> <https://github.com/apache/nifi/blob/master/nifi-nar-bundles/nifi-framework-bundle/nifi-framework/nifi-properties-loader/src/test/groovy/org/apache/nifi/properties/NiFiPropertiesLoaderGroovyTest.groovy>
>> 
>> Andy LoPresto
>> alopre...@apache.org <mailto:alopre...@apache.org>
>> alopresto.apa...@gmail.com <mailto:alopresto.apa...@gmail.com>
>> PGP Fingerprint: 70EC B3E5 98A6 5A3F D3C4  BACE 3C6E F65B 2F7D EF69
>> 
>>> On Sep 23, 2016, at 7:45 PM, Andy LoPresto <alopre...@apache.org 
>>> <mailto:alopre...@apache.org>> wrote:
>>> 
>>> Tom,
>>> 
>>> You’ll want to take a look at ProtectedNiFiProperties [1] and 
>>> NiFiPropertiesLoader [2]. ProtectedNiFiProperties provides a decorator on a 
>>> normal NiFiProperties class which allows access to various values via key 
>>> access or through named getters. It “unprotects” the values and can return 
>>> a regular NiFiProperties instance with direct access to the plain values. 
>>> The NiFiPropertiesLoader can be instantiated with the decryption key 
>>> (currently the only supported protection scheme is AES/GCM encryption) and 
>>> can load multiple instances of the NiFiProperties directly from any 
>>> nifi.properties file simultaneously.
>>> 
>>> If you wanted to do this with a non-native file (i.e. a source that NiFi 
>>> does not have an internal mechanism for reading), you’d probably use a 
>>> GetFile -> ExtractText -> EncryptContent processor chain, or the 
>>> ExecuteScript processor (Groovy and other scripting languages have 
>>> extensive tooling provided to easily read from files, parse text, etc.).
>>> 
>>> [1] 
>>> https://github.com/apache/nifi/blob/master/nifi-nar-bundles/nifi-framework-bundle/nifi-framework/nifi-properties-loader/src/main/java/org/apache/nifi/properties/ProtectedNiFiProperties.java
>>>  
>>> <https://github.com/apache/nifi/blob/master/nifi-nar-bundles/nifi-framework-bundle/nifi-framework/nifi-properties-loader/src/main/java/org/apache/nifi/properties/ProtectedNiFiProperties.java>
>>> [2] 
>>> https://github.com/apache/nifi/blob/master/nifi-nar-bundles/nifi-framework-bundle/nifi-framework/nifi-properties-loader/src/main/java/org/apache/nifi/properties/NiFiPropertiesLoader.java
>>>  
>>> <https://github.com/apache/nifi/blob/master/nifi-nar-bundles/nifi-framework-bundle/nifi-framework/nifi-properties-loader/src/main/java/org/apache/nifi/properties/NiFiPropertiesLoader.java>
>>> 
>>> 
>>> Andy LoPresto
>>> alopre...@apache.org <mailto:alopre...@apache.org>
>>> alopresto.apa...@gmail.com <mailto:alopresto.apa...@gmail.com>
>>> PGP Fingerprint: 70EC B3E5 98A6 5A3F D3C4  BACE 3C6E F65B 2F7D EF69
>>> 
>>>> On Sep 23, 2016, at 3:28 PM, Tom Gullo <tomgu...@gmail.com 
>>>> <mailto:tomgu...@gmail.com>> wrote:
>>>> 
>>>> I'm using v1.0.  I want to access some values that are in the 
>>>> nifi.properties file.  And I would like to just use the nifi.properties 
>>>> file because I'll be encrypting some of these values and I want to use the 
>>>> built in encryption feature.
>>>> 
>>>> Thanks
>>>> 
>>>> On Fri, Sep 23, 2016 at 6:05 PM, Andrew Grande <apere...@gmail.com 
>>>> <mailto:apere...@gmail.com>> wrote:
>>>> Which NiFi version? With 1.0 there are some bits for variable registry 
>>>> available, basically one can reference values from external config files 
>>>> via regular EL expressions.
>>>> 
>>>> Andrew
>>>> 
>>>> 
>>>> On Fri, Sep 23, 2016, 6:00 PM Tom Gullo <tomgu...@gmail.com 
>>>> <mailto:tomgu...@gmail.com>> wrote:
>>>> I want to read in values from nifi.properties in a Groovy ExecuteScript 
>>>> processor.  What's the best way to do that?
>>>> 
>>>> Thanks
>>>> -Tom
>>>> 
>>> 
>> 
>> 
> 

Attachment: signature.asc
Description: Message signed with OpenPGP using GPGMail

Reply via email to