use of com.amazonaws.services.secretsmanager.model.ResourceNotFoundException in project spring-cloud-config by spring-cloud.
the class AwsSecretsManagerEnvironmentRepository method findProperties.
private Map<Object, Object> findProperties(String path) {
Map<Object, Object> properties = new HashMap<>();
GetSecretValueRequest request = new GetSecretValueRequest().withSecretId(path);
try {
GetSecretValueResult response = awsSmClient.getSecretValue(request);
if (response != null) {
Map<String, Object> secretMap = objectMapper.readValue(response.getSecretString(), new TypeReference<Map<String, Object>>() {
});
for (Map.Entry<String, Object> secretEntry : secretMap.entrySet()) {
properties.put(secretEntry.getKey(), secretEntry.getValue());
}
}
} catch (ResourceNotFoundException | IOException e) {
log.debug(String.format("Skip adding propertySource. Unable to load secrets from AWS Secrets Manager for secretId=%s", path), e);
}
return properties;
}
use of com.amazonaws.services.secretsmanager.model.ResourceNotFoundException in project fernet-java8 by l0s.
the class MultiFernetKeyRotatorTest method verifyCreateSecretAddsKeyAndRemovesOldest.
@Test
public final void verifyCreateSecretAddsKeyAndRemovesOldest() throws IOException {
// given
final Key key0 = Key.generateKey(random);
final Key key1 = Key.generateKey(random);
final Key key2 = Key.generateKey(random);
final DescribeSecretResult description = new DescribeSecretResult();
description.setRotationEnabled(true);
description.setVersionIdsToStages(ImmutableMap.of("version", Arrays.asList("AWSPENDING")));
final InputStream input = new StringInputStream("{\"Step\": \"createSecret\",\"ClientRequestToken\": \"version\",\"SecretId\":\"secret\"}");
final ByteArrayOutputStream output = new ByteArrayOutputStream();
final Context context = mock(Context.class);
try (ByteArrayOutputStream stream = new ByteArrayOutputStream()) {
// pending
key0.writeTo(stream);
// primary
key1.writeTo(stream);
// old key
key2.writeTo(stream);
given(secretsManager.getSecretStage("secret", CURRENT)).willReturn(ByteBuffer.wrap(stream.toByteArray()));
given(secretsManager.describeSecret("secret")).willReturn(description);
given(secretsManager.getSecretVersion("secret", "version")).willThrow(new ResourceNotFoundException(""));
// when
rotator.handleRequest(input, output, context);
// then
verify(secretsManager).putSecretValue(eq("secret"), eq("version"), keyCollector.capture(), eq(PENDING));
final Collection<? extends Key> keys = keyCollector.getValue();
assertEquals(3, keys.size());
// new pending key
assertTrue(keys.contains(key0));
// primary key (old pending)
assertTrue(keys.contains(key1));
// old key (old primary)
assertFalse(keys.contains(key2));
new ObjectMapper().readTree(output.toByteArray());
}
}
use of com.amazonaws.services.secretsmanager.model.ResourceNotFoundException in project fernet-java8 by l0s.
the class MultiFernetKeyRotatorTest method verifyCreateClearsIntermediateSecret.
@Test
public final void verifyCreateClearsIntermediateSecret() throws IOException {
// given
final byte[] secretBytes = new byte[32];
random.nextBytes(secretBytes);
final int originalHashCode = Arrays.hashCode(secretBytes);
final ByteBuffer secretByteBuffer = ByteBuffer.wrap(secretBytes);
assertTrue(Arrays.equals(secretByteBuffer.array(), secretBytes));
final DescribeSecretResult description = new DescribeSecretResult();
description.setRotationEnabled(true);
description.setVersionIdsToStages(ImmutableMap.of("clientRequestToken", Arrays.asList("AWSPENDING")));
given(secretsManager.getSecretStage("secretId", CURRENT)).willReturn(secretByteBuffer);
given(secretsManager.describeSecret("secretId")).willReturn(description);
given(secretsManager.getSecretVersion("secretId", "clientRequestToken")).willThrow(new ResourceNotFoundException(""));
final InputStream input = new StringInputStream("{\"Step\": \"createSecret\",\"ClientRequestToken\": \"clientRequestToken\",\"SecretId\":\"secretId\"}");
final ByteArrayOutputStream output = new ByteArrayOutputStream();
final Context context = mock(Context.class);
// when
rotator.handleRequest(input, output, context);
// then
final byte[] modifiedBytes = secretByteBuffer.array();
assertEquals(32, modifiedBytes.length);
assertNotEquals(originalHashCode, Arrays.hashCode(secretBytes));
new ObjectMapper().readTree(output.toByteArray());
}
use of com.amazonaws.services.secretsmanager.model.ResourceNotFoundException in project fernet-java8 by l0s.
the class SecretsManagerTest method verifyAssertCurrentStageExistsThrowsException.
@Test
public final void verifyAssertCurrentStageExistsThrowsException() {
// given
final GetSecretValueRequest request = new GetSecretValueRequest();
request.setSecretId("secret");
request.setVersionStage("AWSCURRENT");
given(delegate.getSecretValue(eq(request))).willThrow(new ResourceNotFoundException("not found"));
// when / then (exception thrown)
assertThrows(ResourceNotFoundException.class, () -> manager.assertCurrentStageExists("secret"));
}
use of com.amazonaws.services.secretsmanager.model.ResourceNotFoundException in project spring-cloud-aws by awspring.
the class AwsSecretsManagerPropertySourceTest method throwsExceptionWhenSecretNotFound.
@Test
void throwsExceptionWhenSecretNotFound() {
when(client.getSecretValue(any(GetSecretValueRequest.class))).thenThrow(new ResourceNotFoundException("secret not found"));
assertThatThrownBy(() -> propertySource.init()).isInstanceOf(ResourceNotFoundException.class);
}
Aggregations