Environment substitution support for url's

Issue #493 resolved
Alexander Fanshawe created an issue

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)

  1. Andrey Somov

    Feel free to test the latest source code.

    assertEquals("{database={url=jdbc:postgresql://localhost:5432/server493, user=user493, password=password493}}", output);
    

  2. Log in to comment