jgstew / besapi

besapi is a Python library designed to interact with the BigFix REST API.
MIT License
5 stars 1 forks source link

enhance file upload to not upload existing files #3

Closed jgstew closed 1 year ago

jgstew commented 1 year ago

When using the BigFix REST API to upload a file to the BigFix Server, you can just send the file to the root and if it already exists with the exact same SHA1 and filename, then it will not create a duplicate file on the remote server.

Before sending the file to the root server, the file could be hashed locally to determine it's SHA1 hash value, then use that value along with the filename in order to determine if the file should be uploaded again, or if an existing copy of the file already exists and that step can be skipped.

Doing this check should save time for any file over a fairly small size, and also have less impact on the root server than sending it a file that it must first hash on the root server itself in order to determine the file's SHA1 hash value in order to determine if the file already exists on the root itself.

Can get the full list of all uploads on the root using: https://bigfix:52311/api/uploads but this could be slow if there are large number of uploads already there.

It should be faster to look for the specific upload in question like this: https://bigfix:52311/api/upload/092bd8ef7b91507bb3848640ef47bb392e7d95b1/test_besapi_upload.txt

The besapi.upload() function should have a parameter added that would be the file's sha1. If the sha1 isn't provided, then the file should be hashed to determine it, otherwise use the provided hash in case we have already hashed the file previously and do not need to do it again, which would be slow for large files.

Use the SHA1 hash of the file, along with it's filename in order to query the root to see if we need to upload the file or not.

The previous behavior of always sending the file each time could be achieved by giving an invalid sha1 value in the parameter, since it would never match a real file, though perhaps it should do that without querying the root first if it knows the sha1 is not valid.


Upload RESTAPI reference:

Approximate location for upload function in the code:

Examples that uses besapi to upload files:

jgstew commented 1 year ago

This is implemented and published as of v3.1.4