Skip to content

Commit 7433ffc

Browse files
committed
Support config profiles through environment variable
1 parent c14d744 commit 7433ffc

File tree

2 files changed

+14
-4
lines changed

2 files changed

+14
-4
lines changed

CHANGELOG.md

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -3,6 +3,9 @@
33
* [new] Support JSON and YAML expansion in configuration. Use a `myKey|json` or `myKey|yaml` as key syntax. The suffix
44
will be removed and the value will be replaced by the parsed subtree. Useful for parsing JSON structures passed by
55
cloud platforms.
6+
* [new] The `SEEDSTACK_PROFILES` environment variable can now be used to specify comma-separated configuration profiles
7+
to enable. These profiles will be added to the profiles already defined in the `seedstack.profiles` system property if
8+
any.
69

710
# Version 3.12.1 (2021-05-21)
811

core/src/main/java/org/seedstack/seed/core/internal/configuration/ProfileProcessor.java

Lines changed: 11 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -8,22 +8,26 @@
88
package org.seedstack.seed.core.internal.configuration;
99

1010
import com.google.common.base.Strings;
11+
import org.seedstack.coffig.TreeNode;
12+
import org.seedstack.coffig.node.MapNode;
13+
import org.seedstack.coffig.spi.ConfigurationProcessor;
14+
1115
import java.util.ArrayList;
1216
import java.util.Arrays;
1317
import java.util.HashMap;
18+
import java.util.HashSet;
1419
import java.util.List;
1520
import java.util.Map;
21+
import java.util.Optional;
1622
import java.util.Set;
1723
import java.util.function.Predicate;
1824
import java.util.regex.Matcher;
1925
import java.util.regex.Pattern;
2026
import java.util.stream.Collectors;
21-
import org.seedstack.coffig.TreeNode;
22-
import org.seedstack.coffig.node.MapNode;
23-
import org.seedstack.coffig.spi.ConfigurationProcessor;
2427

2528
public class ProfileProcessor implements ConfigurationProcessor {
2629
private static final String SEEDSTACK_PROFILES_PROPERTY = "seedstack.profiles";
30+
private static final String SEEDSTACK_PROFILES_ENV = "SEEDSTACK_PROFILES";
2731
private static Pattern keyWithProfilePattern = Pattern.compile("(.*)<([,\\s\\w]+)>");
2832
private static Predicate<String> notNullOrEmpty = ((Predicate<String>) Strings::isNullOrEmpty).negate();
2933

@@ -67,6 +71,9 @@ private static Set<String> parseProfiles(String value) {
6771
}
6872

6973
static Set<String> activeProfiles() {
70-
return parseProfiles(System.getProperty(SEEDSTACK_PROFILES_PROPERTY, ""));
74+
Set<String> activeProfiles = new HashSet<>();
75+
activeProfiles.addAll(parseProfiles(System.getProperty(SEEDSTACK_PROFILES_PROPERTY, "")));
76+
activeProfiles.addAll(parseProfiles(Optional.ofNullable(System.getenv(SEEDSTACK_PROFILES_ENV)).orElse("")));
77+
return activeProfiles;
7178
}
7279
}

0 commit comments

Comments
 (0)