Skip to content

Commit

Permalink
Further refactoring org defined param handling #1783
Browse files Browse the repository at this point in the history
  • Loading branch information
gregelin committed Nov 4, 2022
1 parent 6eeb3b1 commit 73faee8
Show file tree
Hide file tree
Showing 2 changed files with 5 additions and 16 deletions.
19 changes: 4 additions & 15 deletions controls/oscal.py
Original file line number Diff line number Diff line change
Expand Up @@ -124,7 +124,6 @@ def __init__(self, catalog_key='NIST_SP-800-53_rev4', parameter_values=dict()):
self.parameter_values = parameter_values
self.flattened_controls_all_as_dict = self.get_flattened_controls_all_as_dict()
self.flattened_controls_all_as_dict_list = self.get_flattened_controls_all_as_dict_list()
self.parameters_by_control = self._cache_parameters_by_control()

def _load_catalog_json(self):
"""Read catalog file - JSON"""
Expand Down Expand Up @@ -243,6 +242,8 @@ def get_guidance_related_links_text_by_value_in_href(self, control, value):
links_text = [ l['text'] for l in self.get_control_guidance_links(control) if l['rel']=="related" and value in l['href'] ]
return links_text

# Organizational Defined Parameters

def get_control_parameter_label_by_id(self, control, param_id):
"""Return value of a parameter of a control by id of parameter"""
param = self.find_dict_by_value(control['parameters'], "id", param_id)
Expand Down Expand Up @@ -287,6 +288,8 @@ def get_org_defined_parameter_by_id(self, parameter_id):
"""Return an organization defined parameter object dictionary by parameter id"""
return self.get_all_control_parameters_for_catalog()[parameter_id]

# Control prose

def get_control_prose_as_markdown(self, control_data, part_types={"statement"}, parameter_values=dict()):
# Concatenate the prose text of all of the 'parts' of this control
# in Markdown. Filter out the parts that are not wanted.
Expand Down Expand Up @@ -473,17 +476,3 @@ def get_flattened_controls_all_as_dict_list(self):
cl_all_list.append(cl_dict)
return cl_all_list

def _cache_parameters_by_control(self):
cache = defaultdict(list)
if self.oscal:
groups = self.oscal["groups"]
for family in groups:
for control in family["controls"]:
control_id = control["id"]
for parameter in control.get("parameters", []):
cache[control_id].append(parameter["id"])
return dict(cache)

def get_parameter_ids_for_control(self, control_id):
return self.parameters_by_control.get(control_id, [])

2 changes: 1 addition & 1 deletion guidedmodules/module_logic.py
Original file line number Diff line number Diff line change
Expand Up @@ -343,7 +343,7 @@ def _component(e):
"statements": []
}

param_ids = catalog.get_parameter_ids_for_control(control_id)
param_ids = catalog.get_control_parameter_ids_by_control_id(control_id)
ir["parameter_settings"] = [
dict(param_id=param_id, value=params.get(param_id))
for param_id in param_ids
Expand Down

0 comments on commit 73faee8

Please sign in to comment.