-
1. Re: Environment variable in view model transformation
rareddy Apr 5, 2018 9:15 AM (in response to rptmat57)There is closing ")" missing on the concat, but I do not understand the part you say it works? Did you try without the variable directly?
-
2. Re: Environment variable in view model transformation
rptmat57 Apr 5, 2018 1:28 PM (in response to rareddy)the missing ")" is due to my copy pasting. it is actually there in the transformation.
what I meant is that it does work if I use
DECLARE STRING VARIABLES.token = 'Token sqwerty12345';
but when I use "ENV('SPM_TOKEN')" it doesn't
-
3. Re: Environment variable in view model transformation
shawkins Apr 5, 2018 2:43 PM (in response to rptmat57)The ENV function looks for key value pairs in the java environment variables. The Teiid declare statement creates a variable that is local to that block and can be directly referenced as VARIABLES.name.
-
4. Re: Environment variable in view model transformation
rptmat57 Apr 5, 2018 2:55 PM (in response to shawkins)let me rephrase then:
How can I retrieve an environment variable I created (using 'export SPM_TOKEN=Token sqwerty12345') in my procedure and send it in my header?
Or what would you say the best way to do this is? I don't want to hardcode the token because it is subject to change, and also because I want to check in my project to a repository (and don't want plain text passwords/tokens)
-
5. Re: Environment variable in view model transformation
rareddy Apr 5, 2018 3:08 PM (in response to rptmat57)DECLARE STRING VARIABLES.token =ENV('SPM_TOKEN')
-
6. Re: Environment variable in view model transformation
rptmat57 Apr 5, 2018 3:13 PM (in response to rareddy)I did try that, but it didn't work. the header is not sent at all in the request
-
7. Re: Environment variable in view model transformation
shawkins Apr 5, 2018 3:27 PM (in response to rptmat57)It's difficult to say what is not working from what you are showing. You can use the logMsg procedures to debug the execution - SYSADMIN · Teiid Documentation
-
8. Re: Environment variable in view model transformation
rareddy Apr 5, 2018 3:29 PM (in response to rptmat57)Have you tried logging the variable to see if the ENV getting the value correctly? did you restart the server after the susbsystem change?
-
9. Re: Environment variable in view model transformation
rptmat57 Apr 6, 2018 8:58 AM (in response to rareddy)I am trying to log the variable, but getting some issues
- if I use this:
EXEC SYSADMIN.logMsg(level=> 'ERROR', context => 'org.something', msg => ENV('SPM_TOKEN'));
I get "Element SYSADMIN.logMsg.msg does not allow nulls."
- then I tried:
DECLARE STRING VARIABLES.token = ENV('SPM_TOKEN');
EXEC SYSADMIN.logMsg(level=> 'ERROR', context => 'org.something', msg => VARIABLES.token);
no errors, but no logging is happening
- If I use:
DECLARE STRING VARIABLES.token = 'Test';
EXEC SYSADMIN.logMsg(level=> 'ERROR', context => 'org.something', msg => VARIABLES.token);
then it all works fine and I see the message in the logs.
-
10. Re: Environment variable in view model transformation
rareddy Apr 6, 2018 9:33 AM (in response to rptmat57)I think problem looks like in the Teiid code. Instead of looking for ENV variables it is looking at System.getProperty which returns the JDK System properties teiid/FunctionMethods.java at master · teiid/teiid · GitHub
Please log a JIRA here - JBoss Issue Tracker
-
11. Re: Environment variable in view model transformation
shawkins Apr 6, 2018 9:54 AM (in response to rareddy)> I think problem looks like in the Teiid code
This has always been the behavior of the function, so it likely needs to remain at least in part. The confusion lies in documenting it as reading environment variables, it should just be documented as system variable or system property.
A likely resolution would be to update the docs, and search first for the system property, then look in the environment variables.
-
12. Re: Environment variable in view model transformation
rptmat57 Apr 6, 2018 10:08 AM (in response to shawkins)thanks for the info, I tried with a system property instead (using "org.jboss.boot.log.file") and it worked!
I'll likely tweak jboss to set my env variable as a system property, that way it'll still work after the fix.
As it stands the name is confusing since it is "ENV()" but reads system properties.
How about creating separate functions, SYS_PROP(), and ENV_VAR() that do what they are supposed to do, and deprecate ENV() but keep it for backward compatibility?
-
13. Re: Environment variable in view model transformation
rareddy Apr 6, 2018 10:48 AM (in response to shawkins)Typically the search order is reversed in other configuration implementations where first ENV then SYSTEM, but that is only way we can keep the backward compatibility. Maybe for next major revision, we can correct the search order?