Skip to content

Commit 2eba447

Browse files
authored
Merge pull request #257 from kxynos/master
Update README.md
2 parents e96ee5f + 69d38af commit 2eba447

File tree

1 file changed

+41
-0
lines changed

1 file changed

+41
-0
lines changed

README.md

Lines changed: 41 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -365,6 +365,47 @@ the `target.input` and `target.output` attributes. For example, to match a threa
365365
servers with incoming traffic, use `any(target.inputs)`. A more advanced example,
366366
matching elements connecting to SQL datastores, would be `any(f.sink.oneOf(Datastore) and f.sink.isSQL for f in target.outputs)`.
367367

368+
## Importing from JSON
369+
370+
With a little bit of Python code it is possible to import a threat model from JSON (notice the special format in the exmaple found in `tests/input.json`). The following example imports the `input.json` example found in tests. Save the following code as `tm2.py`.
371+
372+
```python
373+
374+
#!/usr/bin/env python3
375+
# Example tm2.py contents
376+
# Run: python tm2.py --dfd | dot -Tpng -o sample_json.png
377+
378+
from pytm import (
379+
TM,
380+
Actor,
381+
Boundary,
382+
Classification,
383+
Data,
384+
Dataflow,
385+
Datastore,
386+
Lambda,
387+
Server,
388+
DatastoreType,
389+
Assumption,
390+
load,
391+
)
392+
393+
json_file_string = './tests/input.json'
394+
with open(json_file_string) as input_json:
395+
TM.reset()
396+
tm = load(input_json)
397+
tm.process()
398+
399+
```
400+
401+
We can call `tm2.py` the same way as we did before, here with `--dfd` and then redirect the output to Graphviz (`dot`):
402+
403+
```bash
404+
405+
python tm2.py --dfd | dot -Tpng -o sample_json.png
406+
407+
```
408+
368409
## Making slides!
369410

370411
Once a threat model is done and ready, the dreaded presentation stage comes in - and now pytm can help you there as well, with a template that expresses your threat model in slides, using the power of (RevealMD)[https://github.com/webpro/reveal-md]! Just use the template docs/revealjs.md and you will get some pretty slides, fully configurable, that you can present and share from your browser.

0 commit comments

Comments
 (0)