Search in sources :

Example 6 with SecretsManagerException

use of software.amazon.awssdk.services.secretsmanager.model.SecretsManagerException in project cu-kfs by CU-CommunityApps.

the class AwsSecretServiceImpl method updateSecretValue.

@Override
public void updateSecretValue(String awsKeyName, boolean useKfsInstanceNamespace, String keyValue) {
    createCacheIfNotPresent();
    String fullAwsKey = buildFullAwsKeyName(awsKeyName, useKfsInstanceNamespace);
    UpdateSecretRequest updateSecretRequest = UpdateSecretRequest.builder().secretId(fullAwsKey).secretString(keyValue).build();
    SecretsManagerClient client = buildSecretsManagerClient();
    try {
        performUpdate(updateSecretRequest, client);
        updateCacheValue(fullAwsKey, keyValue);
    } catch (SecretsManagerException e) {
        LOG.error("updateSecretValue, had an error setting value for secret " + fullAwsKey, e);
        throw new RuntimeException(e);
    } finally {
        client.close();
    }
}
Also used : SecretsManagerException(software.amazon.awssdk.services.secretsmanager.model.SecretsManagerException) SecretsManagerClient(software.amazon.awssdk.services.secretsmanager.SecretsManagerClient) UpdateSecretRequest(software.amazon.awssdk.services.secretsmanager.model.UpdateSecretRequest)

Example 7 with SecretsManagerException

use of software.amazon.awssdk.services.secretsmanager.model.SecretsManagerException in project cu-kfs by CU-CommunityApps.

the class AwsSecretServiceImpl method retrieveSecretFromAws.

protected String retrieveSecretFromAws(String fullAwsKey) {
    SecretsManagerClient client = buildSecretsManagerClient();
    try {
        GetSecretValueRequest valueRequest = GetSecretValueRequest.builder().secretId(fullAwsKey).build();
        GetSecretValueResponse valueResponse = client.getSecretValue(valueRequest);
        return valueResponse.secretString();
    } catch (SecretsManagerException e) {
        LOG.error("retrieveSecretFromAws, had an error getting value for secret " + fullAwsKey, e);
        throw new RuntimeException(e);
    } finally {
        client.close();
    }
}
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) SecretsManagerClient(software.amazon.awssdk.services.secretsmanager.SecretsManagerClient)

Example 8 with SecretsManagerException

use of software.amazon.awssdk.services.secretsmanager.model.SecretsManagerException in project radixdlt by radixdlt.

the class AWSSecretManager method createAWSSecret.

public static void createAWSSecret(final Map<String, Object> awsSecret, final String secretName, final AWSSecretsOutputOptions awsSecretsOutputOptions, boolean compress, boolean binarySecret) {
    ObjectMapper objectMapper = new ObjectMapper();
    try {
        String jsonSecret = objectMapper.writeValueAsString(awsSecret);
        if (compress) {
            byte[] compressedBytes = compressData(jsonSecret);
            createBinarySecret(secretName, SdkBytes.fromByteArray(compressedBytes), awsSecretsOutputOptions.getNetworkName());
        } else {
            if (binarySecret) {
                createBinarySecret(secretName, SdkBytes.fromByteArray((byte[]) awsSecret.get("key")), awsSecretsOutputOptions.getNetworkName());
            } else {
                createSecret(secretName, jsonSecret, awsSecretsOutputOptions.getNetworkName());
            }
        }
    } catch (JsonProcessingException e) {
        System.out.println(e);
    } catch (SecretsManagerException e) {
        System.err.println(e.awsErrorDetails().errorMessage());
        System.exit(1);
    } catch (IOException e) {
        System.out.println(e);
        System.exit(1);
    }
}
Also used : SecretsManagerException(software.amazon.awssdk.services.secretsmanager.model.SecretsManagerException) IOException(java.io.IOException) JsonProcessingException(com.fasterxml.jackson.core.JsonProcessingException) ObjectMapper(com.fasterxml.jackson.databind.ObjectMapper)

Example 9 with SecretsManagerException

use of software.amazon.awssdk.services.secretsmanager.model.SecretsManagerException in project aws-doc-sdk-examples by awsdocs.

the class DeleteSecret method deleteSpecificSecret.

// snippet-start:[secretsmanager.java2.delete_secret.main]
public static void deleteSpecificSecret(SecretsManagerClient secretsClient, String secretName) {
    try {
        DeleteSecretRequest secretRequest = DeleteSecretRequest.builder().secretId(secretName).build();
        secretsClient.deleteSecret(secretRequest);
        System.out.println(secretName + " is deleted.");
    } catch (SecretsManagerException e) {
        System.err.println(e.awsErrorDetails().errorMessage());
        System.exit(1);
    }
}
Also used : SecretsManagerException(software.amazon.awssdk.services.secretsmanager.model.SecretsManagerException) DeleteSecretRequest(software.amazon.awssdk.services.secretsmanager.model.DeleteSecretRequest)

Example 10 with SecretsManagerException

use of software.amazon.awssdk.services.secretsmanager.model.SecretsManagerException in project aws-doc-sdk-examples by awsdocs.

the class ListSecrets method listAllSecrets.

// snippet-start:[secretsmanager.java2.list_secrets.main]
public static void listAllSecrets(SecretsManagerClient secretsClient) {
    try {
        ListSecretsResponse secretsResponse = secretsClient.listSecrets();
        List<SecretListEntry> secrets = secretsResponse.secretList();
        for (SecretListEntry secret : secrets) {
            System.out.println("The secret name is " + secret.name());
            System.out.println("The secret descreiption is " + secret.description());
        }
    } catch (SecretsManagerException e) {
        System.err.println(e.awsErrorDetails().errorMessage());
        System.exit(1);
    }
}
Also used : SecretsManagerException(software.amazon.awssdk.services.secretsmanager.model.SecretsManagerException) ListSecretsResponse(software.amazon.awssdk.services.secretsmanager.model.ListSecretsResponse) SecretListEntry(software.amazon.awssdk.services.secretsmanager.model.SecretListEntry)

Aggregations

SecretsManagerException (software.amazon.awssdk.services.secretsmanager.model.SecretsManagerException)13 GetSecretValueRequest (software.amazon.awssdk.services.secretsmanager.model.GetSecretValueRequest)4 GetSecretValueResponse (software.amazon.awssdk.services.secretsmanager.model.GetSecretValueResponse)4 JsonProcessingException (com.fasterxml.jackson.core.JsonProcessingException)3 ObjectMapper (com.fasterxml.jackson.databind.ObjectMapper)2 IOException (java.io.IOException)2 SecretsManagerClient (software.amazon.awssdk.services.secretsmanager.SecretsManagerClient)2 ListSecretsResponse (software.amazon.awssdk.services.secretsmanager.model.ListSecretsResponse)2 SecretListEntry (software.amazon.awssdk.services.secretsmanager.model.SecretListEntry)2 UpdateSecretRequest (software.amazon.awssdk.services.secretsmanager.model.UpdateSecretRequest)2 NonNull (io.micronaut.core.annotation.NonNull)1 Instant (java.time.Instant)1 DateTimeFormatter (java.time.format.DateTimeFormatter)1 HashMap (java.util.HashMap)1 Map (java.util.Map)1 RetryPolicy (net.jodah.failsafe.RetryPolicy)1 SdkClientException (software.amazon.awssdk.core.exception.SdkClientException)1 CreateSecretRequest (software.amazon.awssdk.services.secretsmanager.model.CreateSecretRequest)1 CreateSecretResponse (software.amazon.awssdk.services.secretsmanager.model.CreateSecretResponse)1 DeleteSecretRequest (software.amazon.awssdk.services.secretsmanager.model.DeleteSecretRequest)1