0
votes

I am trying to use an environment variable which contains the file path, in NiFi Expression language. When I just give environment variable ${MY_VAR} for the file name, it is not getting resolved.

But if there is a space or some other character before the NiFi EL, it is being evaluated, but that will make an invalid file name. How to have this resolved without any extra characters.

So as per observation, when the whole content is just an EL it is not getting evaluated otherwise, it is.

PS: I am trying give the file name in Truststore Filename field in default StandardSSLContextService

1
As far as I can tell, the truststore and keystore properties on StandardSSLContextService do not support expression language. - Bryan Bende
@BryanBende As per the help it says so, but that doesn't justify the case the variables getting resolved when added along with some character. - Kannan Ramamoorthy

1 Answers

5
votes

You are encountering a bug in Apache NiFi. As Bryan pointed out, the truststore location field is not intended to support the Expression Language. The problem is stemming from an incorrect line at StandardSSLContextService:183 where the .evaluateExpressionAttributes() method is being invoked in the custom file validator, despite the comment a few lines above explaining the entire reason for this custom validator is because the default supports EL.

I ran a remote debugger and was able to evaluate ${TRUSTSTORE_LOCATION} using the environment variable TRUSTSTORE_LOCATION (which must be set before NiFi is started, because the VariableRegistry.ENVIRONMENT_SYSTEM_REGISTRY is only created by NotificationServiceManager which is invoked in RunNiFi:270). I was able to watch it correctly evaluate the environment variable to a file path, but then it was concatenated to the current running directory (.../nifi-assembly/target/nifi-1.4.0-SNAPSHOT-bin/nifi-1.4.0-SNAPSHOT/TRUSTSTORE_LOCATION) rather than being treated as an absolute/relative path because the property descriptor is unaware that this is the result of EL evaluation.

I have filed NIFI-4274 to document this bug. A workaround is to use a hard-coded truststore location in NiFi and use symlinks on your filesystem to point that at the actual file location if you do not know it at configure time.