diff --git a/diagramParser.py b/diagramParser.py index 4b853302b89d322e5db0f6bfe838220fbac84d9d..af6f1bf4a777c16ab0d81cd9cde4de932492e3bd 100644 --- a/diagramParser.py +++ b/diagramParser.py @@ -86,6 +86,7 @@ def parseDynamic(df, metricList): joinMetrcs(threatDynamic.metrics, metricList) # Adds the metrics to the global metric list threatDynamic.associateBowtie(df, threatDynamic.type) # Associate the dynamic with the correct components + print(threatDynamic, "\n") elif df[const.textArea3][i] == const.ConsequenceDynamic: consequenceDynamic = dynamic.BowtieDynamic( @@ -94,7 +95,8 @@ def parseDynamic(df, metricList): ) consequenceDynamic.metrics = extractMetrics(df, i, 4) # Extracts metrics from the dynamic component joinMetrcs(threatDynamic.metrics, metricList) # Adds the metrics to the global metric list - consequenceDynamic.associateBowtie(df, consequenceDynamic.type) # Associate the dynamic with the correct components + consequenceDynamic.associateBowtie(df, consequenceDynamic.type) + print(consequenceDynamic, "\n")# Associate the dynamic with the correct components elif df[const.textArea3][i] == const.AttackDynamic: @@ -105,7 +107,7 @@ def parseDynamic(df, metricList): attackDynamic.metrics = extractMetrics(df, i, 4) joinMetrcs(threatDynamic.metrics, metricList) # Adds the metrics to the global metric list attackDynamic.associateBowtie(df,attackDynamic.type) # Associate the dynamic with the correct components - + print(attackDynamic, "\n") elif df[const.textArea3][i] == const.ERDynamic: erDynamic = dynamic.ERDynamic( @@ -115,7 +117,8 @@ def parseDynamic(df, metricList): ) erDynamic.metrics = extractMetrics(df, i, 8) joinMetrcs(threatDynamic.metrics, metricList) # Adds the metrics to the global metric list - #erDynamic.associatedERComponents(df) + erDynamic.associatER(df) + print(erDynamic , "\n") def extractMetrics(df, index, startRange): diff --git a/dynamics.py b/dynamics.py index b77cc346ad4dd0ec115c87f7fff653d3afbbac12..8ca86270793c594b3bd77ebff181c9326b17a389 100644 --- a/dynamics.py +++ b/dynamics.py @@ -39,6 +39,16 @@ class BowtieDynamic(DynamicComponent): self.associatedAttack = None # Attack associated with the dynamic self.associatedConsequence = None # Consequence associated with the dynamic + + def __str__(self) -> str: + if self.type == const.ThreatDynamic: + return super().__str__() + f"Associated threat ID: {self.associatedThreat[const.Id].item()} Associated attack ID {(self.associatedAttack[const.Id].item())}" + elif self.type == const.ConsequenceDynamic: + return super().__str__() + f"Associated consequence ID: {self.associatedConsequence[const.Id].item()} Assocaited attack ID:{(self.associatedAttack[const.Id].item())}" + elif self.type == const.AttackDynamic: + return super().__str__() + f"Associated attack ID: {self.associatedAttack[const.Id].item()}" + + """_summary_ Handles the associated dynamics for the bowtie model as they are different from the ER model ER model has one type of dynamic component with metrics however, the bowtie model has three dynamic types and needs more parsing @@ -93,14 +103,6 @@ class BowtieDynamic(DynamicComponent): self.associatedAttack = sourceComponent - - - - - - - - class ERDynamic(DynamicComponent): def __init__(self, componentID, type, description) -> None: super().__init__(componentID) @@ -109,6 +111,8 @@ class ERDynamic(DynamicComponent): self.associatedERComponents = [] # Associated ER component self.type = type + def __str__(self) -> str: + return super().__str__() + f"ER Dynamic: {self.type}, {self.description}, Amount of associated components {len(self.associatedERComponents)}" """_summary_ Function will use the dynamic component ID to find linked threats, ER components, attacks and consequences