diff --git a/ERFormatConstants.py b/ERFormatConstants.py index cbbe74971c4fd91f07020a26cb57b4d6741e962f..a4b1609bf7ca1863194fb7f24377dd9b9073b6d3 100644 --- a/ERFormatConstants.py +++ b/ERFormatConstants.py @@ -21,14 +21,16 @@ textArea14 = "Text Area 14" textArea15 = "Text Area 15" textArea16 = "Text Area 16" + #Mapped fields for Threat component -Threat = textArea1 # The threat +Threat = "Threat" # The threat +ThreatValue = textArea1 # The threat ThreatID = textArea2 # The id of the threat ThreatIDValue = textArea3 # Value ThreatSource = textArea4 # The threat source -ThreatSource = textArea5 # Value +ThreatSourceValue = textArea5 # Value Likelihood = textArea6 # The likelihood of the threat LikelihoodValue = textArea7 # Value @@ -40,7 +42,8 @@ Vulnerability = textArea10 # The vulnerability VulnerabilityValue = textArea11 # Value #Consequence -Consequence = textArea1 # The consequence score of the area -> Text area 6 +Consequence = "Consequence" # The consequence score of the area -> Text area 6 +ConsequenceValue = textArea1 # The consequence ConsequenceID = textArea2 # The id of the consequence ConsequenceIDValue = textArea3 # Value @@ -55,7 +58,8 @@ AffectedComponent = textArea8 # The affected component AffectedComponentValue = textArea9 # Value #Attack -Attack = textArea1 # The attack +Attack = "Attack" # The attack +AttackValue = textArea1 # The attack AttackType = textArea2 # The type of attack AttackTypeValue = textArea3 # Value @@ -66,4 +70,13 @@ AttackedComponentValue = textArea5 # Value AttackDescription = textArea6 # The description of the attack AttackDescriptionValue = textArea7 # Value +#Dynamics +ThreatDynamic = "Threat Dynamics" # The dynamics + +ConsequenceDynamic = "Consequence Dynamics" # The dynamics + +AttackDynamic = "Attack Dynamics" # The dynamics + +Dynamics = "Dynamics" # The dynamics + diff --git a/diagramParser.py b/diagramParser.py index af009618fa300baa27be4dd5ca39f447c3304da3..c3049e27834f85afadc6d10600c022b2446a43e8 100644 --- a/diagramParser.py +++ b/diagramParser.py @@ -7,42 +7,69 @@ import dynamics as dynamic def parseDiagramFile(csvFile): df = pd.read_csv(csvFile) df.drop(["Shape Library", "Page ID", "Contained By", "Group", "Comments", "property 1"], axis=1, inplace=True) #Removing unecessary data - - print(df.head) - - - # List containing all threats and their descriptions - threats = [] + threats = {} + threats = parseThreats(df, threats) + print(threats) + print(len(threats)) + #List containing all consequences - consequences = [] + consequences = {} + consequences = parseConsequences(df, consequences) + print(consequences) + #List containing all metrics metrics = [] #List containing all attacks attacks = [] -def parseThreats(df): +def parseThreats(df, threatDict): for i in range(len(df)): - if df[const.textArea1][i] == const.Threat: - threat = component.Threat( - df[const.Id][i], # The id of the entity - df[const.componentID][i], # The component ID field provided by LucidChart - df[const.textArea4][i], - df[const.Description][i], - df[const.textArea6][i], - df[const.textArea7][i]) - + if df[const.ThreatValue][i] == const.Threat: #Creates threat object + + threat = component.Threat( + df[const.ThreatIDValue][i], # ID from ER + df[const.Id][i], # LucidChart ID + df[const.ThreatSourceValue][i], + df[const.ThreatDescriptionValue][i], + df[const.LikelihoodValue][i], + df[const.VulnerabilityValue][i] + ) + threatDict[df.Id[i]] = threat + + return threatDict + +#Parses consequences and adds it to dictionary +def parseConsequences(df, consequenceDict): + for i in range(len(df)): + if df[const.ConsequenceValue][i] == const.Consequence: + consequence = component.Consequence( + df[const.ConsequenceIDValue][i], + df[const.Id][i], + df[const.ConsequenceDescriptionValue][i], + df[const.ConsequenceScoreValue][i], + df[const.AffectedComponentValue][i] + ) + consequenceDict[df.Id[i]] = consequence + + return consequenceDict -def parseConsequences(df): +def parseAttacks(df, attackDict): for i in range(len(df)): - if df["Shape Type"][i] == "Consequence": - consequences.append(df["Name"][i]) - print(consequences) + if df[const.AttackValue][i] == const.Attack: + attack = component.Attack( + df[const.Id][i], + df[const.AttackedComponentValue][i], + df[const.AttackDescriptionValue][i], + ) + attackDict[df.Id[i]] = attack -def parseMetrics(df): + return attackDict + +#Parses metrics components and adds it to list +def parseDynamic(df, dynamicsDict): for i in range(len(df)): - if df["Shape Type"][i] == "Metric": - metrics.append(df["Name"][i]) - print(metrics) \ No newline at end of file + pass + \ No newline at end of file