Changeset View
Changeset View
Standalone View
Standalone View
swh/objstorage/api/client.py
Show All 17 Lines | class RemoteObjStorage(ObjStorage, SWHRemoteAPI): | ||||
http protocol. | http protocol. | ||||
Attributes: | Attributes: | ||||
url (string): The url of the server to connect. Must end | url (string): The url of the server to connect. Must end | ||||
with a '/' | with a '/' | ||||
session: The session to send requests. | session: The session to send requests. | ||||
""" | """ | ||||
def __init__(self, url): | def __init__(self, url, **kwargs): | ||||
super().__init__(api_exception=ObjStorageAPIError, url=url) | super().__init__(api_exception=ObjStorageAPIError, url=url, **kwargs) | ||||
def check_config(self, *, check_write): | def check_config(self, *, check_write): | ||||
return self.post('check_config', {'check_write': check_write}) | return self.post('check_config', {'check_write': check_write}) | ||||
def __contains__(self, obj_id): | def __contains__(self, obj_id): | ||||
return self.post('content/contains', {'obj_id': obj_id}) | return self.post('content/contains', {'obj_id': obj_id}) | ||||
def add(self, content, obj_id=None, check_presence=True): | def add(self, content, obj_id=None, check_presence=True): | ||||
return self.post('content/add', {'content': content, 'obj_id': obj_id, | return self.post('content/add', {'content': content, 'obj_id': obj_id, | ||||
'check_presence': check_presence}) | 'check_presence': check_presence}) | ||||
def get(self, obj_id): | def get(self, obj_id): | ||||
return self.post('content/get', {'obj_id': obj_id}) | return self.post('content/get', {'obj_id': obj_id}) | ||||
def get_batch(self, obj_ids): | def get_batch(self, obj_ids): | ||||
return self.post('content/get/batch', {'obj_ids': obj_ids}) | return self.post('content/get/batch', {'obj_ids': obj_ids}) | ||||
def check(self, obj_id): | def check(self, obj_id): | ||||
return self.post('content/check', {'obj_id': obj_id}) | return self.post('content/check', {'obj_id': obj_id}) | ||||
def delete(self, obj_id): | |||||
super().delete(obj_id) | |||||
return self.post('content/delete', {'obj_id': obj_id}) | |||||
# Management methods | # Management methods | ||||
def get_random(self, batch_size): | def get_random(self, batch_size): | ||||
return self.post('content/get/random', {'batch_size': batch_size}) | return self.post('content/get/random', {'batch_size': batch_size}) | ||||
# Streaming methods | # Streaming methods | ||||
def add_stream(self, content_iter, obj_id, check_presence=True): | def add_stream(self, content_iter, obj_id, check_presence=True): | ||||
Show All 9 Lines |