Search in sources :

Example 1 with ConfigDataResourceNotFoundException

use of org.springframework.boot.context.config.ConfigDataResourceNotFoundException in project spring-cloud-zookeeper by spring-cloud.

the class ZookeeperConfigDataLoader method load.

@Override
public ConfigData load(ConfigDataLoaderContext context, ZookeeperConfigDataResource resource) {
    try {
        CuratorFramework curator = context.getBootstrapContext().get(CuratorFramework.class);
        if (curator == null) {
            // this can happen if certain conditions are met
            return null;
        }
        ZookeeperPropertySource propertySource = new ZookeeperPropertySource(resource.getContext(), curator);
        List<ZookeeperPropertySource> propertySources = Collections.singletonList(propertySource);
        return new ConfigData(propertySources, source -> {
            List<ConfigData.Option> options = new ArrayList<>();
            options.add(ConfigData.Option.IGNORE_IMPORTS);
            options.add(ConfigData.Option.IGNORE_PROFILES);
            if (StringUtils.hasText(resource.getProfile())) {
                options.add(ConfigData.Option.PROFILE_SPECIFIC);
            }
            return ConfigData.Options.of(options.toArray(new ConfigData.Option[0]));
        });
    } catch (Exception e) {
        if (log.isDebugEnabled()) {
            log.debug("Error getting properties from zookeeper: " + resource, e);
        }
        throw new ConfigDataResourceNotFoundException(resource, e);
    }
}
Also used : CuratorFramework(org.apache.curator.framework.CuratorFramework) ConfigData(org.springframework.boot.context.config.ConfigData) ArrayList(java.util.ArrayList) ConfigDataResourceNotFoundException(org.springframework.boot.context.config.ConfigDataResourceNotFoundException) ConfigDataResourceNotFoundException(org.springframework.boot.context.config.ConfigDataResourceNotFoundException)

Example 2 with ConfigDataResourceNotFoundException

use of org.springframework.boot.context.config.ConfigDataResourceNotFoundException in project spring-cloud-aws by awspring.

the class AwsSecretsManagerConfigDataLoader method load.

@Override
public ConfigData load(ConfigDataLoaderContext context, AwsSecretsManagerConfigDataResource resource) {
    try {
        AWSSecretsManager sm = context.getBootstrapContext().get(AWSSecretsManager.class);
        AwsSecretsManagerPropertySource propertySource = resource.getPropertySources().createPropertySource(resource.getContext(), resource.isOptional(), sm);
        if (propertySource != null) {
            return new ConfigData(Collections.singletonList(propertySource));
        } else {
            return null;
        }
    } catch (Exception e) {
        throw new ConfigDataResourceNotFoundException(resource, e);
    }
}
Also used : AwsSecretsManagerPropertySource(io.awspring.cloud.secretsmanager.AwsSecretsManagerPropertySource) ConfigData(org.springframework.boot.context.config.ConfigData) AWSSecretsManager(com.amazonaws.services.secretsmanager.AWSSecretsManager) ConfigDataResourceNotFoundException(org.springframework.boot.context.config.ConfigDataResourceNotFoundException) ConfigDataResourceNotFoundException(org.springframework.boot.context.config.ConfigDataResourceNotFoundException)

Example 3 with ConfigDataResourceNotFoundException

use of org.springframework.boot.context.config.ConfigDataResourceNotFoundException in project spring-cloud-aws by awspring.

the class ParameterStoreConfigDataLoader method load.

@Override
@Nullable
public ConfigData load(ConfigDataLoaderContext context, ParameterStoreConfigDataResource resource) {
    try {
        SsmClient ssm = context.getBootstrapContext().get(SsmClient.class);
        ParameterStorePropertySource propertySource = resource.getPropertySources().createPropertySource(resource.getContext(), resource.isOptional(), ssm);
        if (propertySource != null) {
            return new ConfigData(Collections.singletonList(propertySource));
        } else {
            return null;
        }
    } catch (Exception e) {
        throw new ConfigDataResourceNotFoundException(resource, e);
    }
}
Also used : ConfigData(org.springframework.boot.context.config.ConfigData) ParameterStorePropertySource(io.awspring.cloud.parameterstore.ParameterStorePropertySource) ConfigDataResourceNotFoundException(org.springframework.boot.context.config.ConfigDataResourceNotFoundException) SsmClient(software.amazon.awssdk.services.ssm.SsmClient) ConfigDataResourceNotFoundException(org.springframework.boot.context.config.ConfigDataResourceNotFoundException) Nullable(org.springframework.lang.Nullable)

Example 4 with ConfigDataResourceNotFoundException

use of org.springframework.boot.context.config.ConfigDataResourceNotFoundException in project spring-cloud-consul by spring-cloud.

the class ConsulConfigDataLoader method doLoad.

public ConfigData doLoad(ConfigDataLoaderContext context, ConsulConfigDataResource resource) {
    try {
        ConsulClient consul = getBean(context, ConsulClient.class);
        ConsulConfigIndexes indexes = getBean(context, ConsulConfigIndexes.class);
        ConsulPropertySource propertySource = resource.getConsulPropertySources().createPropertySource(resource.getContext(), consul, indexes.getIndexes()::put);
        if (propertySource == null) {
            return null;
        }
        List<ConsulPropertySource> propertySources = Collections.singletonList(propertySource);
        if (ALL_OPTIONS.size() == 1) {
            // boot 2.4.2 and prior
            return new ConfigData(propertySources);
        } else if (ALL_OPTIONS.size() == 2) {
            // boot 2.4.3 and 2.4.4
            return new ConfigData(propertySources, Option.IGNORE_IMPORTS, Option.IGNORE_PROFILES);
        } else if (ALL_OPTIONS.size() > 2) {
            // boot 2.4.5+
            return new ConfigData(propertySources, source -> {
                List<Option> options = new ArrayList<>();
                options.add(Option.IGNORE_IMPORTS);
                options.add(Option.IGNORE_PROFILES);
                if (StringUtils.hasText(resource.getProfile())) {
                    options.add(Option.PROFILE_SPECIFIC);
                }
                return Options.of(options.toArray(new Option[0]));
            });
        }
    } catch (Exception e) {
        if (log.isDebugEnabled()) {
            log.debug("Error getting properties from consul: " + resource, e);
        }
        throw new ConfigDataResourceNotFoundException(resource, e);
    }
    return null;
}
Also used : ConsulClient(com.ecwid.consul.v1.ConsulClient) ConfigData(org.springframework.boot.context.config.ConfigData) ArrayList(java.util.ArrayList) ConfigDataResourceNotFoundException(org.springframework.boot.context.config.ConfigDataResourceNotFoundException) Option(org.springframework.boot.context.config.ConfigData.Option) ConfigDataResourceNotFoundException(org.springframework.boot.context.config.ConfigDataResourceNotFoundException)

Example 5 with ConfigDataResourceNotFoundException

use of org.springframework.boot.context.config.ConfigDataResourceNotFoundException in project spring-cloud-aws by awspring.

the class SecretsManagerConfigDataLoader method load.

@Override
@Nullable
public ConfigData load(ConfigDataLoaderContext context, SecretsManagerConfigDataResource resource) {
    try {
        SecretsManagerClient sm = context.getBootstrapContext().get(SecretsManagerClient.class);
        SecretsManagerPropertySource propertySource = resource.getPropertySources().createPropertySource(resource.getContext(), resource.isOptional(), sm);
        if (propertySource != null) {
            return new ConfigData(Collections.singletonList(propertySource));
        } else {
            return null;
        }
    } catch (Exception e) {
        throw new ConfigDataResourceNotFoundException(resource, e);
    }
}
Also used : ConfigData(org.springframework.boot.context.config.ConfigData) SecretsManagerPropertySource(io.awspring.cloud.secretsmanager.SecretsManagerPropertySource) ConfigDataResourceNotFoundException(org.springframework.boot.context.config.ConfigDataResourceNotFoundException) SecretsManagerClient(software.amazon.awssdk.services.secretsmanager.SecretsManagerClient) ConfigDataResourceNotFoundException(org.springframework.boot.context.config.ConfigDataResourceNotFoundException) Nullable(org.springframework.lang.Nullable)

Aggregations

ConfigData (org.springframework.boot.context.config.ConfigData)6 ConfigDataResourceNotFoundException (org.springframework.boot.context.config.ConfigDataResourceNotFoundException)6 ArrayList (java.util.ArrayList)2 Nullable (org.springframework.lang.Nullable)2 AWSSecretsManager (com.amazonaws.services.secretsmanager.AWSSecretsManager)1 AWSSimpleSystemsManagement (com.amazonaws.services.simplesystemsmanagement.AWSSimpleSystemsManagement)1 ConsulClient (com.ecwid.consul.v1.ConsulClient)1 ParameterStorePropertySource (io.awspring.cloud.parameterstore.ParameterStorePropertySource)1 AwsParamStorePropertySource (io.awspring.cloud.paramstore.AwsParamStorePropertySource)1 AwsSecretsManagerPropertySource (io.awspring.cloud.secretsmanager.AwsSecretsManagerPropertySource)1 SecretsManagerPropertySource (io.awspring.cloud.secretsmanager.SecretsManagerPropertySource)1 CuratorFramework (org.apache.curator.framework.CuratorFramework)1 Option (org.springframework.boot.context.config.ConfigData.Option)1 SecretsManagerClient (software.amazon.awssdk.services.secretsmanager.SecretsManagerClient)1 SsmClient (software.amazon.awssdk.services.ssm.SsmClient)1