in aws-memorydb-acl/src/main/java/software/amazon/memorydb/acl/UpdateHandler.java [130:162]
private void handleTagging(AmazonWebServicesClientProxy proxy, ProxyClient<MemoryDbClient> client,
final Map<String, String> tags, final ResourceModel model) {
final Set<Tag> newTags = tags == null ? Collections.emptySet() : new HashSet<>(Translator.translateTags(tags));
final Set<Tag> existingTags = new HashSet<>();
//Fix for unpopulated arn on resource model
setModelArn(proxy, client, model);
if (!StringUtils.isNullOrEmpty(model.getArn())) {
existingTags.addAll(
Translator.translateTags(
proxy.injectCredentialsAndInvokeV2(
Translator.translateToListTagsRequest(model),
client.client()::listTags).tagList()));
}
final List<Tag> tagsToRemove = existingTags.stream()
.filter(tag -> !newTags.contains(tag))
.collect(Collectors.toList());
final List<Tag> tagsToAdd = newTags.stream()
.filter(tag -> !existingTags.contains(tag))
.collect(Collectors.toList());
if (!CollectionUtils.isNullOrEmpty(tagsToRemove)) {
proxy.injectCredentialsAndInvokeV2(
Translator.translateToUntagResourceRequest(model.getArn(), tagsToRemove),
client.client()::untagResource);
}
if (!CollectionUtils.isNullOrEmpty(tagsToAdd)) {
proxy.injectCredentialsAndInvokeV2(
Translator.translateToTagResourceRequest(model.getArn(), tagsToAdd),
client.client()::tagResource);
}
}