ballerina-spec icon indicating copy to clipboard operation
ballerina-spec copied to clipboard

Support environment variable expansion in Bal tool-managed configuration files such as `Ballerina.toml`, `Persist.toml`

Open sameerajayasoma opened this issue 3 years ago • 3 comments

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.

sameerajayasoma avatar Nov 28 '22 22:11 sameerajayasoma

There is no standard way to specify environment variables in .toml files. See: https://github.com/toml-lang/toml/issues/25

sameerajayasoma avatar Nov 28 '22 22:11 sameerajayasoma

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.

sameerajayasoma avatar Nov 28 '22 22:11 sameerajayasoma

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

sameerajayasoma avatar Nov 28 '22 22:11 sameerajayasoma