Skip to content

Commit 9d36821

Browse files
committed
Introducing EmptyElement to avoid showing "invalid" elements on diagrams
- added EmptyElement - skipped generation EmptyElement on DFD and SEQ diagrams
1 parent 4890300 commit 9d36821

File tree

3 files changed

+22
-2
lines changed

3 files changed

+22
-2
lines changed

pytm/pytm.py

Lines changed: 14 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -685,7 +685,7 @@ def __init__(
685685
if args:
686686
element = args[0]
687687
else:
688-
element = kwargs.pop("element", Element("invalid"))
688+
element = kwargs.pop("element", EmptyElement())
689689

690690
self.target = element.name
691691
self.element = element
@@ -1016,7 +1016,7 @@ def seq(self):
10161016
participants.append(
10171017
'database {0} as "{1}"'.format(e._uniq_name(), e.display_name())
10181018
)
1019-
elif not isinstance(e, Dataflow) and not isinstance(e, Boundary):
1019+
elif not isinstance(e, (Dataflow, Boundary, EmptyElement)):
10201020
participants.append(
10211021
'entity {0} as "{1}"'.format(e._uniq_name(), e.display_name())
10221022
)
@@ -1583,6 +1583,18 @@ def _safeset(self, attr, value):
15831583
pass
15841584

15851585

1586+
class EmptyElement(Element):
1587+
"""An empty element to avoid generation of elements for standalone Finding"""
1588+
1589+
def __init__(self):
1590+
super().__init__("AutoGenerated", description="Autogenerated element for Finding")
1591+
# This type is used as a part of manual created Finding
1592+
# and is not a component of data flows described by users
1593+
# That why it has not be drawn on diagrams
1594+
# To do this just mark it as already drawn
1595+
self._is_drawn = True # Prevent drawing on diagrams
1596+
1597+
15861598
class Asset(Element):
15871599
"""An asset with outgoing or incoming dataflows"""
15881600

tests/test_pytmfunc.py

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -58,6 +58,8 @@ def test_seq(self):
5858
Dataflow(db, web, "Retrieve comments")
5959
Dataflow(web, user, "Show comments (*)")
6060

61+
Finding() # Finding with an empty element
62+
6163
self.assertTrue(tm.check())
6264
output = tm.seq()
6365

tm.py

Lines changed: 6 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -11,6 +11,7 @@
1111
Lambda,
1212
Server,
1313
DatastoreType,
14+
Finding,
1415
)
1516

1617
tm = TM("my test tm")
@@ -59,6 +60,10 @@
5960
secretDb.storesPII = True
6061
secretDb.maxClassification = Classification.TOP_SECRET
6162

63+
finding_to_overwrite = Finding(
64+
threat_id="DO01", example="API Gateway is used to check and limit requests",
65+
)
66+
6267
my_lambda = Lambda("AWS Lambda")
6368
my_lambda.controls.hasAccessControl = True
6469
my_lambda.inBoundary = vpc
@@ -100,6 +105,7 @@
100105
db_to_web.dstPort = 80
101106
db_to_web.data = comment_retrieved
102107
db_to_web.responseTo = web_to_db
108+
db_to_web.overrides = [finding_to_overwrite]
103109

104110
comment_to_show = Data(
105111
"Web server shows comments to the end user", classifcation=Classification.PUBLIC

0 commit comments

Comments
 (0)