Skip to content

Commit

Permalink
Patching .gitignore
Browse files Browse the repository at this point in the history
  • Loading branch information
Louie Simpson committed Mar 8, 2019
2 parents 7393dfc + a546b1d commit b205292
Show file tree
Hide file tree
Showing 2 changed files with 8,761 additions and 8 deletions.
72 changes: 64 additions & 8 deletions cleanup_csv.py
Original file line number Diff line number Diff line change
Expand Up @@ -20,6 +20,42 @@ def find_control_by_id(id):
if control == id:
return control

def find_control_description(input_text):

#print("Looking for everything from beginning to supplemental guidance")
control_description = ""
if("supplemental guidance" in input_text.lower()):

m = re.split("Supplemental Guidance:", input_text, re.IGNORECASE)
if(m):
#print("Found control description ", m[0])
control_description = m[0]
else:
control_description = input_text

return control_description

def find_supp_guidance(input_text):
supp_guidance = ""
if("supplemental guidance" in input_text.lower()):
m = re.split("Supplemental Guidance:", input_text, re.IGNORECASE)
if(m[1]):
g = re.split("Related control(s)?:", m[1], re.IGNORECASE)
supp_guidance = g[0]


return supp_guidance

def extract_related_controls(input_text):
matches = []
if("related control" in input_text.lower()):

m = re.search("related control[s]?:([^\.]+)\.", input_text.lower())
if(m):
raw = m.groups(0)[0].replace(" ", "")
matches = raw.split(",")

return matches

controls = {'Controls': {}}
idx = 0
Expand All @@ -31,7 +67,7 @@ def find_control_by_id(id):
for row in reader:
foo = []


params = {}
is_enhancement = False
#Id we are on top row skip to next
if row['ID'] == 'ID':
Expand All @@ -48,39 +84,59 @@ def find_control_by_id(id):
control = {}

te = find_enhancement_by_control_id(row['ID'])

#If there is an enancement we need to get the parent control
parameter_string = row['Parameters'].strip()
if is_enhancement:
if te:
te['Impacts'].append(file['Impact'])
if parameter_string:
te['Parameters'].append({"Level": file['Impact'], "Param": row['Parameters']})
else:
enhancement = {
"ID": row["ID"],
"ControlText": row['Control Description'],
"ControlText": find_control_description(row['Control Description']),
"Impacts": [file['Impact']],
"FedrampGuidance": row['Further Guidance'].strip()
"SupplementalGuidance": find_supp_guidance(row['Control Description']),
"RelatedControls": extract_related_controls(row['Control Description']),
"FedrampGuidance": row['Further Guidance'].strip(),
"Parameters": []
}
if (parameter_string):
enhancement['Parameters'].append({"Level": file['Impact'], "Param": row['Parameters']})


if controls['Controls'][tc]:
controls['Controls'][tc]["Enhancements"].append(enhancement)

is_enhancement = False
else:
if tc:
#If we just need add all the params for each impact
controls['Controls'][tc]['Impacts'].append(file['Impact'])
if parameter_string:
controls['Controls'][tc]['Parameters'].append({"Level": file['Impact'], "Param": row['Parameters']})

else:
params[file['Impact']] = row['Parameters']
control = {
"ID": row["ID"],
"TITLE": row['Control Name'],
"ControlText": row['Control Description'],
"Family": row["Family"],
"ControlText": find_control_description(row['Control Description']),
"Impacts": [file['Impact']],
"Enhancements": [],
"FedrampGuidance": row['Further Guidance'].strip()
"RelatedControls": extract_related_controls(row['Control Description']),
"SupplementalGuidance": find_supp_guidance(row['Control Description']),
"FedrampGuidance": row['Further Guidance'].strip(),
"Parameters": []
}
if(parameter_string):
control['Parameters'].append({"Level": file['Impact'], "Param": row['Parameters']})
controls['Controls'][row["ID"]] = control

output_struct = {"Controls": []}
output_struct = []
for control in controls['Controls']:
output_struct['Controls'].append(controls['Controls'][control])
output_struct.append(controls['Controls'][control])

with open('./output/fedramp_controls.json', 'wb') as f:
json.dump(output_struct, codecs.getwriter('utf-8')(f), ensure_ascii=False)
Expand Down
Loading

0 comments on commit b205292

Please sign in to comment.