All Downloads are FREE. Search and download functionalities are using the official Maven repository.

org.unleash.features.config.UnleashAutoConfiguration Maven / Gradle / Ivy

There is a newer version: 1.0.29
Show newest version
package org.unleash.features.config;

import io.getunleash.DefaultUnleash;
import io.getunleash.Unleash;
import io.getunleash.strategy.Strategy;
import io.getunleash.util.UnleashConfig;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.boot.autoconfigure.condition.ConditionalOnBean;
import org.springframework.boot.context.properties.EnableConfigurationProperties;
import org.springframework.context.annotation.Bean;
import org.springframework.context.annotation.ComponentScan;
import org.springframework.context.annotation.Configuration;
import org.springframework.util.CollectionUtils;
import org.springframework.util.StringUtils;
import org.unleash.features.autoconfigure.UnleashProperties;

import java.util.Map;
import java.util.UUID;

@SuppressWarnings("SpringJavaAutowiredFieldsWarningInspection")
@Configuration
@EnableConfigurationProperties(UnleashProperties.class)
@ComponentScan("org.unleash.features.aop")
public class UnleashAutoConfiguration {
    @Autowired(required = false)
    private Map strategyMap;

    @Bean
    @ConditionalOnBean(UnleashProperties.class)
    public Unleash unleash(final UnleashProperties unleashProperties) {
        final UnleashConfig unleashConfig = UnleashConfig
                .builder()
                .appName(unleashProperties.getAppName())
                .environment(unleashProperties.getEnvironment())
                .unleashAPI(unleashProperties.getApiUrl())
                .customHttpHeader("Authorization", unleashProperties.getApiToken())
                .instanceId(!StringUtils.hasText(unleashProperties.getInstanceId()) ? unleashProperties.getInstanceId() : UUID.randomUUID().toString())
                .build();

        return !CollectionUtils.isEmpty(strategyMap) ? new DefaultUnleash(unleashConfig, strategyMap.values().toArray(new Strategy[0])) :
                new DefaultUnleash(unleashConfig);
    }
}




© 2015 - 2024 Weber Informatics LLC | Privacy Policy