Search in sources :

Example 6 with PropertyMapper

use of org.keycloak.quarkus.runtime.configuration.mappers.PropertyMapper in project keycloak by keycloak.

the class Help method isVisible.

private boolean isVisible(OptionSpec option) {
    if (allOptions) {
        return true;
    }
    String optionName = option.longestName();
    boolean isFeatureOption = optionName.startsWith("--feature");
    String canonicalOptionName = NS_KEYCLOAK_PREFIX.concat(optionName.replace("--", ""));
    String propertyName = getMappedPropertyName(canonicalOptionName);
    PropertyMapper mapper = getMapper(propertyName);
    if (mapper == null && !isFeatureOption) {
        // only filter mapped and non-feature options
        return true;
    }
    String commandName = commandSpec().name();
    boolean isBuildTimeProperty = isFeatureOption || mapper.isBuildTime();
    if (Build.NAME.equals(commandName)) {
        // by default, build command only shows build time props
        return isBuildTimeProperty;
    }
    if (StartDev.NAME.equals(commandName)) {
        // by default, start-dev command only shows runtime props
        return !isBuildTimeProperty;
    }
    return true;
}
Also used : PropertyMapper(org.keycloak.quarkus.runtime.configuration.mappers.PropertyMapper)

Example 7 with PropertyMapper

use of org.keycloak.quarkus.runtime.configuration.mappers.PropertyMapper in project keycloak by keycloak.

the class Picocli method hasConfigChanges.

private static boolean hasConfigChanges() {
    Optional<String> currentProfile = Optional.ofNullable(Environment.getProfile());
    Optional<String> persistedProfile = getBuildTimeProperty("kc.profile");
    if (!persistedProfile.orElse("").equals(currentProfile.orElse(""))) {
        return true;
    }
    for (String propertyName : getConfig().getPropertyNames()) {
        // only check keycloak build-time properties
        if (!isBuildTimeProperty(propertyName)) {
            continue;
        }
        ConfigValue configValue = getConfig().getConfigValue(propertyName);
        if (configValue == null || configValue.getConfigSourceName() == null) {
            continue;
        }
        // try to resolve any property set using profiles
        if (propertyName.startsWith("%")) {
            propertyName = propertyName.substring(propertyName.indexOf('.') + 1);
        }
        String persistedValue = getBuildTimeProperty(propertyName).orElse("");
        String runtimeValue = getRuntimeProperty(propertyName).orElse(null);
        if (runtimeValue == null && isNotBlank(persistedValue)) {
            PropertyMapper mapper = PropertyMappers.getMapper(propertyName);
            if (mapper != null && persistedValue.equals(mapper.getDefaultValue())) {
                // same as default
                continue;
            }
            // probably because it was unset
            return true;
        }
        // changes to a single property is enough to indicate changes to configuration
        if (!persistedValue.equals(runtimeValue)) {
            return true;
        }
    }
    return false;
}
Also used : ConfigValue(io.smallrye.config.ConfigValue) 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