How to parameterize a password for a data-source using environment variables

How to parameterize a password for a data-source using environment variables

book

Article ID: KB0076145

calendar_today

Updated On:

Products Versions
TIBCO Streaming 7

Description

How do I parametrize a password for a data-source using environment variables?

Issue/Introduction

How to parameterize a password for a data-source using environment variables

Resolution

In the example: It is often not advisable to have a password (mypass) distributed around an entire series of machines because it makes password maintenance untenable.

Therefore, a reasonable solution would be to set an environment variable from a sourced file as part of the startup shell script (example: source /streambase/passwords.sh).

<data-source name="mysqldb" type="jdbc">

<uri value="jdbc:derby://localhost:1527/mysqldb;user=jeanne;password=darc"/>

<driver value="org.apache.derby.jdbc.ClientDriver"/> <param name="jdbc-retry-sqlstate" value="40001"/>

</data-source>


Environment variable expansion in the configuration file works for all environment variables.
Only certain environment variables (eg, STREAMBASE_HOME) are guaranteed to be set by the server.
But all other variables are passed through from the environment which started sbd.
Thus, a data source configuration would look like this:

<uri value="jdbc:derby://localhost:1527/mysqldb;user=$\{MYSQLDB_USER\};password=$\{MYSQLDB_PASS\}"/>


All-caps naming is a convention in environment variables, but not a requirement. Any un-set environment variables will cause a configuration file parsing error, so you need to make sure to set all variables you use to something, even if it is just empty-string.
 

Additional Information

Please see more on enciphering usernames and passwords