Skip to content

Commit

Permalink
Add documentation for reconstruct_all_subresponses
Browse files Browse the repository at this point in the history
  • Loading branch information
mlaferrera committed Mar 29, 2019
1 parent c74c323 commit a52229e
Show file tree
Hide file tree
Showing 3 changed files with 27 additions and 3 deletions.
4 changes: 4 additions & 0 deletions CHANGELOG.md
Original file line number Diff line number Diff line change
Expand Up @@ -7,6 +7,10 @@ and this project adheres to [Semantic Versioning](https://semver.org/spec/v2.0.0

## Unreleased

### Added

- `Stoq.reconstruct_all_subresponses()` method to allow for reconstructing `StoqResponse` objects iteratively (@maydewd)

### Changed

- Force payload content to be of type bytes
Expand Down
Binary file added docs/_static/reconstruct-results.png
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
26 changes: 23 additions & 3 deletions stoq/core.py
Original file line number Diff line number Diff line change
Expand Up @@ -267,6 +267,25 @@
>>> results = s.scan_payload(payload)
>>> results.split()
Reconstructing Subresponse Results
----------------------------------
stoQ can produce complex results depending on the recursion depth and extracted payload objects.
In order to help handle complex results and limit redundant processing of payloads when using
stoQ as a framework, a method exists that will allow for iterating over each result as if it
were the original root object. This is especially useful when handling compressed archives, such
as `zip` or `apk` files that may have multiple levels of archived content. Additionally, the
defined decorators will be run against each newly constructed `StoqResponse` and added to the
results.
>>> for result in s.reconstruct_all_subresponses(results):
... print(result)
Below is a simple flow diagram of the iterated results when being reconstructed.
.. image:: /_static/reconstruct-results.png
.. _multiplugindir:
Multiple Plugin directories
Expand All @@ -286,7 +305,6 @@
"""

import os
import json
import queue
import logging
import configparser
Expand Down Expand Up @@ -837,7 +855,9 @@ def _apply_decorators(self, response: StoqResponse) -> None:
if decorator_response.errors:
response.errors[plugin_name].extend(decorator_response.errors)

def reconstruct_all_subresponses(self, stoq_response: StoqResponse) -> Iterable[StoqResponse]:
def reconstruct_all_subresponses(
self, stoq_response: StoqResponse
) -> Iterable[StoqResponse]:
for i, new_root_result in enumerate(stoq_response.results):
parent_payload_ids = {stoq_response.results[i].payload_id}
relevant_results: List[PayloadResults] = [new_root_result]
Expand All @@ -850,7 +870,7 @@ def reconstruct_all_subresponses(self, stoq_response: StoqResponse) -> Iterable[
request_meta=stoq_response.request_meta,
errors=stoq_response.errors,
time=stoq_response.time,
scan_id=stoq_response.scan_id
scan_id=stoq_response.scan_id,
)
self._apply_decorators(new_response)
yield new_response

0 comments on commit a52229e

Please sign in to comment.