Search in sources :

Example 6 with PutSecretValueRequest

use of com.amazonaws.services.secretsmanager.model.PutSecretValueRequest in project fernet-java8 by l0s.

the class SecretsManagerTest method verifyPutSecretValueStoresKeys.

@Test
public final void verifyPutSecretValueStoresKeys() throws IOException {
    // given
    final String expected = "expected";
    final Key key0 = mock(Key.class);
    final Key key1 = mock(Key.class);
    final Answer<?> answer = new Answer<Void>() {

        public Void answer(final InvocationOnMock invocation) throws Throwable {
            final OutputStream stream = invocation.getArgument(0);
            stream.write(expected.getBytes("UTF-8"));
            return null;
        }
    };
    doAnswer(answer).when(key0).writeTo(any(OutputStream.class));
    doAnswer(answer).when(key1).writeTo(any(OutputStream.class));
    // when
    manager.putSecretValue("secret", "version", asList(key0, key1), PREVIOUS);
    // then
    final PutSecretValueRequest request = new PutSecretValueRequest();
    request.setSecretId("secret");
    request.setClientRequestToken("version");
    request.setVersionStages(singleton("AWSPREVIOUS"));
    request.setSecretBinary(ByteBuffer.wrap((expected + expected).getBytes("UTF-8")));
    verify(delegate).putSecretValue(eq(request));
}
Also used : Answer(org.mockito.stubbing.Answer) Mockito.doAnswer(org.mockito.Mockito.doAnswer) PutSecretValueRequest(com.amazonaws.services.secretsmanager.model.PutSecretValueRequest) InvocationOnMock(org.mockito.invocation.InvocationOnMock) OutputStream(java.io.OutputStream) Key(com.macasaet.fernet.Key) Test(org.junit.Test)

Example 7 with PutSecretValueRequest

use of com.amazonaws.services.secretsmanager.model.PutSecretValueRequest in project fernet-java8 by l0s.

the class MemoryOverwritingRequestHandler method afterError.

public void afterError(final Request<?> request, final Response<?> response, final Exception exception) {
    final Object requestObject = request.getOriginalRequestObject();
    if (requestObject instanceof PutSecretValueRequest) {
        final PutSecretValueRequest putRequest = (PutSecretValueRequest) requestObject;
        overwriteSecret(putRequest);
    }
}
Also used : PutSecretValueRequest(com.amazonaws.services.secretsmanager.model.PutSecretValueRequest)

Example 8 with PutSecretValueRequest

use of com.amazonaws.services.secretsmanager.model.PutSecretValueRequest in project JAQU-CAZ-Payments-API by InformedSolutions.

the class SecretsManagerInitialisation method createSecret.

@SneakyThrows
public void createSecret(String secretName, String apiKey, String... cleanAirZoneId) {
    Map<String, String> apiKeysMap = Arrays.asList(cleanAirZoneId).stream().map(cazId -> cazId.replace("-", "")).collect(Collectors.toMap(Function.identity(), string -> apiKey));
    String secretString = objectMapper.writeValueAsString(apiKeysMap);
    try {
        CreateSecretRequest createSecretRequest = new CreateSecretRequest().withName(secretName).withSecretString(secretString);
        secretsManager.createSecret(createSecretRequest);
    } catch (ResourceExistsException e) {
        PutSecretValueRequest putSecretValueRequest = new PutSecretValueRequest();
        putSecretValueRequest.withSecretId(secretName).withSecretString(secretString);
        secretsManager.putSecretValue(putSecretValueRequest);
    }
}
Also used : Arrays(java.util.Arrays) Component(org.springframework.stereotype.Component) SneakyThrows(lombok.SneakyThrows) CreateSecretRequest(com.amazonaws.services.secretsmanager.model.CreateSecretRequest) PutSecretValueRequest(com.amazonaws.services.secretsmanager.model.PutSecretValueRequest) Map(java.util.Map) ObjectMapper(com.fasterxml.jackson.databind.ObjectMapper) AWSSecretsManager(com.amazonaws.services.secretsmanager.AWSSecretsManager) ResourceExistsException(com.amazonaws.services.secretsmanager.model.ResourceExistsException) AllArgsConstructor(lombok.AllArgsConstructor) Function(java.util.function.Function) Collectors(java.util.stream.Collectors) PutSecretValueRequest(com.amazonaws.services.secretsmanager.model.PutSecretValueRequest) ResourceExistsException(com.amazonaws.services.secretsmanager.model.ResourceExistsException) CreateSecretRequest(com.amazonaws.services.secretsmanager.model.CreateSecretRequest) SneakyThrows(lombok.SneakyThrows)

Aggregations

PutSecretValueRequest (com.amazonaws.services.secretsmanager.model.PutSecretValueRequest)8 Test (org.junit.Test)4 Key (com.macasaet.fernet.Key)3 ByteBuffer (java.nio.ByteBuffer)3 DefaultRequest (com.amazonaws.DefaultRequest)2 Response (com.amazonaws.Response)2 HttpResponse (com.amazonaws.http.HttpResponse)2 PutSecretValueResult (com.amazonaws.services.secretsmanager.model.PutSecretValueResult)2 OutputStream (java.io.OutputStream)2 Mockito.doAnswer (org.mockito.Mockito.doAnswer)2 InvocationOnMock (org.mockito.invocation.InvocationOnMock)2 Answer (org.mockito.stubbing.Answer)2 AWSSecretsManager (com.amazonaws.services.secretsmanager.AWSSecretsManager)1 CreateSecretRequest (com.amazonaws.services.secretsmanager.model.CreateSecretRequest)1 ResourceExistsException (com.amazonaws.services.secretsmanager.model.ResourceExistsException)1 ObjectMapper (com.fasterxml.jackson.databind.ObjectMapper)1 ByteArrayOutputStream (java.io.ByteArrayOutputStream)1 IOException (java.io.IOException)1 Arrays (java.util.Arrays)1 Map (java.util.Map)1