Skip to content

Commit 3128719

Browse files
committed
fix: always upload the binary even if it does exist already
1 parent 10af1dc commit 3128719

File tree

2 files changed

+19
-36
lines changed

2 files changed

+19
-36
lines changed

pyproject.toml

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -4,7 +4,7 @@ build-backend = "setuptools.build_meta"
44

55
[project]
66
name = "reait"
7-
version = "1.2.1"
7+
version = "1.2.2"
88
readme = "README.md"
99
classifiers=[
1010
"Programming Language :: Python :: 3",

src/reait/api.py

Lines changed: 18 additions & 35 deletions
Original file line numberDiff line numberDiff line change
@@ -15,7 +15,7 @@
1515
from requests import request, Response, HTTPError
1616
from sklearn.metrics.pairwise import cosine_similarity
1717

18-
__version__ = "1.2.1"
18+
__version__ = "1.2.2"
1919

2020
re_conf = {
2121
"apikey": environ.get("REAI_API_KEY", ""),
@@ -335,43 +335,25 @@ def RE_upload(fpath: str) -> Response:
335335
:param fpath: File path for binary to analyse
336336
"""
337337
bin_id = re_binary_id(fpath)
338-
result = re_hash_check(bin_id)
339338

340-
if result:
339+
with open(fpath, "rb") as fd:
340+
res: Response = reveng_req(
341+
requests.post, "v1/upload", files={"file": fd})
342+
343+
if res.ok:
341344
logger.info(
342-
"File %s - %s already uploaded. Skipping upload...", fpath, bin_id)
343-
344-
res = Response()
345-
res.status_code = 200
346-
res.url = f"{re_conf['host']}/v1/upload"
347-
res._content = (
348-
(
349-
'{0}"success": true,'
350-
'"message": "File already uploaded!",'
351-
'"sha_256_hash": "{1}"{2}'
352-
)
353-
.format("{", bin_id, "}")
354-
.encode()
345+
"Successfully uploaded binary to your account. %s - %s", fpath, bin_id
346+
)
347+
elif res.status_code == 400:
348+
if "error" in res.json().keys():
349+
logger.warning("Error uploading %s - %s",
350+
fpath, res.json()["error"])
351+
elif res.status_code == 413:
352+
logger.warning("File too large. Please upload files under 10MB.")
353+
elif res.status_code == 500:
354+
logger.error(
355+
"Internal Server Error. Please contact support. Skipping upload..."
355356
)
356-
else:
357-
with open(fpath, "rb") as fd:
358-
res: Response = reveng_req(
359-
requests.post, "v1/upload", files={"file": fd})
360-
361-
if res.ok:
362-
logger.info(
363-
"Successfully uploaded binary to your account. %s - %s", fpath, bin_id
364-
)
365-
elif res.status_code == 400:
366-
if "error" in res.json().keys():
367-
logger.warning("Error uploading %s - %s",
368-
fpath, res.json()["error"])
369-
elif res.status_code == 413:
370-
logger.warning("File too large. Please upload files under 10MB.")
371-
elif res.status_code == 500:
372-
logger.error(
373-
"Internal Server Error. Please contact support. Skipping upload..."
374-
)
375357

376358
res.raise_for_status()
377359
return res
@@ -1302,6 +1284,7 @@ def RE_similar_functions(
13021284
res.raise_for_status()
13031285
return res
13041286

1287+
13051288
def RE_binary_ann(
13061289
analysis_id: int,
13071290
confidence: float = 0.0,

0 commit comments

Comments
 (0)