Exemplo n.º 1
0
    def s3_bucket_response_delete_keys(self, body, bucket_name, *args,
                                       **kwargs):
        template = self.response_template(s3_delete_keys_response_template)
        elements = minidom.parseString(body).getElementsByTagName("Object")
        if len(elements) == 0:
            raise MalformedXML()

        deleted_names = []
        error_names = []

        keys = []
        for element in elements:
            if len(element.getElementsByTagName("VersionId")) == 0:
                version_id = None
            else:
                version_id = element.getElementsByTagName(
                    "VersionId")[0].firstChild.nodeValue

            keys.append({
                "key_name":
                element.getElementsByTagName("Key")[0].firstChild.nodeValue,
                "version_id":
                version_id,
            })

        for k in keys:
            key_name = k["key_name"]
            version_id = k["version_id"]
            success = self.backend.delete_object(bucket_name,
                                                 undo_clean_key_name(key_name),
                                                 version_id)

            if success:
                deleted_names.append({
                    "key": key_name,
                    "version_id": version_id
                })
            else:
                error_names.append(key_name)

        return (
            200,
            {},
            template.render(deleted=deleted_names, delete_errors=error_names),
        )
Exemplo n.º 2
0
    def s3_bucket_response_delete_keys(self, request, body, bucket_name):
        template = self.response_template(s3_delete_keys_response_template)

        elements = minidom.parseString(body).getElementsByTagName('Object')
        if len(elements) == 0:
            raise MalformedXML()

        deleted_names = []
        error_names = []

        keys = []
        for element in elements:
            if len(element.getElementsByTagName('VersionId')) == 0:
                version_id = None
            else:
                version_id = element.getElementsByTagName(
                    'VersionId')[0].firstChild.nodeValue

            keys.append({
                'key_name':
                element.getElementsByTagName('Key')[0].firstChild.nodeValue,
                'version_id':
                version_id
            })

        for k in keys:
            key_name = k['key_name']
            version_id = k['version_id']
            success = self.backend.delete_key(bucket_name,
                                              undo_clean_key_name(key_name),
                                              version_id)

            if success:
                deleted_names.append({
                    'key': key_name,
                    'version_id': version_id
                })
            else:
                error_names.append(key_name)

        return (
            200,
            {},
            template.render(deleted=deleted_names, delete_errors=error_names),
        )