public function copyAction($imageId)
{
$this->checkScopedPermissions('IMAGES', 'MANAGE');
$object = $this->request->getJsonBody();
if (empty($object->cloudLocation) || empty($object->cloudPlatform)) {
throw new ApiErrorException(400, ErrorMessage::ERR_INVALID_STRUCTURE, "Invalid body");
}
$locations = Aws::getCloudLocations();
if (!in_array($object->cloudLocation, $locations)) {
throw new ApiErrorException(400, ErrorMessage::ERR_INVALID_VALUE, "Invalid region");
}
if ($object->cloudPlatform !== 'ec2') {
throw new ApiErrorException(400, ErrorMessage::ERR_INVALID_VALUE, "Only Ec2 cloud platform is supported");
}
$image = $this->getImage($imageId, true);
$imageAdapter = $this->adapter('image');
//Re-validates an Entity
$imageAdapter->validateEntity($image);
if ($image->cloudLocation == $object->cloudLocation) {
throw new ApiErrorException(400, ErrorMessage::ERR_BAD_REQUEST, 'Destination region is the same as source one');
}
try {
$newImage = $image->migrateEc2Location($object->cloudLocation, $this->getUser());
} catch (NotEnabledPlatformException $e) {
throw new ApiErrorException(400, ErrorMessage::ERR_NOT_ENABLED_PLATFORM, $e->getMessage());
}
$this->response->setStatus(202);
return $this->result($imageAdapter->toData($newImage));
}