Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Use multiple file upload for boefje handler #3581

Draft
wants to merge 1 commit into
base: main
Choose a base branch
from
Draft
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
23 changes: 23 additions & 0 deletions boefjes/boefjes/clients/bytes_client.py
Original file line number Diff line number Diff line change
Expand Up @@ -122,6 +122,29 @@ def save_raw(self, boefje_meta_id: str, raw: str | bytes, mime_types: Set[str] =

return UUID(response.json()[file_name])

@retry_with_login
def save_raw_files(self, boefje_meta_id: str, boefje_results: list[tuple[set, bytes | str]]) -> UUID:
file_name = "raw" # The name provides a key for all ids returned, so this is arbitrary as we only upload 1 file

response = self._session.post(
"/bytes/raw",
json={
"files": [
{
"name": file_name,
"content": b64encode(raw if isinstance(raw, bytes) else raw.encode()).decode(),
"tags": list(mime_types),
}
for mime_types, raw in boefje_results
]
},
headers=self.headers,
params={"boefje_meta_id": str(boefje_meta_id)},
)
self._verify_response(response)

return UUID(response.json()[file_name])

@retry_with_login
def get_raw(self, raw_data_id: str) -> bytes:
response = self._session.get(f"/bytes/raw/{raw_data_id}", headers=self.headers)
Expand Down
8 changes: 4 additions & 4 deletions boefjes/boefjes/job_handler.py
Original file line number Diff line number Diff line change
Expand Up @@ -141,6 +141,7 @@ def handle(self, boefje_meta: BoefjeMeta) -> None:
self.bytes_client.save_boefje_meta(boefje_meta)

if boefje_results:
boefje_results_with_updated_mime_types = []
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Created but unused (yet)?

for boefje_added_mime_types, output in boefje_results:
valid_mimetypes = set()
for mimetype in boefje_added_mime_types:
Expand All @@ -152,10 +153,9 @@ def handle(self, boefje_meta: BoefjeMeta) -> None:
)
else:
valid_mimetypes.add(mimetype)
raw_file_id = self.bytes_client.save_raw(boefje_meta.id, output, mime_types.union(valid_mimetypes))
logger.info(
"Saved raw file %s for boefje %s[%s]", raw_file_id, boefje_meta.boefje.id, boefje_meta.id
)
boefje_results_with_updated_mime_types.append((mime_types.union(valid_mimetypes), output))
self.bytes_client.save_raw_files(boefje_meta.id, boefje_results)
logger.info("Saved raw file for boefje %s[%s]", boefje_meta.boefje.id, boefje_meta.id)
else:
logger.info("No results for boefje %s[%s]", boefje_meta.boefje.id, boefje_meta.id)

Expand Down
Loading