- changed status to resolved
Environment substitution support for url's
Issue #493
resolved
making use of : https://bitbucket.org/asomov/snakeyaml/wiki/Variable substitution
I have the following in a config file:
database:
url: ${DATABASE_URL:-jdbc:postgresql://localhost:5432/server}
user: ${DATABASE_USER:-server}
password: ${DATABASE_PASSWORD:-passw0rd1}
user and password are being substituted correctly, but url is not.
code to config and load yaml:
private fun loadProperties(file: String): Properties {
return try {
val stream = PersistenceConfiguration::class.java.classLoader.getResourceAsStream(file)
val yaml = Yaml(EnvScalarConstructor())
yaml.addImplicitResolver(EnvScalarConstructor.ENV_TAG, EnvScalarConstructor.ENV_FORMAT, "$")
yaml.loadAs(stream, Properties::class.java)
} catch (e: Exception) {
throw RuntimeException(e)
}
}
println("properties = ${properties}")
gives:
properties = {database={url=${DATABASE_URL:-jdbc:postgresql://localhost:5432/server}, user=server, password=passw0rd1}}
is it a bug? is there a workaround?
thoughts welcome.
Comments (3)
-
-
Feel free to test the latest source code.
assertEquals("{database={url=jdbc:postgresql://localhost:5432/server493, user=user493, password=password493}}", output);
-
it will be delivered in version 1.28 in February 2021
- Log in to comment
Fix issue 493: env value can contain special characters
→ <<cset 84f4c0f50d8a>>