Skip to content

Possibility to nullify config used in ConfigMapping #1291

Description

@alex-martel

This heavily relates to; #845

I have some ConfigMapping that are feature related. Those feature are enabled/disabled via .enabled=[true|false]

those ConfigMapping are used "lazily" in ApplicationScoped bean that are using Instance<> and LookupIfProperty() mechanism in quarkus.

I wish that if the enabled flag is false, all of feature.**.* get nullified to I don't have a startup error. I do not know / want to specify manually all the configs to be nullyfied, nor I want to force people to go and remove all their feature related config, they should just toggle the enabled/disable so they don't have to fully reconfigure the feature.

I tried using an interceptor, but it does not work, as the ConfigMapping does not "load" values "/ usees interceptor..

but in soft the logic I had taht I would kike somehow to apply to the config mapping is the following;

public class SubSystemDisabler implements ConfigSourceInterceptor {
    private static final long serialVersionUID = 1L;
  
    private static final List<String> subSystems = List.of("feature", "feature_b", "feature_b");
    private static final UnaryOperator<String> ENABLED = name -> name.concat(".enabled");
    private static final UnaryOperator<String> STARTS_WITH_ANY = name -> subSystems.stream()
            .filter(name::startsWith).findFirst().orElse(null);
    @Override
    public ConfigValue getValue(ConfigSourceInterceptorContext context, String name) {
        String handle = STARTS_WITH_ANY.apply(name);
        if (handle != null) {
            String enabled = ENABLED.apply(handle);
            if (enabled.equals(name)) {
                return context.proceed(name);
            }
            ConfigValue subsystemEnabled = context.proceed(enabled);
            if (subsystemEnabled != null && !Boolean.parseBoolean(subsystemEnabled.getValue())) {
                log.debug("{} is false, disabling {}", enabled, name);
                return null;
            }
        }
        return context.proceed(name);
    }
}

Hope it is somewhat clear, I have created a little app here https://github.com/manofthepeace/opt-configmapping to show the structure, with a super simple mapping, in my app the config are far more complex with lots of nesting.

Obviously the above interceptor is wrong for the job, but its what I would like to achieve in a nutshell. Options welcome :) thanks

Metadata

Metadata

Assignees

No one assigned

    Labels

    enhancementNew feature or request

    Type

    No type
    No fields configured for issues without a type.

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions