Search in sources :

Example 1 with Tag

use of software.amazon.awssdk.services.secretsmanager.model.Tag 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 2 with Tag

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

the class AWSSecretManager method createNewSecret.

private static String createNewSecret(SecretsManagerClient secretsClient, String secretName, Object secretValue, String network, boolean binarySecret) {
    List<Tag> tagList = buildTags(network, secretName);
    CreateSecretRequest secretRequest;
    if (binarySecret) {
        secretRequest = CreateSecretRequest.builder().name(secretName).description("Validator keys").secretBinary((SdkBytes) secretValue).tags(tagList).build();
    } else {
        secretRequest = CreateSecretRequest.builder().name(secretName).description("Validator keys").secretString((String) secretValue).tags(tagList).build();
    }
    CreateSecretResponse secretResponse = secretsClient.createSecret(secretRequest);
    return secretResponse.arn();
}
Also used : SdkBytes(software.amazon.awssdk.core.SdkBytes) CreateSecretRequest(software.amazon.awssdk.services.secretsmanager.model.CreateSecretRequest) Tag(software.amazon.awssdk.services.secretsmanager.model.Tag) CreateSecretResponse(software.amazon.awssdk.services.secretsmanager.model.CreateSecretResponse)

Example 3 with Tag

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

the class AWSSecretManager method buildTags.

private static List<Tag> buildTags(String network, String name) {
    List<Tag> tagList = new ArrayList<>();
    Tag envTypeTag = Tag.builder().key("radixdlt:environment-type").value("development").build();
    Tag teamTag = Tag.builder().key("radixdlt:team").value("devops").build();
    Tag appTag = Tag.builder().key("radixdlt:application").value("validator").build();
    Tag nameTag = Tag.builder().key("radixdlt:name").value(name).build();
    Tag networkTag = Tag.builder().key("radixdlt:network").value(network).build();
    tagList.add(envTypeTag);
    tagList.add(appTag);
    tagList.add(teamTag);
    tagList.add(nameTag);
    tagList.add(networkTag);
    return tagList;
}
Also used : ArrayList(java.util.ArrayList) Tag(software.amazon.awssdk.services.secretsmanager.model.Tag)

Example 4 with Tag

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

the class AwsSecretsManagerTest method createOrUpdateSecret.

private void createOrUpdateSecret(final String testSecretName, final String tagKey, final String tagVal, final String secretValue) {
    final Tag testSecretTag = Tag.builder().key(tagKey).value(tagVal).build();
    try {
        updateIfDifferentSecretValue(testSecretName, secretValue);
        updateIfDifferentSecretTag(testSecretName, testSecretTag);
    } catch (final ResourceNotFoundException e) {
        createTestSecret(testSecretName, testSecretTag, secretValue);
    }
}
Also used : Tag(software.amazon.awssdk.services.secretsmanager.model.Tag) ResourceNotFoundException(software.amazon.awssdk.services.secretsmanager.model.ResourceNotFoundException)

Aggregations

Tag (software.amazon.awssdk.services.secretsmanager.model.Tag)4 ArrayList (java.util.ArrayList)1 SdkBytes (software.amazon.awssdk.core.SdkBytes)1 CreateSecretRequest (software.amazon.awssdk.services.secretsmanager.model.CreateSecretRequest)1 CreateSecretResponse (software.amazon.awssdk.services.secretsmanager.model.CreateSecretResponse)1 DescribeSecretResponse (software.amazon.awssdk.services.secretsmanager.model.DescribeSecretResponse)1 ResourceNotFoundException (software.amazon.awssdk.services.secretsmanager.model.ResourceNotFoundException)1