Skip to content

Commit

Permalink
encapsulating the wildcard behavior
Browse files Browse the repository at this point in the history
Signed-off-by: Steve Hawkins <[email protected]>
  • Loading branch information
shawkins committed Dec 6, 2024
1 parent 2b3e3d4 commit a6bd17e
Show file tree
Hide file tree
Showing 10 changed files with 89 additions and 196 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -379,7 +379,7 @@ public void validateConfig(List<String> cliArgs, AbstractCommand abstractCommand
Optional.ofNullable(PropertyMappers.getRuntimeMappers().get(category)).ifPresent(mappers::addAll);
Optional.ofNullable(PropertyMappers.getBuildTimeMappers().get(category)).ifPresent(mappers::addAll);
for (PropertyMapper<?> mapper : mappers) {
Configuration.getKcConfigValues(mapper).forEach(configValue -> {
mapper.getKcConfigValues().forEach(configValue -> {
String configValueStr = configValue.getValue();

// don't consider missing or anything below standard env properties
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -129,15 +129,15 @@ public void accept(String key, String value) {
PropertyMapper<?> mapper = PropertyMappers.getMapper(key);

if (mapper != null) {
String to = mapper.getTo();
mapper = mapper.forKey(key);

String mappedKey = mapper.getMappedKey(key).orElse(null);
String to = mapper.getTo();

if (to != null) {
properties.put(mapper.getTo(mappedKey), value);
properties.put(mapper.getTo(), value);
}

properties.put(mapper.getFrom(mappedKey), value);
properties.put(mapper.getFrom(), value);
}
}
}, ignored -> {});
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -19,7 +19,6 @@

import static org.keycloak.quarkus.runtime.cli.Picocli.ARG_PREFIX;

import java.util.List;
import java.util.Map;
import java.util.Optional;
import java.util.Properties;
Expand Down Expand Up @@ -113,19 +112,6 @@ public static ConfigValue getKcConfigValue(String propertyName) {
return getConfigValue(NS_KEYCLOAK_PREFIX.concat(propertyName));
}

/**
* Get all Keycloak config values for the mapper. A multivalued config option is a config option that
* has a wildcard in its name, e.g. log-level-<category>.
*
* @return a map of config values where the key is the resolved wildcard (e.g. category) and the value is the config value
*/
public static List<ConfigValue> getKcConfigValues(PropertyMapper<?> mapper) {
if (mapper.hasWildcard()) {
return mapper.getWildcardKeys().stream().map(v -> getConfigValue(mapper.getFrom(v))).toList();
}
return List.of(Configuration.getConfigValue(mapper.getFrom()));
}

public static Optional<String> getOptionalValue(String name) {
return getConfig().getOptionalValue(name, String.class);
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -50,13 +50,15 @@ private static Map<String, String> buildProperties() {
PropertyMapper<?> mapper = PropertyMappers.getMapper(key);

if (mapper != null) {
mapper = mapper.forEnvKey(key);

String to = mapper.getTo();

if (to != null) {
properties.put(to, value);
}

properties.put(mapper.getFrom(mapper.getMappedEnvVarKey(key).orElse(null)), value);
properties.put(mapper.getFrom(), value);
}
else {
// most probably an SPI but could be also something else
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -27,6 +27,7 @@
import org.keycloak.quarkus.runtime.Environment;
import org.keycloak.quarkus.runtime.configuration.mappers.PropertyMapper;
import org.keycloak.quarkus.runtime.configuration.mappers.PropertyMappers;
import org.keycloak.quarkus.runtime.configuration.mappers.WildcardPropertyMapper;

import java.util.Iterator;
import java.util.List;
Expand Down Expand Up @@ -87,7 +88,7 @@ public Iterator<String> iterateNames(ConfigSourceInterceptorContext context) {
disableAdditionalNames.set(true);
try {
mappedWildcardNames = PropertyMappers.getWildcardMappers().stream()
.map(PropertyMapper::getToWithWildcards)
.map(WildcardPropertyMapper::getToWithWildcards)
.flatMap(Set::stream)
.toList();
} finally {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -112,7 +112,7 @@ public static PropertyMapper<?>[] getMappers() {
.validator(LoggingPropertyMappers::validateCategoryLogLevel)
.wildcardKeysTransformer(LoggingPropertyMappers::getConfiguredLogCategories)
.transformer((v,c) -> toLevel(v).getName())
.mapFrom(LoggingOptions.LOG_LEVEL, LoggingPropertyMappers::resolveCategoryLogLevelFromParentLogLevelOption) // a fallback to log-level
.wildcardMapFrom(LoggingOptions.LOG_LEVEL, LoggingPropertyMappers::resolveCategoryLogLevelFromParentLogLevelOption) // a fallback to log-level
.paramLabel("level")
.build(),
// Syslog
Expand Down
Loading

0 comments on commit a6bd17e

Please sign in to comment.