Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Set Play Framework Configuration Variable of type list with an environment variable

What I am trying to do is setting a configuration variable of type list as environment variable. I know that I can use env variables like this:

variable = ${?ENV_VAR}

But what I dont know is how the env var must look like to be accepted as type list. I have tried:

( "item1" "item2" )
["item1","item2"]
"item1":"item2"

All three notations throw a config exception:

Configuration error[env var ES_NODES: elasticsearch.hosts has type STRING rather than LIST]

How can I tell play to parse an env var as list?

like image 218
MeiSign Avatar asked Oct 31 '22 10:10

MeiSign


1 Answers

tested with play 2.3 The following is an optional solution (there might be other solutions that are prettier...):

env config exmple:

export KAFKA_BROKERS="12.1.1.2:9092,33.3.3.3:9092"

and play config:

kafka.brokersStr = "127.0.0.1:9092","someotherip:9092"
kafka.brokersStr = ${?KAFKA_BROKERS}
kafka.brokers = [${kafka.brokersStr}]

If $KAFKA_BROKERS is not defined the second assignment into "kafka.brokersStr" will be ignored.


The problem is that if KAFKA_BROKERS is not defined and if we will use it directly in the list, "kafka.brokers" will be "[]" and override any default configuration even though there is no value in $KAFKA_BROKERS.

The bad example:
In play application.conf there is a feature that if an env var is set to an undefined env var the configuration will use a previous value: e.g env var AA is not defined and in conf you heve the following :

a.a = "aa" 
a.a = ${?AA}

a.a will still be "aa"

but if a.a was a list:

a.a = ["aa"]
a.a = [${?AA}]

a.a would be an empty list "[]"

like image 155
ozma Avatar answered Dec 21 '22 12:12

ozma