in aws-transfer-workflow/src/main/java/software/amazon/transfer/workflow/UpdateHandler.java [35:95]
public ProgressEvent<ResourceModel, CallbackContext> handleRequest(
AmazonWebServicesClientProxy proxy,
ResourceHandlerRequest<ResourceModel> request,
CallbackContext callbackContext,
Logger logger) {
if (this.client == null){
this.client = ClientBuilder.getClient();
}
ResourceModel model = request.getDesiredResourceState();
String arn = String.format("arn:%s:transfer:%s:%s:workflow/%s",
request.getAwsPartition(),
request.getRegion(),
request.getAwsAccountId(),
model.getWorkflowId());
model.setTags(Converter.TagConverter.translateTagfromMap(request.getDesiredResourceTags()));
Set<Tag> previousTags = Converter.TagConverter.translateTagfromMap(request.getPreviousResourceTags());
Set<Tag> desiredTags = model.getTags();
Set<Tag> tagsToAdd = Sets.difference(new HashSet<>(desiredTags), new HashSet<>(previousTags));
Set<Tag> tagsToRemove = Sets.difference(new HashSet<>(previousTags), new HashSet<>(desiredTags));
try {
if (!tagsToAdd.isEmpty()) {
TagResourceRequest tagResourceRequest = TagResourceRequest.builder()
.arn(arn)
.tags(tagsToAdd.stream().map(Converter.TagConverter::toSdk).collect(Collectors.toList()))
.build();
proxy.injectCredentialsAndInvokeV2(tagResourceRequest, client::tagResource);
}
if (!tagsToRemove.isEmpty()) {
UntagResourceRequest unTagResourceRequest = UntagResourceRequest.builder()
.arn(arn)
.tagKeys(tagsToRemove.stream().map(Tag::getKey).collect(Collectors.toList()))
.build();
proxy.injectCredentialsAndInvokeV2(unTagResourceRequest, client::untagResource);
}
logger.log(String.format("%s %s updated tags successfully",
ResourceModel.TYPE_NAME,
model.getPrimaryIdentifier()));
return ProgressEvent.<ResourceModel, CallbackContext>builder()
.resourceModel(model)
.status(OperationStatus.SUCCESS)
.build();
} catch (InvalidRequestException e) {
throw new CfnInvalidRequestException(request.toString(), e);
} catch (InternalServiceErrorException e) {
throw new CfnServiceInternalErrorException("Updating tags for workflow", e);
} catch (ResourceNotFoundException e) {
throw new CfnNotFoundException(ResourceModel.TYPE_NAME, arn);
} catch (TransferException e) {
logger.log(String.format("Failed to update %s", arn));
throw new CfnGeneralServiceException(e.getMessage(), e);
}
}