Search in sources :

Example 16 with GetSecretValueResponse

use of software.amazon.awssdk.services.secretsmanager.model.GetSecretValueResponse in project aws-iot-greengrass-edge-connector-for-kinesis-video-stream by awslabs.

the class SecretsClientTest method getSecretValue_validSecretId_returnsSecretValue.

@Test
public void getSecretValue_validSecretId_returnsSecretValue() {
    GetSecretValueResponse secretValueResponse = GetSecretValueResponse.builder().secretString(SECRET_VALUE).build();
    when(secretsManagerClient.getSecretValue((GetSecretValueRequest) any())).thenReturn(secretValueResponse);
    String response = secretsClient.getSecretValue(SECRET_ID);
    assertEquals(response, SECRET_VALUE);
}
Also used : GetSecretValueResponse(software.amazon.awssdk.services.secretsmanager.model.GetSecretValueResponse) Test(org.junit.jupiter.api.Test)

Example 17 with GetSecretValueResponse

use of software.amazon.awssdk.services.secretsmanager.model.GetSecretValueResponse in project secrets-manager by bancolombia.

the class AWSSecretManagerConnectorTest method prepareClient.

private void prepareClient(String data) {
    SecretsManagerClientBuilder clientBuilderMock = Mockito.mock(SecretsManagerClientBuilder.class);
    SecretsManagerClient clientMock = Mockito.mock(SecretsManagerClient.class);
    GetSecretValueResponse responseMock = GetSecretValueResponse.builder().secretString(data).build();
    PowerMockito.mockStatic(SecretsManagerClient.class);
    when(SecretsManagerClient.builder()).thenReturn(clientBuilderMock);
    when(clientBuilderMock.credentialsProvider(any())).thenReturn(clientBuilderMock);
    when(clientBuilderMock.region(any())).thenReturn(clientBuilderMock);
    when(clientBuilderMock.build()).thenReturn(clientMock);
    when(clientMock.getSecretValue(any(GetSecretValueRequest.class))).thenReturn(responseMock);
}
Also used : SecretsManagerClientBuilder(software.amazon.awssdk.services.secretsmanager.SecretsManagerClientBuilder) GetSecretValueRequest(software.amazon.awssdk.services.secretsmanager.model.GetSecretValueRequest) GetSecretValueResponse(software.amazon.awssdk.services.secretsmanager.model.GetSecretValueResponse) SecretsManagerClient(software.amazon.awssdk.services.secretsmanager.SecretsManagerClient)

Example 18 with GetSecretValueResponse

use of software.amazon.awssdk.services.secretsmanager.model.GetSecretValueResponse in project aws-lambda-powertools-java by awslabs.

the class SecretsProviderTest method getValueBase64.

@Test
public void getValueBase64() {
    String key = "Key2";
    String expectedValue = "Value2";
    byte[] valueb64 = Base64.getEncoder().encode(expectedValue.getBytes());
    GetSecretValueResponse response = GetSecretValueResponse.builder().secretBinary(SdkBytes.fromByteArray(valueb64)).build();
    Mockito.when(client.getSecretValue(paramCaptor.capture())).thenReturn(response);
    String value = provider.getValue(key);
    assertThat(value).isEqualTo(expectedValue);
    assertThat(paramCaptor.getValue().secretId()).isEqualTo(key);
}
Also used : GetSecretValueResponse(software.amazon.awssdk.services.secretsmanager.model.GetSecretValueResponse) Test(org.junit.jupiter.api.Test)

Example 19 with GetSecretValueResponse

use of software.amazon.awssdk.services.secretsmanager.model.GetSecretValueResponse in project signers by ConsenSys.

the class AwsSecretsManager method fetchSecret.

public Optional<String> fetchSecret(final String secretName) {
    try {
        final GetSecretValueRequest getSecretValueRequest = GetSecretValueRequest.builder().secretId(secretName).build();
        final GetSecretValueResponse valueResponse = secretsManagerClient.getSecretValue(getSecretValueRequest);
        return Optional.of(valueResponse.secretString());
    } catch (final ResourceNotFoundException e) {
        return Optional.empty();
    } catch (final SecretsManagerException e) {
        throw new RuntimeException("Failed to fetch secret from AWS Secrets Manager.", e);
    }
}
Also used : SecretsManagerException(software.amazon.awssdk.services.secretsmanager.model.SecretsManagerException) GetSecretValueRequest(software.amazon.awssdk.services.secretsmanager.model.GetSecretValueRequest) GetSecretValueResponse(software.amazon.awssdk.services.secretsmanager.model.GetSecretValueResponse) ResourceNotFoundException(software.amazon.awssdk.services.secretsmanager.model.ResourceNotFoundException)

Example 20 with GetSecretValueResponse

use of software.amazon.awssdk.services.secretsmanager.model.GetSecretValueResponse in project tessera by ConsenSys.

the class AWSKeyVaultServiceTest method getSecretSecretManagerRerurnsNull.

@Test
public void getSecretSecretManagerRerurnsNull() {
    String secretName = "name";
    Map<String, String> getSecretData = Map.of(AWSKeyVaultService.SECRET_NAME_KEY, secretName);
    GetSecretValueResponse secretValueResponse = null;
    when(secretsManager.getSecretValue(any(GetSecretValueRequest.class))).thenReturn(secretValueResponse);
    try {
        keyVaultService.getSecret(getSecretData);
        failBecauseExceptionWasNotThrown(VaultSecretNotFoundException.class);
    } catch (VaultSecretNotFoundException vaultSecretNotFoundException) {
        verify(secretsManager).getSecretValue(any(GetSecretValueRequest.class));
        assertThat(vaultSecretNotFoundException).hasMessage("The requested secret '" + secretName + "' was not found in AWS Secrets Manager");
    }
}
Also used : GetSecretValueRequest(software.amazon.awssdk.services.secretsmanager.model.GetSecretValueRequest) VaultSecretNotFoundException(com.quorum.tessera.key.vault.VaultSecretNotFoundException) GetSecretValueResponse(software.amazon.awssdk.services.secretsmanager.model.GetSecretValueResponse) Test(org.junit.Test)

Aggregations

GetSecretValueResponse (software.amazon.awssdk.services.secretsmanager.model.GetSecretValueResponse)21 GetSecretValueRequest (software.amazon.awssdk.services.secretsmanager.model.GetSecretValueRequest)15 Test (org.junit.jupiter.api.Test)6 SecretsManagerException (software.amazon.awssdk.services.secretsmanager.model.SecretsManagerException)4 VaultSecretNotFoundException (com.quorum.tessera.key.vault.VaultSecretNotFoundException)2 Test (org.junit.Test)2 SecretsManagerClient (software.amazon.awssdk.services.secretsmanager.SecretsManagerClient)2 ResourceNotFoundException (software.amazon.awssdk.services.secretsmanager.model.ResourceNotFoundException)2 SecretException (co.com.bancolombia.secretsmanager.api.exceptions.SecretException)1 EdgeConnectorForKVSException (com.aws.iot.edgeconnectorforkvs.model.exceptions.EdgeConnectorForKVSException)1 JsonParseException (com.fasterxml.jackson.core.JsonParseException)1 JsonProcessingException (com.fasterxml.jackson.core.JsonProcessingException)1 ObjectMapper (com.fasterxml.jackson.databind.ObjectMapper)1 LinkedHashMap (java.util.LinkedHashMap)1 Map (java.util.Map)1 RetryPolicy (net.jodah.failsafe.RetryPolicy)1 SdkClientException (software.amazon.awssdk.core.exception.SdkClientException)1 SecretsManagerClientBuilder (software.amazon.awssdk.services.secretsmanager.SecretsManagerClientBuilder)1 InvalidParameterException (software.amazon.awssdk.services.secretsmanager.model.InvalidParameterException)1 InvalidRequestException (software.amazon.awssdk.services.secretsmanager.model.InvalidRequestException)1