Beispiel #1
0
 def test_object_is_iterator(self, mock_connection):
     mock_server = MockConnection()
     mock_connection.return_value = mock_server
     mock_server.mock_add_request(
         MockResponse('POST',
                      'https://localhost:9000/hello?delete=', {
                          'User-Agent': _DEFAULT_USER_AGENT,
                          'Content-Md5': u'YcTFWle4oiLJ6sT95FwpdA=='
                      },
                      200,
                      content=b'<Delete/>'))
     client = Minio('localhost:9000')
     it = itertools.chain((DeleteObject("Ab"), DeleteObject("c")))
     for err in client.remove_objects('hello', it):
         print(err)
Beispiel #2
0
    def handle(self, *args, **options):
        existing = set(map(str, Check.objects.values_list("code", flat=True)))

        c = client()
        delete_list = []
        for obj in c.list_objects(settings.S3_BUCKET):
            try:
                UUID(obj.object_name[:-1])
            except ValueError:
                continue

            if obj.object_name[:-1] not in existing:
                delete_list.append(obj.object_name)

        print("Staged for deletion: %d" % len(delete_list))
        for prefix in delete_list:
            print("Deleting %s" % prefix)
            q = c.list_objects(settings.S3_BUCKET, prefix)
            delete_objs = [DeleteObject(obj.object_name) for obj in q]
            if delete_objs:
                errors = c.remove_objects(settings.S3_BUCKET, delete_objs)
                for e in errors:
                    print("remove_objects error: ", e)

        return "Done!"
 def test_object_is_tuple(self, mock_connection):
     mock_server = MockConnection()
     mock_connection.return_value = mock_server
     mock_server.mock_add_request(
         MockResponse('POST',
                      'https://localhost:9000/hello?delete=', {
                          'User-Agent': _DEFAULT_USER_AGENT,
                          'Content-Md5': u'Te1kmIjQRNNz70DJjsrD8A=='
                      },
                      200,
                      content=b'<Delete/>'))
     client = Minio('localhost:9000')
     for err in client.remove_objects(
             "hello",
         (DeleteObject("Ab"), DeleteObject("c")),
     ):
         print(err)
Beispiel #4
0
def _remove_objects(code, upto_n):
    if upto_n <= 0:
        return

    prefix = "%s/" % code
    start_after = prefix + enc(upto_n + 1)
    q = client().list_objects(settings.S3_BUCKET, prefix, start_after=start_after)
    delete_objs = [DeleteObject(obj.object_name) for obj in q]
    if delete_objs:
        errors = client().remove_objects(settings.S3_BUCKET, delete_objs)
        for e in errors:
            print("remove_objects error: ", e)
Beispiel #5
0
 def deleteBucket(self):
     bucket_name = "my-test-bucket"
     myPrint("Fetching objects level 1 list")
     myPrint("Total objects level 1 " +
             str(len(self.listObjects(bucket_name, False))))
     myPrint("Fetching object recursive list")
     object_names = self.listObjects(bucket_name, True)
     removed_objects = []
     myPrint("Total objects " + str(len(object_names)))
     for obj_name in object_names:
         removed_objects.append(DeleteObject(obj_name))
     errors = self.client.remove_objects(bucket_name, removed_objects)
     for error in errors:
         myPrint(error, 11)
     self.client.remove_bucket(bucket_name)
Beispiel #6
0
def _ensure_remove_bucket(client: Minio, bucket_name: str):
    if client.bucket_exists(bucket_name):
        # remove content
        objs: Iterator[Object] = client.list_objects(
            bucket_name, prefix=None, recursive=True
        )

        # FIXME: minio 7.1.0 does NOT remove all objects!? Added in requirements/constraints.txt
        to_delete = [DeleteObject(o.object_name) for o in objs]
        errors: Iterator[DeleteError] = client.remove_objects(bucket_name, to_delete)

        list_of_errors = list(errors)
        assert not any(list_of_errors), list(list_of_errors)

        # remove bucket
        client.remove_bucket(bucket_name)

    assert not client.bucket_exists(bucket_name)
Beispiel #7
0
    def remove_objects(self, bucket_name: str, objects: List[str]):
        try:
            delete = [DeleteObject(name, version_id=None) for name in objects]
            iter_errors: Iterator[DeleteError] = self._minio.remove_objects(
                bucket_name, delete)
            for err in iter_errors:
                log.error(
                    "Failed to delete '%s' [version=%s]: %s (code: %s)",
                    err.name,
                    err.version_id,
                    err.message,
                    err.code,
                )

        except MinioException:
            logging.exception("Could remove objects")
            return False
        return True
# Licensed under the Apache License, Version 2.0 (the "License");
# you may not use this file except in compliance with the License.
# You may obtain a copy of the License at
#
#     http://www.apache.org/licenses/LICENSE-2.0
#
# Unless required by applicable law or agreed to in writing, software
# distributed under the License is distributed on an "AS IS" BASIS,
# WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
# See the License for the specific language governing permissions and
# limitations under the License.

# Note: YOUR-ACCESSKEYID, YOUR-SECRETACCESSKEY, my-bucketname and my-prefix
# are dummy values, please replace them with original values.

from minio import Minio
from minio.deleteobjects import DeleteObject

client = Minio('s3.amazonaws.com',
               access_key='YOUR-ACCESSKEYID',
               secret_key='YOUR-SECRETACCESSKEY')

# Remove a prefix recursively.
delete_object_list = map(
    lambda x: DeleteObject(x.object_name),
    client.list_objects("my-bucketname", "my-prefix", recursive=True),
)
errors = client.remove_objects("my-bucketname", delete_object_list)
for error in errors:
    print("error occured when deleting object", error)