Esempio n. 1
0
    def delete_batch(self, request):

        aws_request = {
            'Bucket': request.bucket,
            'Delete': {
                'Objects': [{
                    'Key': object
                } for object in request.objects]
            }
        }

        try:
            aws_response = self.client.delete_objects(**aws_request)
        except Exception as e:
            message = e.response['Error']['Message']
            code = int(e.response['ResponseMetadata']['HTTPStatusCode'])
            raise messages.S3ClientError(message, code)

        deleted = [obj['Key'] for obj in aws_response.get('Deleted', [])]

        failed = [obj['Key'] for obj in aws_response.get('Errors', [])]

        errors = [
            messages.S3ClientError(obj['Message'], obj['Code'])
            for obj in aws_response.get('Errors', [])
        ]

        return messages.DeleteBatchResponse(deleted, failed, errors)
Esempio n. 2
0
    def delete_batch(self, request):

        aws_request = {
            'Bucket': request.bucket,
            'Delete': {
                'Objects': [{
                    'Key': object
                } for object in request.objects]
            }
        }

        try:
            aws_response = self.client.delete_objects(**aws_request)
        except Exception as e:
            raise messages.S3ClientError(str(e), get_http_error_code(e))

        deleted = [obj['Key'] for obj in aws_response.get('Deleted', [])]

        failed = [obj['Key'] for obj in aws_response.get('Errors', [])]

        errors = [
            messages.S3ClientError(obj['Message'], obj['Code'])
            for obj in aws_response.get('Errors', [])
        ]

        return messages.DeleteBatchResponse(deleted, failed, errors)
Esempio n. 3
0
    def delete_batch(self, request):

        deleted, failed, errors = [], [], []
        for object in request.objects:
            try:
                delete_request = messages.DeleteRequest(request.bucket, object)
                self.delete(delete_request)
                deleted.append(object)
            except messages.S3ClientError as e:
                failed.append(object)
                errors.append(e)

        return messages.DeleteBatchResponse(deleted, failed, errors)