def list_objects(self, bucket_id, **kwargs): try: _, objs = self.swift.get_container(bucket_id) except swiftclient.ClientException as err: if err.http_status == 404: raise errors.DriverBucketUnfoundError(err.args[0]) raise return [o['name'] for o in objs]
def upload(self, bucket_id, name, content, acl='public-read', **kwargs): if bucket_id not in self.buckets: raise errors.DriverBucketUnfoundError("Bucket not found") stored = io.BytesIO() copyfileobj(content, stored) stored.seek(0) self.buckets[bucket_id][name] = stored return {'name': name}
def list_objects(self, bucket_id, **kwargs): try: response = self.client.list_objects( namespace_name=self.kwargs['namespace'], bucket_name=bucket_id, ) except oci.exceptions.ServiceError as err: if err.code == 'BucketNotFound': raise errors.DriverBucketUnfoundError(err) raise return [o.name for o in response.data.objects]
def list_objects(self, bucket_id, **kwargs): bucket = self.s3.Bucket(bucket_id) try: objects = [o.key for o in bucket.objects.all()] except botocore.exceptions.ClientError as err: code = err.response['Error']['Code'] msg = err.response['Error']['Message'] if code == 'NoSuchBucket': raise errors.DriverBucketUnfoundError(msg) raise return objects
def upload(self, bucket_id, name, content, acl=None, multipart_threshold=None, multipart_chunksize=None, max_concurrency=None, **kwargs): acl = acl or self.default_object_acl extra = {'ACL': acl} multipart_threshold = multipart_threshold or base.MULTIPART_THRESHOLD multipart_chunksize = multipart_chunksize or base.MULTIPART_CHUNKSIZE max_concurrency = max_concurrency or base.MAX_CONCURRENCY transfer_config = TransferConfig( multipart_threshold=multipart_threshold, max_concurrency=max_concurrency, multipart_chunksize=multipart_chunksize, ) try: self.s3.meta.client.upload_fileobj( Fileobj=content, Bucket=bucket_id, Key=name, ExtraArgs=extra, Config=transfer_config, ) except botocore.exceptions.ClientError as err: code = err.response['Error']['Code'] msg = err.response['Error']['Message'] if code == 'NoSuchBucket': raise errors.DriverBucketUnfoundError(msg) elif code == 'AccessDenied': raise errors.DriverBucketUnfoundError(msg) raise return {'name': name}
def download(self, url, block_size=65536, **kwargs): parsed_url = urlparse(url) bucket_id = parsed_url.netloc if bucket_id not in self.buckets: raise errors.DriverBucketUnfoundError("Bucket not found") obj_name = parsed_url.path[1:] if obj_name not in self.buckets[bucket_id]: raise errors.DriverObjectUnfoundError("Object not found") fd = self.buckets[bucket_id][obj_name] for chunk in fd.read(block_size): pass self.buckets[bucket_id][obj_name].seek(0)
def delete_object(self, bucket_id, name, **kwargs): if bucket_id not in self.buckets: raise errors.DriverBucketUnfoundError("Bucket not found") self.buckets[bucket_id].pop(name, None)
def list_objects(self, bucket_id, **kwargs): if bucket_id not in self.buckets: raise errors.DriverBucketUnfoundError("Bucket not found") return list(self.buckets[bucket_id])