use of com.amazonaws.services.secretsmanager.model.ResourceNotFoundException in project datarouter by hotpads.
the class AwsSecretClient method read.
@Override
public final Secret read(String name) {
var request = new GetSecretValueRequest().withSecretId(name);
// .withVersionStage("")// related to AWS rotation
try {
GetSecretValueResult result;
try (var $ = TracerTool.startSpan("AWSSecretsManager getSecretValue", TraceSpanGroupType.CLOUD_STORAGE)) {
TracerTool.appendToSpanInfo(name);
result = client.getSecretValue(request);
}
return new Secret(name, result.getSecretString());
} catch (ResourceNotFoundException e) {
throw new SecretNotFoundException(name, e);
}
}
use of com.amazonaws.services.secretsmanager.model.ResourceNotFoundException in project datarouter by hotpads.
the class AwsSecretClient method update.
@Override
public final void update(Secret secret) {
// this can update various stuff (like description and kms key) AND updates the version stage to AWSCURRENT.
// for rotation, use PutSecretValue, which only updates the version stages and value of a secret explicitly
var request = new UpdateSecretRequest().withSecretId(secret.getName()).withSecretString(secret.getValue());
try {
try (var $ = TracerTool.startSpan("AWSSecretsManager updateSecret", TraceSpanGroupType.CLOUD_STORAGE)) {
TracerTool.appendToSpanInfo(secret.getName());
client.updateSecret(request);
}
} catch (ResourceExistsException e) {
throw new SecretExistsException("Requested update already exists.", secret.getName(), e);
} catch (ResourceNotFoundException e) {
throw new SecretNotFoundException(secret.getName(), e);
}
}
use of com.amazonaws.services.secretsmanager.model.ResourceNotFoundException in project datarouter by hotpads.
the class AwsSecretClient method delete.
@Override
public final void delete(String name) {
var request = new DeleteSecretRequest().withSecretId(name);
// .withRecoveryWindowInDays(0L);//7-30 days to undelete. default 30
try {
try (var $ = TracerTool.startSpan("AWSSecretsManager deleteSecret", TraceSpanGroupType.CLOUD_STORAGE)) {
TracerTool.appendToSpanInfo(name);
client.deleteSecret(request);
}
} catch (ResourceNotFoundException e) {
throw new SecretNotFoundException(name, e);
}
}
use of com.amazonaws.services.secretsmanager.model.ResourceNotFoundException in project fernet-java8 by l0s.
the class AbstractFernetKeyRotatorTest method verifyConditionallyCreateCreatesSecret.
@Test
public final void verifyConditionallyCreateCreatesSecret() throws UnsupportedEncodingException {
// given
given(secretsManager.getSecretVersion("secret", "version")).willThrow(new ResourceNotFoundException("not found"));
// when
rotator.conditionallyCreateSecret("secret", "version");
// then
verify(rotator).createSecret("secret", "version");
}
use of com.amazonaws.services.secretsmanager.model.ResourceNotFoundException in project fernet-java8 by l0s.
the class SimpleFernetKeyRotatorTest method verifyHandleRequestCreatesKey.
@Test
public void verifyHandleRequestCreatesKey() throws IOException {
// given
final Context context = mock(Context.class);
final String clientRequestToken = "clientRequestToken";
final String secretId = "secretId";
final DescribeSecretResult secretDescription = new DescribeSecretResult();
secretDescription.setRotationEnabled(true);
secretDescription.addVersionIdsToStagesEntry(clientRequestToken, singletonList("AWSPENDING"));
given(secretsManager.describeSecret(secretId)).willReturn(secretDescription);
given(secretsManager.getSecretVersion(secretId, clientRequestToken)).willThrow(new ResourceNotFoundException("no value yet"));
final RotationRequest creationRequest = new RotationRequest();
creationRequest.setClientRequestToken(clientRequestToken);
creationRequest.setSecretId(secretId);
creationRequest.setStep(Step.CREATE_SECRET);
final byte[] creationRequestBytes = mapper.writeValueAsBytes(creationRequest);
// when
try (InputStream input = new ByteArrayInputStream(creationRequestBytes)) {
try (OutputStream output = new ByteArrayOutputStream()) {
rotator.handleRequest(input, output, context);
// then
verify(secretsManager).putSecretValue(eq("secretId"), eq(clientRequestToken), any(Key.class), eq(PENDING));
}
}
}
Aggregations