Search in sources :

Example 1 with PropertyMapper

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());
        }
    }
}
Also used : StaticInitConfigSourceProviderBuildItem(io.quarkus.deployment.builditem.StaticInitConfigSourceProviderBuildItem) PropertyMapper(org.keycloak.quarkus.runtime.configuration.mappers.PropertyMapper) BuildStep(io.quarkus.deployment.annotations.BuildStep)

Example 2 with PropertyMapper

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);
    }
}
Also used : ConfigValue(io.smallrye.config.ConfigValue) GeneratedResourceBuildItem(io.quarkus.deployment.builditem.GeneratedResourceBuildItem) ByteArrayOutputStream(java.io.ByteArrayOutputStream) Properties(java.util.Properties) PropertyMapper(org.keycloak.quarkus.runtime.configuration.mappers.PropertyMapper) File(java.io.File) JarFile(java.util.jar.JarFile) IOException(java.io.IOException) BuildStep(io.quarkus.deployment.annotations.BuildStep)

Example 3 with PropertyMapper

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());
    }
}
Also used : PersistedConfigSource(org.keycloak.quarkus.runtime.configuration.PersistedConfigSource) ConfigArgsConfigSource.parseConfigArgs(org.keycloak.quarkus.runtime.configuration.ConfigArgsConfigSource.parseConfigArgs) UnaryOperator(java.util.function.UnaryOperator) Configuration.getRuntimeProperty(org.keycloak.quarkus.runtime.configuration.Configuration.getRuntimeProperty) ArrayList(java.util.ArrayList) Environment.isDevMode(org.keycloak.quarkus.runtime.Environment.isDevMode) ConfigArgsConfigSource(org.keycloak.quarkus.runtime.configuration.ConfigArgsConfigSource) AUTO_BUILD_OPTION_SHORT(org.keycloak.quarkus.runtime.cli.command.AbstractStartCommand.AUTO_BUILD_OPTION_SHORT) PropertyMappers(org.keycloak.quarkus.runtime.configuration.mappers.PropertyMappers) Build(org.keycloak.quarkus.runtime.cli.command.Build) Map(java.util.Map) BiConsumer(java.util.function.BiConsumer) StringUtil.isNotBlank(org.keycloak.utils.StringUtil.isNotBlank) OptionSpec(picocli.CommandLine.Model.OptionSpec) CommandLine(picocli.CommandLine) PrintWriter(java.io.PrintWriter) Environment(org.keycloak.quarkus.runtime.Environment) PropertyMappers.formatValue(org.keycloak.quarkus.runtime.configuration.mappers.PropertyMappers.formatValue) Configuration.getConfig(org.keycloak.quarkus.runtime.configuration.Configuration.getConfig) OPTION_PART_SEPARATOR(org.keycloak.quarkus.runtime.configuration.Configuration.OPTION_PART_SEPARATOR) Iterator(java.util.Iterator) Main(org.keycloak.quarkus.runtime.cli.command.Main) Predicate(java.util.function.Predicate) Set(java.util.Set) ConfigArgsConfigSource.hasOptionValue(org.keycloak.quarkus.runtime.configuration.ConfigArgsConfigSource.hasOptionValue) ArgGroupSpec(picocli.CommandLine.Model.ArgGroupSpec) Collectors(java.util.stream.Collectors) ConfigValue(io.smallrye.config.ConfigValue) PropertyMappers.isBuildTimeProperty(org.keycloak.quarkus.runtime.configuration.mappers.PropertyMappers.isBuildTimeProperty) File(java.io.File) List(java.util.List) Start(org.keycloak.quarkus.runtime.cli.command.Start) Configuration.getBuildTimeProperty(org.keycloak.quarkus.runtime.configuration.Configuration.getBuildTimeProperty) Optional(java.util.Optional) ConfigCategory(org.keycloak.quarkus.runtime.configuration.mappers.ConfigCategory) PropertyMapper(org.keycloak.quarkus.runtime.configuration.mappers.PropertyMapper) SECTION_KEY_COMMAND_LIST(picocli.CommandLine.Model.UsageMessageSpec.SECTION_KEY_COMMAND_LIST) CommandSpec(picocli.CommandLine.Model.CommandSpec) Quarkus(io.quarkus.runtime.Quarkus) StartDev(org.keycloak.quarkus.runtime.cli.command.StartDev) AUTO_BUILD_OPTION_LONG(org.keycloak.quarkus.runtime.cli.command.AbstractStartCommand.AUTO_BUILD_OPTION_LONG) ConfigCategory(org.keycloak.quarkus.runtime.configuration.mappers.ConfigCategory) ArgGroupSpec(picocli.CommandLine.Model.ArgGroupSpec) PropertyMapper(org.keycloak.quarkus.runtime.configuration.mappers.PropertyMapper)

Example 4 with PropertyMapper

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);
}
Also used : CommandSpec(picocli.CommandLine.Model.CommandSpec) ArrayList(java.util.ArrayList) PropertyMapper(org.keycloak.quarkus.runtime.configuration.mappers.PropertyMapper)

Example 5 with PropertyMapper

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;
}
Also used : HashMap(java.util.HashMap) PropertyMapper(org.keycloak.quarkus.runtime.configuration.mappers.PropertyMapper)

Aggregations

PropertyMapper (org.keycloak.quarkus.runtime.configuration.mappers.PropertyMapper)7 ConfigValue (io.smallrye.config.ConfigValue)3 BuildStep (io.quarkus.deployment.annotations.BuildStep)2 File (java.io.File)2 ArrayList (java.util.ArrayList)2 CommandSpec (picocli.CommandLine.Model.CommandSpec)2 GeneratedResourceBuildItem (io.quarkus.deployment.builditem.GeneratedResourceBuildItem)1 StaticInitConfigSourceProviderBuildItem (io.quarkus.deployment.builditem.StaticInitConfigSourceProviderBuildItem)1 Quarkus (io.quarkus.runtime.Quarkus)1 ByteArrayOutputStream (java.io.ByteArrayOutputStream)1 IOException (java.io.IOException)1 PrintWriter (java.io.PrintWriter)1 HashMap (java.util.HashMap)1 Iterator (java.util.Iterator)1 List (java.util.List)1 Map (java.util.Map)1 Optional (java.util.Optional)1 Properties (java.util.Properties)1 Set (java.util.Set)1 BiConsumer (java.util.function.BiConsumer)1