diff --git a/ERFormatConstants.py b/ERFormatConstants.py index 229bf92f42ca8ab5a175827a8768ba0801b59fee..a53c47ac44c34440b28ba3897f2d794d2e851fc4 100644 --- a/ERFormatConstants.py +++ b/ERFormatConstants.py @@ -1,7 +1,6 @@ #File contains constants from the CSV export format of the entity relationship tool #Generic fields for all rows in the CSV file -componentID = "Id" # LucidChart ID Id = "Id" # The id of the entity textArea1 = "Text Area 1" @@ -76,3 +75,4 @@ ThreatDynamic = "Threat" # The threat dynamics ConsequenceDynamic = "Consequence" # The consequence dynamics AttackDynamic = "Attack" # The attack dynamics ERDynamic = "ER" # The ER dynamics +BowtieDynamicType = textArea3 # The bowtie dynamics diff --git a/diagramParser.py b/diagramParser.py index 8bcd1ab7170051e6544317be2191f580ba903d5d..891b42344f40680142735da7a6a316cb25b6935a 100644 --- a/diagramParser.py +++ b/diagramParser.py @@ -21,6 +21,7 @@ def parseDiagramFile(csvFile): #List containing all attacks attacks = [] + parseDynamic(df) @@ -68,29 +69,46 @@ def parseAttacks(df, attackDict): return attackDict #Parses metrics components and adds it to list -def parseDynamic(df): +def parseDynamic(df, metricList): for i in range(len(df)): # Iterates through the dataframe if df[const.textArea1][i] == const.Dynamics: # If the component is a dynamic component if df[const.textArea3][i] == const.ThreatDynamic: # If the dynamic component is a threat - print("Found threat dynamic") + threatDynamic = dynamic.BowtieDynamic( + df[const.Id][i], # Component ID LucidChart + df[const.textArea3][i] + ) + extractMetrics(df, i, 4) + + elif df[const.textArea3][i] == const.ConsequenceDynamic: - print("Found consequence dynamic") - elif df[const.textArea3][i] == const.AttackDynamic: - print("Found attack dynamic") + consequenceDynamic = dynamic.BowtieDynamic() + extractMetrics(df, i, 4) + elif df[const.textArea3][i] == const.AttackDynamic: + attackDynamic = dynamic.BowtieDynamic() + extractMetrics(df, i, 4) + elif df[const.textArea3][i] == const.ERDynamic: - print("Found ER dynamic") - - for j in range(8, len(df.columns),2): # Parse all text areas to find metrics - metric = "Text Area "+str(j) - metricDescription = "Text Area "+str(j+1) - if pd.isnull(df[metric][i]) == False: # If the text area is not - print(df["Id"][i]) - print(f"Found Metric with type: {df[metric][i]}") - print(f"Metric description: {df[metricDescription][i]}") - else: - break # First empty field indicates no more metrics + erDynamic = dynamic.ERDynamic() + extractMetrics(df, i, 8) + +def extractMetrics(df, index, startRange, metricList): + for j in range(startRange, len(df.columns),2): # Parse all text areas to find metrics + metricID = "Text Area "+str(j) + metricName = "Text Area "+str(j+1) + + if pd.isnull(df[metric][index]) == False: # If the text area is not empty + print("Metric: ID", df[metricID][index], "Name: ", df[metricName][index]) + metric = dynamic.Metric(df[metricID][index], df[metricName][index]) + metricList.append(metric) + else: + j=0 + break # First empty field indicates no more metrics + + return metricList # Returns metric found in the dynamic component + + diff --git a/dynamics.py b/dynamics.py index 851d688a76a67aaad01400541a66883cf3d54aa3..d5d442de851d4bbf0e156b60744068d8308abaeb 100644 --- a/dynamics.py +++ b/dynamics.py @@ -3,7 +3,7 @@ import logging as log # Dynamics class parent class for both the bowtie dynamics and the architecture dynamics class DynamicComponent: - def __init__(self, componentID, type) -> None: + def __init__(self, componentID) -> None: self.componentID = componentID self.metrics = [Metric] # List of metrics for the dynamic self.DynamicsRow = None # The row in the dynamics table the dynamic is associated with @@ -39,18 +39,25 @@ class DynamicComponent: #Metric class, will be used for all dynamics class Metric: - def __init__(self, name, type, description) -> None: + def __init__(self, ID, name) -> None: + + #Metrics found in the dynamics tables + self.ID = ID # ID of the metric used to locate in dynamics matrics self.name = name # Name of the metric - self.description = description # Description of the metric - self.type = type # Four types of dynamic metrics: process, devteam, opensource and vendor + + + # Metrics found in the metric table + + def __str__(self) -> str: return f"Metric: {self.name}, {self.description}" class BowtieDynamic(DynamicComponent): def __init__(self, componentID, type) -> None: - super().__init__(componentID, type) + super().__init__(componentID) + self.type = type # Type of dynamicM self.associatedThreat = None # List of threats associated with the dynamic self.associatedAttack = None # List of attacks associated with the dynamic diff --git a/tempCodeRunnerFile.py b/tempCodeRunnerFile.py new file mode 100644 index 0000000000000000000000000000000000000000..597a6db294cb721d184d6f12560dfa9e8a67de33 --- /dev/null +++ b/tempCodeRunnerFile.py @@ -0,0 +1 @@ +i \ No newline at end of file