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);
}
}
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;
}
Aggregations