12.5. Passing Configuration Values in Environment Variables #
To avoid storing sensitive information in the configuration file, you can include templates in the configuration file instead of some configuration values or their parts and pass environment variables to replace these templates when running the Postgres ProGate utilities.
Names of templates start with a dollar sign. During the substitution in templates, $var or ${var} is replaced with the value of the var environment variable if it is available or with an empty string otherwise. $$var is used to have the dollar sign included in the configuration value. It is replaced with $var. The ${var-DEFAULT} template gets replaced with the value of the var environment variable if it is available and with the value of DEFAULT otherwise.
Consider an example.
The following is a fragment of the procopy and prosync configuration file with templates used instead of configuration values or their parts:
source:
driver_name: oracle
database: CUSTOM_DATABASE_$$MYDB
host: ${ORACLE_HOST-localhost}
max_conn: 50
options: []
password: $ORACLE_PWD
port: ${NOT_EXISTS_CUSTOM_ENV-1521}
username: $ORACLE_USER
destination:
database: postgres
dsn: $BIHA_DSN
Let's create an environment file .env that sets the variables to replace the templates in the configuration file:
export ORACLE_HOST=10.5.55.230 export ORACLE_PWD=PROGATE export ORACLE_USER=SYSTEM export BIHA_DSN="postgresql://10.5.55.236,10.5.55.237:5432/postgres?user=postgres&password=progate&target_session_attrs=read-write"
Now execute the prosync run command with the above configuration file and the templates replaced with the variables from the environment file:
(source .env && ./prosync run -f config.yml)
In this example, prosync uses the configuration file with these values:
source:
driver_name: oracle
database: CUSTOM_DATABASE_$MYDB
host: 10.5.55.230
max_conn: 50
options: []
password: PROGATE
port: 1521
username: SYSTEM
destination:
database: postgres
dsn: "postgresql://10.5.55.236,10.5.55.237:5432/postgres?user=postgres&password=progate&target_session_attrs=read-write"
Alternatively, you can pass environment variables to utilities directly on the command line. For example:
ORACLE_PWD=PROGATE ./bin/prosync init -f test-any.yml