Skip to content

Commit

Permalink
Browse files Browse the repository at this point in the history
Add API to delete files from filestore only
  • Loading branch information
cccs-rs committed May 27, 2024
2 parents 0d9f0e0 + 8cfbc1b commit 35708e1
Show file tree
Hide file tree
Showing 2 changed files with 22 additions and 1 deletion.
13 changes: 12 additions & 1 deletion assemblyline_client/v4_client/module/file.py
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
from assemblyline_client.v4_client.common.utils import api_path_by_module, get_function_kwargs, \
stream_output, raw_output
stream_output, raw_output, api_path


class File(object):
Expand Down Expand Up @@ -52,6 +52,17 @@ def download(self, sha256, encoding=None, sid=None, output=None, password=None):
return self._connection.download(path, stream_output(output))
return self._connection.download(path, raw_output)

def delete_from_filestore(self, sha256):
"""\
Delete a file from the filestore without deleting the file record
Required:
sha256 : A resource locator for the file (sha256)
Throws a Client exception if the file does not exist or if you don't have the rights to delete the file.
"""
return self._connection.delete(api_path('file/filestore', sha256))

def hex(self, sha256, bytes_only=False, length=None):
"""\
Return an hexadecimal representation of the file.
Expand Down
10 changes: 10 additions & 0 deletions test/test_file.py
Original file line number Diff line number Diff line change
Expand Up @@ -92,6 +92,16 @@ def test_download_to_file_handle(datastore, client):
finally:
os.unlink(download_output)

# noinspection PyUnusedLocal
def test_delete_from_filestore(datastore, filestore, client):
file_id = random_id_from_collection(datastore, 'file')

# Delete file from filestore only
# Shouldn't affect the related document in the datastore
assert filestore.exists(file_id)
assert client.file.delete_from_filestore(file_id)['success']
assert not filestore.exists(file_id) and datastore.file.exists(file_id)


# noinspection PyUnusedLocal
def test_info(datastore, client):
Expand Down

0 comments on commit 35708e1

Please sign in to comment.