Search in sources :

Example 1 with ResourceNotFoundException

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);
    }
}
Also used : Secret(io.datarouter.secret.client.Secret) GetSecretValueResult(com.amazonaws.services.secretsmanager.model.GetSecretValueResult) GetSecretValueRequest(com.amazonaws.services.secretsmanager.model.GetSecretValueRequest) ResourceNotFoundException(com.amazonaws.services.secretsmanager.model.ResourceNotFoundException) SecretNotFoundException(io.datarouter.secret.exception.SecretNotFoundException)

Example 2 with ResourceNotFoundException

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);
    }
}
Also used : ResourceExistsException(com.amazonaws.services.secretsmanager.model.ResourceExistsException) ResourceNotFoundException(com.amazonaws.services.secretsmanager.model.ResourceNotFoundException) SecretNotFoundException(io.datarouter.secret.exception.SecretNotFoundException) SecretExistsException(io.datarouter.secret.exception.SecretExistsException) UpdateSecretRequest(com.amazonaws.services.secretsmanager.model.UpdateSecretRequest)

Example 3 with ResourceNotFoundException

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);
    }
}
Also used : ResourceNotFoundException(com.amazonaws.services.secretsmanager.model.ResourceNotFoundException) SecretNotFoundException(io.datarouter.secret.exception.SecretNotFoundException) DeleteSecretRequest(com.amazonaws.services.secretsmanager.model.DeleteSecretRequest)

Example 4 with ResourceNotFoundException

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");
}
Also used : ResourceNotFoundException(com.amazonaws.services.secretsmanager.model.ResourceNotFoundException) Test(org.junit.Test)

Example 5 with ResourceNotFoundException

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));
        }
    }
}
Also used : Context(com.amazonaws.services.lambda.runtime.Context) DescribeSecretResult(com.amazonaws.services.secretsmanager.model.DescribeSecretResult) ByteArrayInputStream(java.io.ByteArrayInputStream) ByteArrayInputStream(java.io.ByteArrayInputStream) InputStream(java.io.InputStream) ByteArrayOutputStream(java.io.ByteArrayOutputStream) OutputStream(java.io.OutputStream) ByteArrayOutputStream(java.io.ByteArrayOutputStream) ResourceNotFoundException(com.amazonaws.services.secretsmanager.model.ResourceNotFoundException) Key(com.macasaet.fernet.Key) Test(org.junit.Test)

Aggregations

ResourceNotFoundException (com.amazonaws.services.secretsmanager.model.ResourceNotFoundException)10 Test (org.junit.Test)5 GetSecretValueRequest (com.amazonaws.services.secretsmanager.model.GetSecretValueRequest)4 Context (com.amazonaws.services.lambda.runtime.Context)3 DescribeSecretResult (com.amazonaws.services.secretsmanager.model.DescribeSecretResult)3 SecretNotFoundException (io.datarouter.secret.exception.SecretNotFoundException)3 ByteArrayOutputStream (java.io.ByteArrayOutputStream)3 InputStream (java.io.InputStream)3 GetSecretValueResult (com.amazonaws.services.secretsmanager.model.GetSecretValueResult)2 StringInputStream (com.amazonaws.util.StringInputStream)2 ObjectMapper (com.fasterxml.jackson.databind.ObjectMapper)2 Key (com.macasaet.fernet.Key)2 DeleteSecretRequest (com.amazonaws.services.secretsmanager.model.DeleteSecretRequest)1 ResourceExistsException (com.amazonaws.services.secretsmanager.model.ResourceExistsException)1 UpdateSecretRequest (com.amazonaws.services.secretsmanager.model.UpdateSecretRequest)1 Secret (io.datarouter.secret.client.Secret)1 SecretExistsException (io.datarouter.secret.exception.SecretExistsException)1 ByteArrayInputStream (java.io.ByteArrayInputStream)1 IOException (java.io.IOException)1 OutputStream (java.io.OutputStream)1