Search in sources :

Example 1 with ParameterStorePropertySource

use of io.awspring.cloud.parameterstore.ParameterStorePropertySource 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 2 with ParameterStorePropertySource

use of io.awspring.cloud.parameterstore.ParameterStorePropertySource in project spring-cloud-aws by awspring.

the class ParameterStorePropertySources method createPropertySource.

/**
 * Creates property source for given context.
 * @param context property source context equivalent to the parameter name
 * @param optional if creating context should fail with exception if parameter cannot be loaded
 * @param client System Manager Management client
 * @return a property source or null if parameter could not be loaded and optional is set to true
 */
@Nullable
public ParameterStorePropertySource createPropertySource(String context, boolean optional, SsmClient client) {
    Assert.notNull(context, "context is required");
    Assert.notNull(client, "SsmClient is required");
    LOG.info("Loading property from AWS Parameter Store with name: " + context + ", optional: " + optional);
    try {
        ParameterStorePropertySource propertySource = new ParameterStorePropertySource(context, client);
        propertySource.init();
        return propertySource;
    // TODO: howto call close when /refresh
    } catch (Exception e) {
        if (!optional) {
            throw new AwsParameterPropertySourceNotFoundException(e);
        } else {
            LOG.warn("Unable to load AWS parameter from " + context + ". " + e.getMessage());
        }
    }
    return null;
}
Also used : ParameterStorePropertySource(io.awspring.cloud.parameterstore.ParameterStorePropertySource) Nullable(org.springframework.lang.Nullable)

Aggregations

ParameterStorePropertySource (io.awspring.cloud.parameterstore.ParameterStorePropertySource)2 Nullable (org.springframework.lang.Nullable)2 ConfigData (org.springframework.boot.context.config.ConfigData)1 ConfigDataResourceNotFoundException (org.springframework.boot.context.config.ConfigDataResourceNotFoundException)1 SsmClient (software.amazon.awssdk.services.ssm.SsmClient)1