From fbf822a7987a35a8ffd0e9eb13ff77675f9162a1 Mon Sep 17 00:00:00 2001 From: Lou DeGenaro Date: Wed, 4 Dec 2024 13:41:26 -0500 Subject: [PATCH] Fix sonar code smells Signed-off-by: Lou DeGenaro --- trestle/tasks/cis_xlsx_to_oscal_cd.py | 36 +++++++++++++++------------ 1 file changed, 20 insertions(+), 16 deletions(-) diff --git a/trestle/tasks/cis_xlsx_to_oscal_cd.py b/trestle/tasks/cis_xlsx_to_oscal_cd.py index 6e7c7cd9b..e52474e4b 100644 --- a/trestle/tasks/cis_xlsx_to_oscal_cd.py +++ b/trestle/tasks/cis_xlsx_to_oscal_cd.py @@ -752,8 +752,24 @@ def heading_row_2(self) -> None: self.row_names.append(name) self.row_descs.append(name) - def additional_user_columns(self) -> None: - """Additional user columns.""" + def _get_ctl_list(self, prev_row: int, curr_row: int) -> List[str]: + """Get_ctl_list.""" + # if merged row, list is empty + if self.merge_row(prev_row, curr_row): + ctl_list = [] + else: + # if non-rule row, list is empty + rec_no = self.get(curr_row, head_recommendation_no) + if rec_no is None: + ctl_list = [] + else: + # get list + cis_controls = self.get(curr_row, 'CIS Controls') + cis_control_helper = CisControlsHelper(cis_controls) + ctl_list = cis_control_helper.get_ctl_list( + self._benchmark_control_prefix, self.config_object['profile-version'] + ) + return ctl_list def run(self) -> None: """Run.""" @@ -775,20 +791,8 @@ def run(self) -> None: # process each data row of CIS Benchmark file prev_row = None for curr_row in self.row_generator(): - # if merged row, continue - if self.merge_row(prev_row, curr_row): - continue - # account for non-rule row: - rec_no = self.get(curr_row, head_recommendation_no) - if rec_no is None: - continue - # skip if no controls found - cis_controls = self.get(curr_row, 'CIS Controls') - cis_control_helper = CisControlsHelper(cis_controls) - ctl_list = cis_control_helper.get_ctl_list( - self._benchmark_control_prefix, self.config_object['profile-version'] - ) - if not len(ctl_list): + ctl_list = self._get_ctl_list(prev_row, curr_row) + if not ctl_list: continue # create new row self.csv_row_mgr = CsvRowMgr(self.row_names)