in aws-datasync-agent/src/main/java/software/amazon/datasync/agent/ReadHandler.java [24:81]
public ProgressEvent<ResourceModel, CallbackContext> handleRequest(
final AmazonWebServicesClientProxy proxy,
final ResourceHandlerRequest<ResourceModel> request,
final CallbackContext callbackContext,
final ProxyClient<DataSyncClient> proxyClient,
final Logger logger) {
final DataSyncClient client = ClientBuilder.getClient();
final ResourceModel model = request.getDesiredResourceState();
final DescribeAgentRequest describeAgentRequest = Translator.translateToReadRequest(model);
DescribeAgentResponse response;
try {
response = proxy.injectCredentialsAndInvokeV2(describeAgentRequest, client::describeAgent);
} catch (InvalidRequestException e) {
throw new CfnNotFoundException(ResourceModel.TYPE_NAME, model.getAgentArn());
} catch (InternalException e) {
throw new CfnServiceInternalErrorException(e.getMessage(), e.getCause());
} catch (DataSyncException e) {
throw Translator.translateDataSyncExceptionToCfnException(e);
}
// Since tags are not returned by the DescribeAgent call but can be modified,
// we must separately retrieve and return them to ensure we return an up-to-date model.
final ListTagsForResourceRequest listTagsForResourceRequest = Translator.translateToListTagsRequest(model);
ListTagsForResourceResponse tagsResponse;
try {
tagsResponse = proxy.injectCredentialsAndInvokeV2(listTagsForResourceRequest, client::listTagsForResource);
} catch (InvalidRequestException e) {
throw new CfnNotFoundException(ResourceModel.TYPE_NAME, model.getAgentArn());
} catch (InternalException e) {
throw new CfnServiceInternalErrorException(e.getMessage(), e.getCause());
} catch (DataSyncException e) {
throw Translator.translateDataSyncExceptionToCfnException(e);
}
Set<Tag> allTags = new HashSet<Tag>();
if (tagsResponse.tags() != null) {
allTags = Translator.translateTagListEntries(tagsResponse.tags());
}
final Set<Tag> userTags = allTags.stream()
.filter(tag -> !tag.getKey().startsWith(AWS_CFN_TAG_PREFIX))
.collect(Collectors.toSet());
ResourceModel returnModel = ResourceModel.builder()
.agentArn(response.agentArn())
.agentName(response.name())
.securityGroupArns(response.privateLinkConfig() == null ? null : response.privateLinkConfig().securityGroupArns())
.subnetArns(response.privateLinkConfig() == null ? null : response.privateLinkConfig().subnetArns())
.vpcEndpointId(response.privateLinkConfig() == null ? null : response.privateLinkConfig().vpcEndpointId())
.endpointType(response.endpointType() == null ? null : response.endpointType().toString())
.tags(userTags)
.build();
return ProgressEvent.defaultSuccessHandler(returnModel);
}