Search in sources :

Example 1 with ConfigValue

use of io.smallrye.config.ConfigValue 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 2 with ConfigValue

use of io.smallrye.config.ConfigValue in project keycloak by keycloak.

the class ExecutionExceptionHandler method printErrorHints.

private void printErrorHints(PrintWriter errorWriter, Throwable cause) {
    if (cause instanceof FileSystemException) {
        FileSystemException fse = (FileSystemException) cause;
        ConfigValue httpsCertFile = getConfig().getConfigValue("kc.https-certificate-file");
        if (fse.getFile().equals(Optional.ofNullable(httpsCertFile.getValue()).orElse(null))) {
            logError(errorWriter, Messages.httpsConfigurationNotSet().getMessage());
        }
    }
}
Also used : FileSystemException(java.nio.file.FileSystemException) ConfigValue(io.smallrye.config.ConfigValue)

Example 3 with ConfigValue

use of io.smallrye.config.ConfigValue in project keycloak by keycloak.

the class ShowConfig method printProperty.

private void printProperty(String property) {
    ConfigValue configValue = getConfigValue(property);
    if (configValue.getValue() == null) {
        configValue = getConfigValue(property);
    }
    if (configValue.getValue() == null) {
        return;
    }
    if (configValue.getSourceName() == null) {
        return;
    }
    spec.commandLine().getOut().printf("\t%s =  %s (%s)%n", configValue.getName(), formatValue(configValue.getName(), configValue.getValue()), configValue.getConfigSourceName());
}
Also used : ConfigValue(io.smallrye.config.ConfigValue) Configuration.getConfigValue(org.keycloak.quarkus.runtime.configuration.Configuration.getConfigValue)

Example 4 with ConfigValue

use of io.smallrye.config.ConfigValue in project keycloak by keycloak.

the class ShowConfig method getPropertiesByGroup.

private static Map<String, Set<String>> getPropertiesByGroup() {
    Map<String, Set<String>> properties = StreamSupport.stream(getPropertyNames().spliterator(), false).filter(ShowConfig::filterByGroup).collect(Collectors.groupingBy(ShowConfig::groupProperties, Collectors.toSet()));
    StreamSupport.stream(getPropertyNames().spliterator(), false).filter(new Predicate<String>() {

        @Override
        public boolean test(String s) {
            ConfigValue configValue = getConfigValue(s);
            if (configValue == null) {
                return false;
            }
            return PersistedConfigSource.NAME.equals(configValue.getConfigSourceName());
        }
    }).filter(ShowConfig::filterByGroup).collect(Collectors.groupingBy(ShowConfig::groupProperties, Collectors.toSet())).forEach(new BiConsumer<String, Set<String>>() {

        @Override
        public void accept(String group, Set<String> propertyNames) {
            properties.computeIfAbsent(group, name -> new HashSet<>()).addAll(propertyNames);
        }
    });
    return properties;
}
Also used : ConfigValue(io.smallrye.config.ConfigValue) Configuration.getConfigValue(org.keycloak.quarkus.runtime.configuration.Configuration.getConfigValue) Set(java.util.Set) HashSet(java.util.HashSet) Predicate(java.util.function.Predicate)

Example 5 with ConfigValue

use of io.smallrye.config.ConfigValue in project keycloak by keycloak.

the class PropertyMappers method getValue.

public static ConfigValue getValue(ConfigSourceInterceptorContext context, String name) {
    PropertyMapper mapper = MAPPERS.getOrDefault(name, PropertyMapper.IDENTITY);
    ConfigValue configValue = mapper.getConfigValue(name, context);
    if (configValue == null) {
        Optional<String> prefixedMapper = getPrefixedMapper(name);
        if (prefixedMapper.isPresent()) {
            return MAPPERS.get(prefixedMapper.get()).getConfigValue(name, context);
        }
    } else {
        configValue.withName(mapper.getTo());
    }
    return configValue;
}
Also used : ConfigValue(io.smallrye.config.ConfigValue)

Aggregations

ConfigValue (io.smallrye.config.ConfigValue)9 Configuration.getConfigValue (org.keycloak.quarkus.runtime.configuration.Configuration.getConfigValue)2 PropertyMapper (org.keycloak.quarkus.runtime.configuration.mappers.PropertyMapper)2 BuildStep (io.quarkus.deployment.annotations.BuildStep)1 GeneratedResourceBuildItem (io.quarkus.deployment.builditem.GeneratedResourceBuildItem)1 ByteArrayOutputStream (java.io.ByteArrayOutputStream)1 File (java.io.File)1 IOException (java.io.IOException)1 FileSystemException (java.nio.file.FileSystemException)1 HashSet (java.util.HashSet)1 Properties (java.util.Properties)1 Set (java.util.Set)1 Predicate (java.util.function.Predicate)1 JarFile (java.util.jar.JarFile)1