def run(self, endpoint_secure=True, endpoint=None, access_key=None, secret_key=None, filename=None, bucket=None): """ removes a file from a bucket """ # Initialize minioClient with an endpoint and access/secret keys. success, minioClient = minio_client(self, endpoint=endpoint, endpoint_secure=endpoint_secure, access_key=access_key, secret_key=secret_key) if not success: return (False, minioClient) # check if object exists if not minioClient.stat_object(bucket, filename): return (False, "Object {} doesn't exist in bucket {}".format( filename, bucket)) # remove it if it does try: minioClient.remove_object(bucket, filename) return (True, filename) except ResponseError as err: return (False, err)
def run(self, endpoint_secure=True, endpoint=None, access_key=None, secret_key=None, bucket=None): """ lists objects in a bucket """ # Initialize minioClient with an endpoint and access/secret keys. success, minioClient = minio_client(self, endpoint=endpoint, endpoint_secure=endpoint_secure, access_key=access_key, secret_key=secret_key) if not success: return (False, minioClient) try: if not minioClient.bucket_exists(bucket): return (False, "Bucket {} doesn't exists".format(bucket)) else: return (True, minioClient.list_objects(bucket)) except ResponseError as err: return (False, err)
def run(self, endpoint_secure=True, endpoint=None, access_key=None, secret_key=None, bucket=None): """ lists available buckets """ # Initialize minioClient with an endpoint and access/secret keys. success, minioClient = minio_client(self, endpoint=endpoint, endpoint_secure=endpoint_secure, access_key=access_key, secret_key=secret_key) if not success: return (False, minioClient) try: bucket_data = minioClient.list_buckets() # clean up the return data bucketlist = [{ 'name': bucket.name, 'creation_date': bucket.creation_date.isoformat() } for bucket in bucket_data] return (True, bucketlist) except ResponseError as err: return (False, err)
def run(self, endpoint_secure=True, endpoint=None, access_key=None, secret_key=None, filename=None, filedata=None, filesource=None, bucket=None, location=None): """ uploads a file from the local disk """ # check supplied config and set global config if available # Initialize minioClient with an endpoint and access/secret keys. success, minioClient = minio_client(self, endpoint=endpoint, endpoint_secure=endpoint_secure, access_key=access_key, secret_key=secret_key) if not success: return (False, minioClient) # Make a bucket with the make_bucket API call. try: if location: minioClient.make_bucket(bucket, location=location) else: minioClient.make_bucket(bucket) except BucketAlreadyOwnedByYou as err: pass except BucketAlreadyExists as err: pass except ResponseError as err: raise #upload the file try: if filedata: self.logger.debug("Writing input content to '{}/{}'".format( bucket, filename)) with NamedTemporaryFile() as fh: fh.write(filedata.encode('utf-8')) fh.seek(0) if minioClient.put_object(bucket, filename, fh, len(filedata)): return (True, "Wrote '{}/{}'".format(bucket, filename)) else: return (False, "Failed to write filedata to '{}/{}'".format( bucket, filename)) else: if os.path.exists(filesource): self.logger.debug("Found file: '{}'".format(filesource)) if minioClient.fput_object(bucket, filename, filesource): return (True, "Write file from '{} to '{}/{}'".format( filesource, bucket, filename)) else: return ( False, "Failed to write file from '{}' to '{}/{}'".format( filesource, bucket, filename)) else: return (False, "Couldn't find file '{}'".format(filesource)) except ResponseError as err: return (False, err) return (False, "Failed for some reason")