Skip to content

Commit

Permalink
write parsed data to csvs
Browse files Browse the repository at this point in the history
  • Loading branch information
Eva committed Sep 29, 2023
1 parent a514fb7 commit 3e7d76f
Show file tree
Hide file tree
Showing 424 changed files with 127,609 additions and 4,894 deletions.
67 changes: 53 additions & 14 deletions src/mappings_explorer/cli/cli.py
Original file line number Diff line number Diff line change
Expand Up @@ -98,26 +98,18 @@ def parse_cve_mappings():
datareader = read_csv_file(cve_filepath)
parsed_mappings = configure_cve_mappings(datareader, attack_object_id_to_name)

parsed_mappings_filepath = (
filepath = (
f"{ROOT_DIR}/src/mappings_explorer/cli/parsed_mappings/cve/parsed_cve_mappings"
)

# write parsed mappings to yaml file
result_yaml_file = open(
f"{parsed_mappings_filepath}.yaml",
"w",
encoding="UTF-8",
)
parsed_mappings_yaml = yaml.dump(parsed_mappings)
result_yaml_file.write(parsed_mappings_yaml)
write_parsed_mappings_yaml(parsed_mappings, filepath)

# write parsed mappings to json file
result_json_file = open(
f"{parsed_mappings_filepath}.json",
"w",
encoding="UTF-8",
)
json.dump(parsed_mappings, fp=result_json_file)
write_parsed_mappings_json(parsed_mappings, filepath)

# write parsed mappings to csv file
write_parsed_mappings_csv(parsed_mappings, filepath)


def read_csv_file(filepath):
Expand Down Expand Up @@ -165,6 +157,9 @@ def parse_nist_mappings():
# write parsed mappings to json file
write_parsed_mappings_json(parsed_mappings, filepath)

# write parsed mappings to csv file
write_parsed_mappings_csv(parsed_mappings, filepath)


def read_excel_file(filepath):
df = pd.read_excel(filepath)
Expand Down Expand Up @@ -196,6 +191,9 @@ def parse_veris_mappings():
# write parsed mappings to json file
write_parsed_mappings_json(parsed_mappings, filepath)

# write parsed mappings to csv file
write_parsed_mappings_csv(parsed_mappings, filepath)


def read_json_file(filepath):
with open(filepath, encoding="UTF-8") as user_file:
Expand Down Expand Up @@ -230,6 +228,9 @@ def parse_security_stack_mappings():
# write parsed data to a json file
write_parsed_mappings_json(parsed_mappings, filepath)

# write parsed mappings to csv file
write_parsed_mappings_csv(parsed_mappings, filepath)


def read_yaml(filepath):
with open(filepath, encoding="UTF-8") as file:
Expand All @@ -253,3 +254,41 @@ def write_parsed_mappings_json(parsed_mappings, filepath):
encoding="UTF-8",
)
json.dump(parsed_mappings, fp=result_json_file)


def write_parsed_mappings_csv(parsed_mappings, filepath):
metatdata_objects = []
attack_objects = []
mapping_platform_objects = []
for index, mapping in enumerate(parsed_mappings):
# metadata object
metadata_object = mapping["metadata"]
metadata_object["key"] = index
metatdata_objects.append(metadata_object)

# attack object
attack_object = mapping["attack-object"]
attack_object["metadata-key"] = index
attack_object["key"] = index
# mapping platform will be its own table and will not be
# part of attack_object
exclude_keys = ["mapping-platform"]
attack_object = {
k: attack_object[k]
for k in set(list(attack_object.keys())) - set(exclude_keys)
}
attack_objects.append(attack_object)

# mapping platform object
mapping_platform_object = mapping["attack-object"]["mapping-platform"]
mapping_platform_object["attack-object-key"] = index
mapping_platform_objects.append(mapping_platform_object)

metadata_df = pd.DataFrame(metatdata_objects)
metadata_df.to_csv(f"{filepath}_metadata.csv")

attack_object_df = pd.DataFrame(attack_objects)
attack_object_df.to_csv(f"{filepath}_attack-objects.csv")

mapping_platform_df = pd.DataFrame(mapping_platform_objects)
mapping_platform_df.to_csv(f"{filepath}_mapping-platforms.csv")
4 changes: 2 additions & 2 deletions src/mappings_explorer/cli/parse_veris_mappings.py
Original file line number Diff line number Diff line change
Expand Up @@ -31,8 +31,8 @@ def configure_veris_mappings(veris_mappings, domain):
"mapping-description": "",
"mapping-target": veris_object,
"mapping-platform": {
"relationship-type": "",
"date-delivered": "",
"relationship-type": "related-to",
"veris-path": veris_object,
},
},
}
Expand Down

Large diffs are not rendered by default.

Large diffs are not rendered by default.

Large diffs are not rendered by default.

Large diffs are not rendered by default.

Large diffs are not rendered by default.

Large diffs are not rendered by default.

Large diffs are not rendered by default.

Large diffs are not rendered by default.

Large diffs are not rendered by default.

Large diffs are not rendered by default.

Large diffs are not rendered by default.

Large diffs are not rendered by default.

Large diffs are not rendered by default.

Large diffs are not rendered by default.

Large diffs are not rendered by default.

Large diffs are not rendered by default.

Large diffs are not rendered by default.

Loading

0 comments on commit 3e7d76f

Please sign in to comment.