in aws-rds-optiongroup/src/main/java/software/amazon/rds/optiongroup/BaseHandlerStd.java [98:133]
protected ProgressEvent<ResourceModel, CallbackContext> updateTags(
final AmazonWebServicesClientProxy proxy,
final ProxyClient<RdsClient> proxyClient,
final ProgressEvent<ResourceModel, CallbackContext> progress,
final Map<String, String> previousTags,
final Map<String, String> desiredTags
) {
return proxy.initiate("rds::tag-option-group", proxyClient, progress.getResourceModel(), progress.getCallbackContext())
.translateToServiceRequest(Translator::describeOptionGroupsRequest)
.makeServiceCall((describeRequest, proxyInvocation) -> proxyInvocation.injectCredentialsAndInvokeV2(
describeRequest,
proxyInvocation.client()::describeOptionGroups
)).handleError((describeRequest, exception, client, resourceModel, ctx) -> Commons.handleException(
ProgressEvent.progress(resourceModel, ctx),
exception,
DEFAULT_OPTION_GROUP_ERROR_RULE_SET
))
.done((describeRequest, describeResponse, invocation, resourceModel, ctx) -> {
final String arn = describeResponse.optionGroupsList().stream().findFirst().get().optionGroupArn();
final Set<Tag> previousTagSet = Translator.translateTagsToModelResource(previousTags);
final Set<Tag> desiredTagSet = Translator.translateTagsToModelResource(desiredTags);
final Set<Tag> tagsToRemove = Sets.difference(previousTagSet, desiredTagSet);
final Set<Tag> tagsToAdd = Sets.difference(desiredTagSet, previousTagSet);
proxyClient.injectCredentialsAndInvokeV2(
Translator.removeTagsFromResourceRequest(arn, tagsToRemove),
proxyClient.client()::removeTagsFromResource
);
proxyClient.injectCredentialsAndInvokeV2(
Translator.addTagsToResourceRequest(arn, tagsToAdd),
proxyClient.client()::addTagsToResource
);
return ProgressEvent.progress(resourceModel, ctx);
});
}