in aws-datasync-locationnfs/src/main/java/software/amazon/datasync/locationnfs/CreateHandler.java [25:84]
public ProgressEvent<ResourceModel, CallbackContext> handleRequest(
final AmazonWebServicesClientProxy proxy,
final ResourceHandlerRequest<ResourceModel> request,
final CallbackContext callbackContext,
final Logger logger) {
final ResourceModel model = request.getDesiredResourceState();
final DataSyncClient client = ClientBuilder.getClient();
if (callbackContext == null && (request.getDesiredResourceState().getLocationArn() != null)) {
throw new CfnInvalidRequestException("LocationArn cannot be specified to create a location.");
}
Map<String, String> tagList = request.getDesiredResourceTags();
if (tagList == null) {
tagList = new HashMap<String, String>();
}
// Check for invalid requested system tags.
for (String key : tagList.keySet()) {
if (key.trim().toLowerCase().startsWith(AWS_TAG_PREFIX)) {
throw new CfnInvalidRequestException(key + " is an invalid key. aws: prefixed tag key names cannot be requested.");
}
}
// Retrieve default stack-level tags with aws:cloudformation prefix.
Map<String,String> systemTagList = request.getSystemTags();
if (systemTagList != null) {
tagList.putAll(systemTagList);
}
CreateLocationNfsRequest createLocationNfsRequest = Translator.translateToCreateRequest(model, tagList);
CreateLocationNfsResponse response;
try {
response = proxy.injectCredentialsAndInvokeV2(createLocationNfsRequest, client::createLocationNfs);
logger.log(String.format("%s created successfully.", ResourceModel.TYPE_NAME));
} catch (InvalidRequestException e) {
throw new CfnInvalidRequestException(e.getMessage(), e.getCause());
} catch (InternalException e) {
throw new CfnServiceInternalErrorException(e.getMessage(), e.getCause());
} catch (DataSyncException e) {
throw Translator.translateDataSyncExceptionToCfnException(e);
}
ResourceModel modelNoUri = ResourceModel.builder()
.mountOptions(model.getMountOptions())
.locationArn(response.locationArn())
.onPremConfig(model.getOnPremConfig())
.serverHostname(model.getServerHostname())
.subdirectory(model.getSubdirectory())
.tags(model.getTags())
.build();
ResourceHandlerRequest<ResourceModel> requestWithArn = request.toBuilder()
.desiredResourceState(modelNoUri)
.build();
return new ReadHandler().handleRequest(proxy, requestWithArn, callbackContext, logger);
}