ballerina-spec
ballerina-spec copied to clipboard
Support environment variable expansion in Bal tool-managed configuration files such as `Ballerina.toml`, `Persist.toml`
Ballerina persistence CLI design introduces a new configuration file called Persist.toml. It specifies the data source (MySQL, by default), DB connection details, and other configurations required by the bal persist tool. This file needs to be committed to the repository, and in this case, hard-coding DB connection details in Persist.toml is not an option. Ideally, the connection details should be specified via environment variables.
We have an excellent way to configure Ballerina programs via configurable variables, but this issue describes an approach to configure the bal tool.
There is no standard way to specify environment variables in .toml files. See: https://github.com/toml-lang/toml/issues/25
Here is my proposal.
Environment variables can be specified only in the:
- TOML keys with string values.
- string values in TOML Arrays
BalToolManagedFile.toml
------------------------
any.toml.key.with.string.value = "xxxx${FOO_BAR}xxxx"
We can use the same rules in Ballerina template-expr to parse and escape characters.
Here FOO_BAR is an environment variable.
We also need a convenient way to specify environment variables when running bal commands. How about a bal.env file at the root of the package directory? bal.env should be added to the .gitignore file.
We can use the subset of the property file format or the popular NodeJS .env file format. See: https://github.com/motdotla/dotenv