Overriding Security Certificate Values
The use of environment variables to assign new values to your app properties at runtime is a handy method that you can use to test your app with multiple data sets.
Follow these steps to set up the environment variables and use them during app runtime.
Step 1: Create environment variables for your app properties
You start by creating one environment variable for each app property that you want to externalize. To do so, run:
export <app-property-name>="<value>"
For example, if your app property name is
username
, run
export username="abc@xyz.com"
or
export USERNAME="abc@xyz.com"
A few things to note about this command:
- Since special characters (such as `! | < > &@ `) are shell command directives, if they appear in value, enclosing the value in double-quotes tells the system to treat such characters as literal values instead of shell command directives.
- The
app-property-name must match the app property exactly or it can use all uppercase letters. For example, the app property,
Message
, can either be entered asMessage
orMESSAGE
, but not asmessage
. - If you want to use a hierarchy for your app property, be sure to use underscores (_) between each level instead of the dot notation. For example, for an app property named
x.y.z
, the environment variable name should be eitherx_y_z
orX_Y_Z
.
Step 2: Set FLOGO_APP_PROPS_ENV=auto environment variable
To use the environment variables during app runtime, set the
FLOGO_APP_PROPS_ENV=auto
environment variable.
To do so, run:
FLOGO_APP_PROPS_ENV=auto ./<app-binary>
For example,
FLOGO_APP_PROPS_ENV=auto MESSAGE="This is variable 1." LOGLEVEL=DEBUG ./Timer-darwin-amd64
password
be sure to encrypt its value for security reasons. For more information, see
Encrypting Password Values.
Setting the
FLOGO_APP_PROPS_ENV=auto
directs your app to search the list of environment variables for each app property by matching the environment variable name to the app property name. When it finds a matching environment variable for a property, the app pulls the value for the property from the environment variable and runs the app with those values. Hence, it is mandatory that the app property name exactly matches the environment variable name for the property.
App properties that were not set as environment variables pick up the default values set for them in the app. A warning message similar to the following is displayed in the output:
<property_name> could not be resolved. Using default values.
Example: Overriding a Certificate Using an Environment Variable
You can override a server key and certificate using an app property. You would, typically, need to override a certificate if the existing certificate has expired or you want to use a custom certificate. You can directly override the certificate at runtime instead of reconfiguring the app. In such a case:
- Export the base64 encoded values of the content of the file in the terminal itself as follows:
export ServerCertificate=<base64encodedCertificateFileContent>
export ServerKey=<base64encodedKeyFileContent> - Set the
FLOGO_APP_PROPS_ENV=auto
environment variable as follows:FLOGO_APP_PROPS_ENV=auto ./<app-binary>