Skip to content
This repository has been archived by the owner on Aug 25, 2024. It is now read-only.

Commit

Permalink
source: dataset: threat modeling: threat dragon: Initial source
Browse files Browse the repository at this point in the history
Signed-off-by: John Andersen <[email protected]>
  • Loading branch information
pdxjohnny committed Jun 11, 2022
1 parent 9ddcdfd commit 7969de3
Show file tree
Hide file tree
Showing 2 changed files with 44 additions and 0 deletions.
43 changes: 43 additions & 0 deletions dffml/source/dataset/threat_modeling.py
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,},},
)
],
)
1 change: 1 addition & 0 deletions setup.py
Original file line number Diff line number Diff line change
Expand Up @@ -94,6 +94,7 @@ class InstallException(Exception):
"dir = dffml.source.dir:DirectorySource",
"dataframe = dffml.source.dataframe:DataFrameSource",
"iris.training = dffml.source.dataset.iris:iris_training.source",
"owasp.threat-dragon = dffml.source.dataset.threat_modeling:threat_dragon.source",
],
"dffml.port": ["json = dffml.port.json:JSON"],
"dffml.service.cli": ["dev = dffml.service.dev:Develop"],
Expand Down

0 comments on commit 7969de3

Please sign in to comment.