This repository has been archived by the owner on Aug 25, 2024. It is now read-only.
-
Notifications
You must be signed in to change notification settings - Fork 138
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
source: dataset: threat modeling: threat dragon: Initial source
Signed-off-by: John Andersen <[email protected]>
- Loading branch information
Showing
2 changed files
with
44 additions
and
0 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,43 @@ | ||
import json | ||
import pathlib | ||
|
||
from ...record import Record | ||
from ..memory import MemorySource | ||
from .base import dataset_source | ||
|
||
|
||
@dataset_source("owasp.threat-dragon") | ||
async def threat_dragon( | ||
filepath: pathlib.Path, feature_name: str = "threat_model", | ||
): | ||
r""" | ||
Examples | ||
-------- | ||
.. code-block:: console | ||
:test: | ||
$ dffml list records -sources threat_model=owasp.threat-dragon \ | ||
-source-threat_model-filepath /home/pdxjohnny/Documents/python/living-threat-models/models/good.json | ||
>>> from dffml.noasync import load | ||
>>> from dffml import iris_training | ||
>>> | ||
>>> records = list(load(iris_training.source())) | ||
>>> print(len(records)) | ||
120 | ||
>>> records[0].export() | ||
{'key': '0', 'features': {'SepalLength': 6.4, 'SepalWidth': 2.8, 'PetalLength': 5.6, 'PetalWidth': 2.2, 'classification': 2}, 'extra': {}} | ||
""" | ||
contents = filepath.read_text() | ||
threat_model_dict = json.loads(contents) | ||
# TODO(security) Validate JSON schema | ||
title = threat_model_dict["summary"]["title"] | ||
yield MemorySource( | ||
records=[ | ||
Record( | ||
key=title, | ||
data={"features": {feature_name: threat_model_dict,},}, | ||
) | ||
], | ||
) |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters