Search in sources :

Example 1 with DescribeSecretResponse

use of software.amazon.awssdk.services.secretsmanager.model.DescribeSecretResponse in project aws-greengrass-provisioner by awslabs.

the class BasicSecretsManagerHelper method getSecretNameFromArn.

@Override
public String getSecretNameFromArn(String arn) {
    DescribeSecretResponse describeSecretResponse = getDescribeSecretResponse(arn);
    throwExceptionOnSecretDeleted(describeSecretResponse);
    return describeSecretResponse.name();
}
Also used : DescribeSecretResponse(software.amazon.awssdk.services.secretsmanager.model.DescribeSecretResponse)

Example 2 with DescribeSecretResponse

use of software.amazon.awssdk.services.secretsmanager.model.DescribeSecretResponse in project aws-greengrass-provisioner by awslabs.

the class BasicSecretsManagerHelper method getSecretArnFromName.

@Override
public String getSecretArnFromName(String name) {
    DescribeSecretResponse describeSecretResponse = getDescribeSecretResponse(name);
    throwExceptionOnSecretDeleted(describeSecretResponse);
    return describeSecretResponse.arn();
}
Also used : DescribeSecretResponse(software.amazon.awssdk.services.secretsmanager.model.DescribeSecretResponse)

Example 3 with DescribeSecretResponse

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

the class AwsSecretsManagerTest method updateIfDifferentSecretTag.

private void updateIfDifferentSecretTag(final String secretName, final Tag newTag) {
    final DescribeSecretResponse describeSecretResponse = testSecretsManagerClient.describeSecret(DescribeSecretRequest.builder().secretId(secretName).build());
    final boolean hasDifferentSecretTag = !describeSecretResponse.hasTags() || !describeSecretResponse.tags().equals(List.of(newTag));
    if (hasDifferentSecretTag) {
        testSecretsManagerClient.untagResource(UntagResourceRequest.builder().secretId(secretName).tagKeys(describeSecretResponse.tags().stream().map(Tag::key).collect(Collectors.toList())).build());
        testSecretsManagerClient.tagResource(TagResourceRequest.builder().secretId(secretName).tags(newTag).build());
    }
}
Also used : Tag(software.amazon.awssdk.services.secretsmanager.model.Tag) DescribeSecretResponse(software.amazon.awssdk.services.secretsmanager.model.DescribeSecretResponse)

Example 4 with DescribeSecretResponse

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

the class DescribeSecret method describeGivenSecret.

// snippet-start:[secretsmanager.java2.describe_secret.main]
public static void describeGivenSecret(SecretsManagerClient secretsClient, String secretName) {
    try {
        DescribeSecretRequest secretRequest = DescribeSecretRequest.builder().secretId(secretName).build();
        DescribeSecretResponse secretResponse = secretsClient.describeSecret(secretRequest);
        Instant lastChangedDate = secretResponse.lastChangedDate();
        // Convert the Instant to readable date
        DateTimeFormatter formatter = DateTimeFormatter.ofLocalizedDateTime(FormatStyle.SHORT).withLocale(Locale.US).withZone(ZoneId.systemDefault());
        formatter.format(lastChangedDate);
        System.out.println("The date of the last change to " + secretResponse.name() + " is " + lastChangedDate);
    } catch (SecretsManagerException e) {
        System.err.println(e.awsErrorDetails().errorMessage());
        System.exit(1);
    }
}
Also used : SecretsManagerException(software.amazon.awssdk.services.secretsmanager.model.SecretsManagerException) Instant(java.time.Instant) DescribeSecretRequest(software.amazon.awssdk.services.secretsmanager.model.DescribeSecretRequest) DateTimeFormatter(java.time.format.DateTimeFormatter) DescribeSecretResponse(software.amazon.awssdk.services.secretsmanager.model.DescribeSecretResponse)

Aggregations

DescribeSecretResponse (software.amazon.awssdk.services.secretsmanager.model.DescribeSecretResponse)4 Instant (java.time.Instant)1 DateTimeFormatter (java.time.format.DateTimeFormatter)1 DescribeSecretRequest (software.amazon.awssdk.services.secretsmanager.model.DescribeSecretRequest)1 SecretsManagerException (software.amazon.awssdk.services.secretsmanager.model.SecretsManagerException)1 Tag (software.amazon.awssdk.services.secretsmanager.model.Tag)1