fix: [tools] black everything

pull/1006/head v2.4.195
Alexandre Dulaunoy 2024-07-24 14:55:21 +02:00
parent 3b9bed803e
commit 4de82a78c8
No known key found for this signature in database
GPG Key ID: 09E2CD4944E6CBCD
1 changed files with 99 additions and 54 deletions

View File

@ -26,8 +26,12 @@ import csv
# uuidv4 generated to be concatenated in v5: 1d348708-7cd8-4854-9eac-f93c0dab8cdd # uuidv4 generated to be concatenated in v5: 1d348708-7cd8-4854-9eac-f93c0dab8cdd
parser = argparse.ArgumentParser(description='Create/update the NICE Framework Taxonomies based on the NICE Framework json file.') parser = argparse.ArgumentParser(
parser.add_argument("-p", "--path", required=True, help="Path to the NICE Framework json file") description='Create/update the NICE Framework Taxonomies based on the NICE Framework json file.'
)
parser.add_argument(
"-p", "--path", required=True, help="Path to the NICE Framework json file"
)
args = parser.parse_args() args = parser.parse_args()
@ -39,7 +43,9 @@ if not os.path.exists(os.path.join(os.path.dirname(__file__), "cybersecurity-opm
# create OPM description from OPM csv file as this data is missing from the NICE framework # create OPM description from OPM csv file as this data is missing from the NICE framework
with open(os.path.join(os.path.dirname(__file__), "cybersecurity-opm.csv"), newline='') as csvfile: with open(
os.path.join(os.path.dirname(__file__), "cybersecurity-opm.csv"), newline=''
) as csvfile:
opm = {} opm = {}
reader = csv.reader(csvfile, delimiter=',', quotechar="\"") reader = csv.reader(csvfile, delimiter=',', quotechar="\"")
for row in reader: for row in reader:
@ -56,7 +62,7 @@ galaxies = {
"description": "Work roles based on the NIST NICE framework", "description": "Work roles based on the NIST NICE framework",
"uuid": "10a2e9d7-781b-4ff4-bb3e-f0003108fe41", "uuid": "10a2e9d7-781b-4ff4-bb3e-f0003108fe41",
"version": 1, "version": 1,
"icon": 'user' "icon": 'user',
}, },
"skill": { "skill": {
"namespace": "nist-nice", "namespace": "nist-nice",
@ -65,7 +71,7 @@ galaxies = {
"description": "Skills based on the NIST NICE framework", "description": "Skills based on the NIST NICE framework",
"uuid": "96c5b9e7-5e70-479e-990c-8f1dea06c520", "uuid": "96c5b9e7-5e70-479e-990c-8f1dea06c520",
"version": 1, "version": 1,
"icon": 'user' "icon": 'user',
}, },
"task": { "task": {
"namespace": "nist-nice", "namespace": "nist-nice",
@ -74,7 +80,7 @@ galaxies = {
"description": "Tasks based on the NIST NICE framework", "description": "Tasks based on the NIST NICE framework",
"uuid": "98ba1aa3-d171-49e4-adf1-b7fb5e26a942", "uuid": "98ba1aa3-d171-49e4-adf1-b7fb5e26a942",
"version": 1, "version": 1,
"icon": 'user' "icon": 'user',
}, },
"knowledge": { "knowledge": {
"namespace": "nist-nice", "namespace": "nist-nice",
@ -83,7 +89,7 @@ galaxies = {
"description": "Knowledge based on the NIST NICE framework", "description": "Knowledge based on the NIST NICE framework",
"uuid": "de7e23f2-cef8-44ed-b209-b584f7da58a2", "uuid": "de7e23f2-cef8-44ed-b209-b584f7da58a2",
"version": 1, "version": 1,
"icon": 'user' "icon": 'user',
}, },
"competency_area": { "competency_area": {
"namespace": "nist-nice", "namespace": "nist-nice",
@ -92,7 +98,7 @@ galaxies = {
"description": "Competency areas based on the NIST NICE framework", "description": "Competency areas based on the NIST NICE framework",
"uuid": "e78357aa-01bd-4635-99a1-8eb860fa3bd5", "uuid": "e78357aa-01bd-4635-99a1-8eb860fa3bd5",
"version": 1, "version": 1,
"icon": 'user' "icon": 'user',
}, },
"opm_code": { "opm_code": {
"namespace": "nist-nice", "namespace": "nist-nice",
@ -101,8 +107,8 @@ galaxies = {
"description": "Office of Personnel Management codes in cybersecurity", "description": "Office of Personnel Management codes in cybersecurity",
"uuid": "2c56dfbc-82a5-48db-aea4-854ede951c65", "uuid": "2c56dfbc-82a5-48db-aea4-854ede951c65",
"version": 1, "version": 1,
"icon": 'user' "icon": 'user',
} },
} }
clusters = { clusters = {
@ -115,7 +121,7 @@ clusters = {
"uuid": "f81819e1-326b-41a5-89dd-a40d73c5bbbf", "uuid": "f81819e1-326b-41a5-89dd-a40d73c5bbbf",
'source': '', 'source': '',
'values': [], 'values': [],
'version': 1 'version': 1,
}, },
"skill": { "skill": {
'authors': ["NIST", "Jean-Louis Huynen"], 'authors': ["NIST", "Jean-Louis Huynen"],
@ -126,7 +132,7 @@ clusters = {
"uuid": "2d330f93-fa49-4451-859a-aacc68c63110", "uuid": "2d330f93-fa49-4451-859a-aacc68c63110",
'source': '', 'source': '',
'values': [], 'values': [],
'version': 1 'version': 1,
}, },
"task": { "task": {
'authors': ["NIST", "Jean-Louis Huynen"], 'authors': ["NIST", "Jean-Louis Huynen"],
@ -137,7 +143,7 @@ clusters = {
"uuid": "6bcf78de-a3fb-4636-90bc-95a86817ad65", "uuid": "6bcf78de-a3fb-4636-90bc-95a86817ad65",
'source': '', 'source': '',
'values': [], 'values': [],
'version': 1 'version': 1,
}, },
"knowledge": { "knowledge": {
'authors': ["NIST", "Jean-Louis Huynen"], 'authors': ["NIST", "Jean-Louis Huynen"],
@ -148,7 +154,7 @@ clusters = {
"uuid": "796e3e82-ca9a-4749-8421-4810ed440755", "uuid": "796e3e82-ca9a-4749-8421-4810ed440755",
'source': '', 'source': '',
'values': [], 'values': [],
'version': 1 'version': 1,
}, },
"competency_area": { "competency_area": {
'authors': ["NIST", "Jean-Louis Huynen"], 'authors': ["NIST", "Jean-Louis Huynen"],
@ -159,7 +165,7 @@ clusters = {
"uuid": "91696bc7-ede9-4875-8814-768bd5c99c66", "uuid": "91696bc7-ede9-4875-8814-768bd5c99c66",
'source': '', 'source': '',
'values': [], 'values': [],
'version': 1 'version': 1,
}, },
"opm_code": { "opm_code": {
'authors': ["OPM", "Jean-Louis Huynen"], 'authors': ["OPM", "Jean-Louis Huynen"],
@ -170,18 +176,26 @@ clusters = {
"uuid": "76772dae-0e98-4d96-8603-6993aea936d1", "uuid": "76772dae-0e98-4d96-8603-6993aea936d1",
'source': 'https://dw.opm.gov/datastandards/referenceData/2273/current', 'source': 'https://dw.opm.gov/datastandards/referenceData/2273/current',
'values': [], 'values': [],
'version': 1 'version': 1,
} },
} }
def get_relationships(nice_data, external_id): def get_relationships(nice_data, external_id):
relationships = [] relationships = []
for element in nice_data["response"]["elements"]["relationships"]: for element in nice_data["response"]["elements"]["relationships"]:
if element["source_element_identifier"] == external_id: if element["source_element_identifier"] == external_id:
relationships.append({ relationships.append(
"dest-uuid": str(uuid.uuid5(uuid.UUID("1d348708-7cd8-4854-9eac-f93c0dab8cdd"), element["dest_element_identifier"])), {
"type": "involves" "dest-uuid": str(
}) uuid.uuid5(
uuid.UUID("1d348708-7cd8-4854-9eac-f93c0dab8cdd"),
element["dest_element_identifier"],
)
),
"type": "involves",
}
)
return relationships return relationships
@ -203,7 +217,12 @@ with open(args.path) as f:
for element in nice_data["response"]["elements"]["elements"]: for element in nice_data["response"]["elements"]["elements"]:
# Defining a uuidd v5 identifier # Defining a uuidd v5 identifier
uuid_str = str(uuid.uuid5(uuid.UUID("1d348708-7cd8-4854-9eac-f93c0dab8cdd"),element["element_identifier"])) uuid_str = str(
uuid.uuid5(
uuid.UUID("1d348708-7cd8-4854-9eac-f93c0dab8cdd"),
element["element_identifier"],
)
)
# generating relationship # generating relationship
relationships = get_relationships(nice_data, element["element_identifier"]) relationships = get_relationships(nice_data, element["element_identifier"])
@ -213,30 +232,56 @@ with open(args.path) as f:
# Adding values in corresponding cluster # Adding values in corresponding cluster
if element["element_type"] in g: if element["element_type"] in g:
if element["element_type"] == "opm_code": if element["element_type"] == "opm_code":
clusters[element["element_type"]]["values"].append({ clusters[element["element_type"]]["values"].append(
{
"description": opm[element["element_identifier"]], "description": opm[element["element_identifier"]],
"uuid": uuid_str, "uuid": uuid_str,
"value": f'{opm[element["element_identifier"]][0:150]} - {element["element_identifier"]}', "value": f'{opm[element["element_identifier"]][0:150]} - {element["element_identifier"]}',
"related": relationships, "related": relationships,
}) }
)
else: else:
clusters[element["element_type"]]["values"].append({ clusters[element["element_type"]]["values"].append(
{
"description": element["text"], "description": element["text"],
"uuid": uuid_str, "uuid": uuid_str,
"value": element["element_identifier"], "value": element["element_identifier"],
"value": f'{element["text"][0:150]} - {element["element_identifier"]}', "value": f'{element["text"][0:150]} - {element["element_identifier"]}',
"related": relationships "related": relationships,
}) }
)
# Writing galaxies and clusters # Writing galaxies and clusters
for e in g: for e in g:
with open(os.path.join(os.path.dirname(__file__), '..', '..', 'galaxies', f'nice-framework-{e}s.json'), 'w') as f: with open(
os.path.join(
os.path.dirname(__file__),
'..',
'..',
'galaxies',
f'nice-framework-{e}s.json',
),
'w',
) as f:
json.dump(galaxies[e], f, indent=2, sort_keys=True, ensure_ascii=False) json.dump(galaxies[e], f, indent=2, sort_keys=True, ensure_ascii=False)
f.write('\n') # only needed for the beauty and to be compliant with jq_all_the_things f.write(
'\n'
) # only needed for the beauty and to be compliant with jq_all_the_things
with open(os.path.join(os.path.dirname(__file__), '..', '..', 'clusters', f'nice-framework-{e}s.json'), 'w') as f: with open(
os.path.join(
os.path.dirname(__file__),
'..',
'..',
'clusters',
f'nice-framework-{e}s.json',
),
'w',
) as f:
json.dump(clusters[e], f, indent=2, sort_keys=True, ensure_ascii=False) json.dump(clusters[e], f, indent=2, sort_keys=True, ensure_ascii=False)
f.write('\n') # only needed for the beauty and to be compliant with jq_all_the_things f.write(
'\n'
) # only needed for the beauty and to be compliant with jq_all_the_things
print(f'{len(g)*2} file created:') print(f'{len(g)*2} file created:')
for e in g: for e in g: