use of io.awspring.cloud.secretsmanager.SecretsManagerPropertySource 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);
}
}
use of io.awspring.cloud.secretsmanager.SecretsManagerPropertySource in project spring-cloud-aws by awspring.
the class SecretsManagerPropertySources method createPropertySource.
/**
* Creates property source for given context.
* @param context property source context equivalent to the secret name
* @param optional if creating context should fail with exception if secret cannot be loaded
* @param client Secret Manager client
* @return a property source or null if secret could not be loaded and optional is set to true
*/
@Nullable
public SecretsManagerPropertySource createPropertySource(String context, boolean optional, SecretsManagerClient client) {
Assert.notNull(context, "context is required");
Assert.notNull(client, "SecretsManagerClient is required");
LOG.info("Loading secrets from AWS Secret Manager secret with name: " + context + ", optional: " + optional);
try {
SecretsManagerPropertySource propertySource = new SecretsManagerPropertySource(context, client);
propertySource.init();
return propertySource;
// TODO: howto call close when /refresh
} catch (Exception e) {
if (!optional) {
throw new AwsSecretsManagerPropertySourceNotFoundException(e);
} else {
LOG.warn("Unable to load AWS secret from " + context + ". " + e.getMessage());
}
}
return null;
}
Aggregations