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

Updated the Pydantic functions used by the API #1312

Merged
merged 19 commits into from
Jul 24, 2023
Merged
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
8 changes: 4 additions & 4 deletions docs/developer/developing-new-tasks.md
Original file line number Diff line number Diff line change
Expand Up @@ -116,13 +116,13 @@ etc) prior to execution by setting the state in `Task.REQUIRED_STATES`. Each
Evidence object specifies which states it supports in the
`Evidence.POSSIBLE_STATES` list attribute for that Task (e.g. see the
[`GoogleCloudDisk` possible states
here](https:/google/turbinia/blob/cc79288ae36cfec749381b80694b4c1290d76583/turbinia/evidence.py#L661)).
here - Line 717](https:/google/turbinia/blob/master/turbinia/evidence.py)).
These states are set up by the pre-processors and then after the Task is
completed, the post-processor will tear down this state (e.g. unmount or
detach, etc). For more details on the different states and how the
pre/post-processors will set these up at runtime, see the
[`Evidence.preprocess()`
docstrings](https:/google/turbinia/blob/cc79288ae36cfec749381b80694b4c1290d76583/turbinia/evidence.py#L291).
docstrings - Line 405](https:/google/turbinia/blob/master/turbinia/evidence.py).

### Evidence Paths

Expand All @@ -144,7 +144,7 @@ generally this should not be needed as long as you set the
`TurbiniaTask.REQUIRED_STATES` for the Task to match your actual requirements
since the `local_path` should always be created by the pre-processors.
See the [docstrings for these attributes in the Evidence
object](https:/google/turbinia/blob/cc79288ae36cfec749381b80694b4c1290d76583/turbinia/evidence.py#L127)
object - Line 203](https:/google/turbinia/blob/master/turbinia/evidence.py)
for more details.

### Recipe configuration
Expand All @@ -155,7 +155,7 @@ should be run. Each Task has a `TASK_CONFIG` dictionary set at the object
level that defines each of the variables that can be used along with the
default values that the Task will use when the recipe does not specify that
variable, or there is no recipe used. See the [Plaso
Task](https:/google/turbinia/blob/8aafea5d4ba165aa72748ed7f1f196c8b9d7175c/turbinia/workers/plaso.py#L35)
Task - Line 29](https:/google/turbinia/blob/master/turbinia/workers/plaso.py)
`TASK_CONFIG` as an example. Tasks can access these variables by referencing
the dictionary at `self.task_config`.

Expand Down
4 changes: 2 additions & 2 deletions docs/user/recipes.md
Original file line number Diff line number Diff line change
Expand Up @@ -45,10 +45,10 @@ with the defaults:

These generally correlate with similarly named command line flags. The current
full list can be [found
here](https:/google/turbinia/blob/8aafea5d4ba165aa72748ed7f1f196c8b9d7175c/turbinia/lib/recipe_helpers.py#L28).
here - Line 36](https:/google/turbinia/blob/master/turbinia/lib/recipe_helpers.py).
Each Task specifies the available recipe keys in a `TASK_CONFIG` attribute for
the Task object (e.g. [here is the `TASK_CONFIG` for the Plaso
Task](https:/google/turbinia/blob/8aafea5d4ba165aa72748ed7f1f196c8b9d7175c/turbinia/workers/plaso.py#L35)).
Task - Line 141](https:/google/turbinia/blob/master/turbinia/workers/plaso.py)).


Here is a [real sample of the `all` Recipe](https:/google/turbinia/blob/master/turbinia/config/recipes/all.yaml)
Expand Down
17 changes: 9 additions & 8 deletions turbinia/api/routes/request.py
Original file line number Diff line number Diff line change
Expand Up @@ -17,6 +17,7 @@
import logging
import uuid
import json
from collections import OrderedDict

from fastapi import HTTPException, APIRouter
from fastapi.responses import JSONResponse
Expand Down Expand Up @@ -47,11 +48,11 @@ async def get_requests_summary(request: Request):
if not requests_summary.get_requests_summary():
return JSONResponse(
content={'detail': 'Request summary is empty'}, status_code=200)
response_json = requests_summary.json(sort_keys=True)
response_json = requests_summary.model_dump_json()
response = OrderedDict(sorted(json.loads(response_json).items()))
return JSONResponse(
status_code=200, content=json.loads(response_json),
media_type='application/json')
except (json.JSONDecodeError, TypeError, ValueError,
status_code=200, content=response, media_type='application/json')
except (json.JSONDecodeError, TypeError, ValueError, AttributeError,
ValidationError) as exception:
log.error(
f'Error retrieving requests summary: {exception!s}', exc_info=True)
Expand All @@ -77,11 +78,11 @@ async def get_request_status(request: Request, request_id: str):
raise HTTPException(
status_code=404,
detail='Request ID not found or the request had no associated tasks.')
response_json = request_out.json(sort_keys=True)
response_json = request_out.model_dump_json()
response = OrderedDict(sorted(json.loads(response_json).items()))
return JSONResponse(
status_code=200, content=json.loads(response_json),
media_type='application/json')
except (json.JSONDecodeError, TypeError, ValueError,
status_code=200, content=response, media_type='application/json')
except (json.JSONDecodeError, TypeError, ValueError, AttributeError,
ValidationError) as exception:
log.error(f'Error retrieving request information: {exception!s}')
raise HTTPException(
Expand Down
Loading