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

Commit 7969de3

Browse files
committed
source: dataset: threat modeling: threat dragon: Initial source
Signed-off-by: John Andersen <[email protected]>
1 parent 9ddcdfd commit 7969de3

File tree

2 files changed

+44
-0
lines changed

2 files changed

+44
-0
lines changed
Lines changed: 43 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,43 @@
1+
import json
2+
import pathlib
3+
4+
from ...record import Record
5+
from ..memory import MemorySource
6+
from .base import dataset_source
7+
8+
9+
@dataset_source("owasp.threat-dragon")
10+
async def threat_dragon(
11+
filepath: pathlib.Path, feature_name: str = "threat_model",
12+
):
13+
r"""
14+
Examples
15+
--------
16+
17+
.. code-block:: console
18+
:test:
19+
20+
$ dffml list records -sources threat_model=owasp.threat-dragon \
21+
-source-threat_model-filepath /home/pdxjohnny/Documents/python/living-threat-models/models/good.json
22+
23+
>>> from dffml.noasync import load
24+
>>> from dffml import iris_training
25+
>>>
26+
>>> records = list(load(iris_training.source()))
27+
>>> print(len(records))
28+
120
29+
>>> records[0].export()
30+
{'key': '0', 'features': {'SepalLength': 6.4, 'SepalWidth': 2.8, 'PetalLength': 5.6, 'PetalWidth': 2.2, 'classification': 2}, 'extra': {}}
31+
"""
32+
contents = filepath.read_text()
33+
threat_model_dict = json.loads(contents)
34+
# TODO(security) Validate JSON schema
35+
title = threat_model_dict["summary"]["title"]
36+
yield MemorySource(
37+
records=[
38+
Record(
39+
key=title,
40+
data={"features": {feature_name: threat_model_dict,},},
41+
)
42+
],
43+
)

setup.py

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -94,6 +94,7 @@ class InstallException(Exception):
9494
"dir = dffml.source.dir:DirectorySource",
9595
"dataframe = dffml.source.dataframe:DataFrameSource",
9696
"iris.training = dffml.source.dataset.iris:iris_training.source",
97+
"owasp.threat-dragon = dffml.source.dataset.threat_modeling:threat_dragon.source",
9798
],
9899
"dffml.port": ["json = dffml.port.json:JSON"],
99100
"dffml.service.cli": ["dev = dffml.service.dev:Develop"],

0 commit comments

Comments
 (0)