Skip to content

Commit 3c45da5

Browse files
committed
Perform mapping for config options pulled from the environment
This allows us to specify config options using a fairly simple mapping of "secition.option" to "SECTION_OPTION".
1 parent e7afeaf commit 3c45da5

File tree

1 file changed

+13
-1
lines changed

1 file changed

+13
-1
lines changed

java/server/src/org/openqa/selenium/grid/config/EnvConfig.java

Lines changed: 13 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -20,16 +20,28 @@
2020
import com.google.common.collect.ImmutableList;
2121

2222
import java.util.List;
23+
import java.util.Locale;
2324
import java.util.Objects;
2425
import java.util.Optional;
2526

27+
/**
28+
* Exposes environment variables as config settings by mapping
29+
* "section.option" to "SECTION_OPTION". Dashes and periods in the options
30+
* are converted to underscores, and all characters are upper-cased assuming
31+
* a US English locale.
32+
*/
2633
public class EnvConfig implements Config {
2734

2835
@Override
2936
public Optional<List<String>> getAll(String section, String option) {
3037
Objects.requireNonNull(section, "Section name not set");
3138
Objects.requireNonNull(option, "Option name not set");
3239

33-
return Optional.ofNullable(System.getenv().get(section + "." + option)).map(ImmutableList::of);
40+
String key = String.format("%s_%s", section, option)
41+
.toUpperCase(Locale.US)
42+
.replace("-", "_")
43+
.replace(".", "_");
44+
45+
return Optional.ofNullable(System.getenv().get(key)).map(ImmutableList::of);
3446
}
3547
}

0 commit comments

Comments
 (0)