-
Couldn't load subscription status.
- Fork 1.1k
feat(12135): Adding support for list access using env variables #12136
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
base: 4.10.x
Are you sure you want to change the base?
Changes from 2 commits
File filter
Filter by extension
Conversations
Jump to
Diff view
Diff view
There are no files selected for viewing
| Original file line number | Diff line number | Diff line change |
|---|---|---|
|
|
@@ -28,6 +28,10 @@ | |
| * @since 1.0 | ||
| */ | ||
| public class EnvironmentPropertySource extends MapPropertySource { | ||
| /** | ||
| * Converts list elemtents defined as _0 or _0_ into names that the resolver can understand; i.e., [0]. | ||
| */ | ||
| private static final String LIST_CONVERTER_REGEX = "_([0-9]{1,2})(?:_|$)"; | ||
|
|
||
| /** | ||
| * The position of the loader. | ||
|
|
@@ -77,20 +81,20 @@ static Map getEnv(@Nullable List<String> includes, @Nullable List<String> exclud | |
| } | ||
|
|
||
| static Map getEnv(Map<String, String> env, @Nullable List<String> includes, @Nullable List<String> excludes) { | ||
| if (includes != null || excludes != null) { | ||
| Map<String, String> result = new HashMap<>(); | ||
| for (Map.Entry<String, String> entry : env.entrySet()) { | ||
| String envVar = entry.getKey(); | ||
| if (excludes != null && excludes.contains(envVar)) { | ||
| continue; | ||
| } | ||
| if (includes != null && !includes.contains(envVar)) { | ||
| continue; | ||
| } | ||
| result.put(envVar, entry.getValue()); | ||
| Map<String, String> result = new HashMap<>(); | ||
|
||
| for (Map.Entry<String, String> entry : env.entrySet()) { | ||
| String envVar = entry.getKey(); | ||
| if (excludes != null && excludes.contains(envVar)) { | ||
| continue; | ||
| } | ||
| if (includes != null && !includes.contains(envVar)) { | ||
| continue; | ||
| } | ||
| return result; | ||
|
|
||
| String convertedEnvVar = envVar.replaceAll(LIST_CONVERTER_REGEX, "[$1]"); | ||
|
|
||
| result.put(convertedEnvVar, entry.getValue()); | ||
| } | ||
| return env; | ||
| return result; | ||
| } | ||
| } | ||
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
pre compile this regex
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Done