use of org.keycloak.quarkus.runtime.configuration.mappers.PropertyMapper in project keycloak by keycloak.
the class KeycloakProcessor method prepareTestEnvironment.
@BuildStep(onlyIf = IsIntegrationTest.class)
void prepareTestEnvironment(BuildProducer<StaticInitConfigSourceProviderBuildItem> configSources, DevServicesDatasourceResultBuildItem dbConfig) {
configSources.produce(new StaticInitConfigSourceProviderBuildItem("org.keycloak.quarkus.runtime.configuration.test.TestKeycloakConfigSourceProvider"));
// this might be too sensitive and break if Quarkus changes the behavior
if (dbConfig != null && dbConfig.getDefaultDatasource() != null) {
Map<String, String> configProperties = dbConfig.getDefaultDatasource().getConfigProperties();
for (Entry<String, String> dbConfigProperty : configProperties.entrySet()) {
PropertyMapper mapper = PropertyMappers.getMapper(dbConfigProperty.getKey());
if (mapper == null) {
continue;
}
String kcProperty = mapper.getFrom();
if (kcProperty.endsWith("db")) {
// db kind set when running tests
continue;
}
System.setProperty(kcProperty, dbConfigProperty.getValue());
}
}
}
use of org.keycloak.quarkus.runtime.configuration.mappers.PropertyMapper in project keycloak by keycloak.
the class KeycloakProcessor method persistBuildTimeProperties.
/**
* <p>Make the build time configuration available at runtime so that the server can run without having to specify some of
* the properties again.
*/
@BuildStep(onlyIf = IsReAugmentation.class)
void persistBuildTimeProperties(BuildProducer<GeneratedResourceBuildItem> resources) {
Properties properties = new Properties();
for (String name : getPropertyNames()) {
PropertyMapper mapper = PropertyMappers.getMapper(name);
ConfigValue value = null;
if (mapper == null) {
if (name.startsWith(NS_QUARKUS)) {
value = Configuration.getConfigValue(name);
if (!QuarkusPropertiesConfigSource.isSameSource(value)) {
continue;
}
}
} else if (mapper.isBuildTime()) {
name = mapper.getFrom();
value = Configuration.getConfigValue(name);
}
if (value != null && value.getValue() != null) {
properties.put(name, value.getValue());
}
}
for (File jar : getProviderFiles().values()) {
properties.put(String.format("kc.provider.file.%s.last-modified", jar.getName()), String.valueOf(jar.lastModified()));
}
String profile = Environment.getProfile();
if (profile != null) {
properties.put(Environment.PROFILE, profile);
properties.put(ProfileManager.QUARKUS_PROFILE_PROP, profile);
}
properties.put(QUARKUS_PROPERTY_ENABLED, String.valueOf(QuarkusPropertiesConfigSource.getConfigurationFile() != null));
try (ByteArrayOutputStream outputStream = new ByteArrayOutputStream()) {
properties.store(outputStream, " Auto-generated, DO NOT change this file");
resources.produce(new GeneratedResourceBuildItem(PersistedConfigSource.PERSISTED_PROPERTIES, outputStream.toByteArray()));
} catch (Exception cause) {
throw new RuntimeException("Failed to persist configuration", cause);
}
}
use of org.keycloak.quarkus.runtime.configuration.mappers.PropertyMapper in project keycloak by keycloak.
the class Picocli method addMappedOptionsToArgGroups.
private static void addMappedOptionsToArgGroups(CommandSpec cSpec, List<PropertyMapper> propertyMappers) {
for (ConfigCategory category : ConfigCategory.values()) {
List<PropertyMapper> mappersInCategory = propertyMappers.stream().filter(m -> category.equals(m.getCategory())).collect(Collectors.toList());
if (mappersInCategory.isEmpty()) {
// picocli raises an exception when an ArgGroup is empty, so ignore it when no mappings found for a category.
continue;
}
ArgGroupSpec.Builder argGroupBuilder = ArgGroupSpec.builder().heading(category.getHeading() + ":").order(category.getOrder()).validate(false);
for (PropertyMapper mapper : mappersInCategory) {
String name = mapper.getCliFormat();
String description = mapper.getDescription();
if (description == null || cSpec.optionsMap().containsKey(name) || name.endsWith(OPTION_PART_SEPARATOR)) {
// when key is already added or has no description, don't add.
continue;
}
String defaultValue = mapper.getDefaultValue();
Iterable<String> expectedValues = mapper.getExpectedValues();
argGroupBuilder.addArg(OptionSpec.builder(name).defaultValue(defaultValue).description(description).paramLabel(mapper.getParamLabel()).completionCandidates(expectedValues).parameterConsumer(PropertyMapperParameterConsumer.INSTANCE).type(String.class).hidden(mapper.isHidden()).build());
}
cSpec.addArgGroup(argGroupBuilder.build());
}
}
use of org.keycloak.quarkus.runtime.configuration.mappers.PropertyMapper in project keycloak by keycloak.
the class Picocli method addOption.
private static void addOption(CommandSpec spec, String command, boolean includeBuildTime, boolean includeRuntime) {
CommandSpec commandSpec = spec.subcommands().get(command).getCommandSpec();
List<PropertyMapper> mappers = new ArrayList<>();
if (includeRuntime) {
mappers.addAll(PropertyMappers.getRuntimeMappers());
}
if (includeBuildTime) {
mappers.addAll(PropertyMappers.getBuildTimeMappers());
}
addMappedOptionsToArgGroups(commandSpec, mappers);
}
use of org.keycloak.quarkus.runtime.configuration.mappers.PropertyMapper in project keycloak by keycloak.
the class KeycloakPropertiesConfigSource method transform.
private static Map<String, String> transform(Map<String, String> properties) {
Map<String, String> result = new HashMap<>(properties.size());
properties.keySet().forEach(k -> {
String key = transformKey(k);
PropertyMapper mapper = PropertyMappers.getMapper(key);
// TODO: remove explicit checks for spi and feature options once we have proper support in our config mappers
if (mapper != null || key.contains(NS_KEYCLOAK_PREFIX + "spi") || key.contains(NS_KEYCLOAK_PREFIX + "feature")) {
String value = replaceProperties(properties.get(k));
result.put(key, value);
if (mapper != null && key.charAt(0) != '%') {
result.put(getMappedPropertyName(key), value);
}
}
});
return result;
}
Aggregations