Search in sources :

Example 1 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 SecretsClient method getSecretValue.

/**
 * Wrapper for getSecretValue function in SecretsManagerClient.
 * @param secretId - secretArn for the secret
 * @return secret value as String
 * @throws EdgeConnectorForKVSException - Wrapper to all exception thrown by SecretsManagerClient
 */
public String getSecretValue(@NonNull String secretId) throws EdgeConnectorForKVSException {
    try {
        log.info("Retrieving Secret Value for " + secretId);
        GetSecretValueRequest secretValueRequest = GetSecretValueRequest.builder().secretId(secretId).versionStage(VERSION_STAGE).build();
        GetSecretValueResponse secretValueResponse = this.secretsManagerClient.getSecretValue(secretValueRequest);
        return secretValueResponse.secretString();
    } catch (Exception e) {
        final String errorMessage = String.format("Could not getSecretValue for secretId: %s", secretId);
        log.error(errorMessage);
        throw new EdgeConnectorForKVSException(errorMessage, e);
    }
}
Also used : EdgeConnectorForKVSException(com.aws.iot.edgeconnectorforkvs.model.exceptions.EdgeConnectorForKVSException) GetSecretValueRequest(software.amazon.awssdk.services.secretsmanager.model.GetSecretValueRequest) GetSecretValueResponse(software.amazon.awssdk.services.secretsmanager.model.GetSecretValueResponse) EdgeConnectorForKVSException(com.aws.iot.edgeconnectorforkvs.model.exceptions.EdgeConnectorForKVSException)

Example 2 with GetSecretValueResponse

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

the class AWSSecretManagerConnector method getSecret.

private String getSecret(String secretName, SecretsManagerClient client) throws SecretException {
    GetSecretValueRequest getSecretValueRequest = GetSecretValueRequest.builder().secretId(secretName).build();
    GetSecretValueResponse getSecretValueResult = client.getSecretValue(getSecretValueRequest);
    if (getSecretValueResult == null) {
        throw new SecretException("Secret value is null");
    } else {
        if (getSecretValueResult.secretString() != null) {
            return getSecretValueResult.secretString();
        }
        throw new SecretException("Secret value is not a String");
    }
}
Also used : SecretException(co.com.bancolombia.secretsmanager.api.exceptions.SecretException) GetSecretValueRequest(software.amazon.awssdk.services.secretsmanager.model.GetSecretValueRequest) GetSecretValueResponse(software.amazon.awssdk.services.secretsmanager.model.GetSecretValueResponse)

Example 3 with GetSecretValueResponse

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

the class ParamManagerIntegrationTest method secretsProvider_get.

@Test
public void secretsProvider_get() {
    SecretsProvider secretsProvider = ParamManager.getSecretsProvider(secretsManagerClient);
    String expectedValue = "Value1";
    GetSecretValueResponse response = GetSecretValueResponse.builder().secretString(expectedValue).build();
    when(secretsManagerClient.getSecretValue(secretsCaptor.capture())).thenReturn(response);
    assertThat(secretsProvider.get("keys")).isEqualTo(expectedValue);
    assertThat(secretsCaptor.getValue().secretId()).isEqualTo("keys");
    // second time is from cache
    assertThat(secretsProvider.get("keys")).isEqualTo(expectedValue);
    verify(secretsManagerClient, times(1)).getSecretValue(any(GetSecretValueRequest.class));
}
Also used : GetSecretValueRequest(software.amazon.awssdk.services.secretsmanager.model.GetSecretValueRequest) GetSecretValueResponse(software.amazon.awssdk.services.secretsmanager.model.GetSecretValueResponse) Test(org.junit.jupiter.api.Test)

Example 4 with GetSecretValueResponse

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

the class SecretsProviderTest method getValue.

@Test
public void getValue() {
    String key = "Key1";
    String expectedValue = "Value1";
    GetSecretValueResponse response = GetSecretValueResponse.builder().secretString(expectedValue).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 5 with GetSecretValueResponse

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

the class AwsSecretsManagerTest method updateIfDifferentSecretValue.

private void updateIfDifferentSecretValue(final String secretName, final String secretValue) {
    final GetSecretValueResponse getSecretValueResponse = testSecretsManagerClient.getSecretValue(GetSecretValueRequest.builder().secretId(secretName).build());
    final boolean hasDifferentSecretValue = !getSecretValueResponse.secretString().equals(secretValue);
    if (hasDifferentSecretValue) {
        testSecretsManagerClient.updateSecret(UpdateSecretRequest.builder().secretId(secretName).secretString(secretValue).build());
    }
}
Also used : GetSecretValueResponse(software.amazon.awssdk.services.secretsmanager.model.GetSecretValueResponse)

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