|
13 | 13 | import trestle.tasks.csv_to_oscal_cd as csv_to_oscal_cd |
14 | 14 | from trestle.common.const import TRESTLE_GENERIC_NS |
15 | 15 | from trestle.tasks.csv_to_oscal_cd import ( |
| 16 | + CHECK_DESCRIPTION, |
| 17 | + CHECK_ID, |
16 | 18 | COMPONENT_DESCRIPTION, |
17 | 19 | COMPONENT_TITLE, |
18 | 20 | COMPONENT_TYPE, |
|
35 | 37 | ToRulesTransformer, |
36 | 38 | ) |
37 | 39 | from trestlebot.transformers.trestle_rule import ( |
| 40 | + Check, |
38 | 41 | ComponentInfo, |
39 | 42 | Control, |
40 | 43 | Parameter, |
@@ -65,13 +68,15 @@ def transform(self, row: Dict[str, str]) -> TrestleRule: |
65 | 68 | profile = self._extract_profile(row) |
66 | 69 | component_info = self._extract_component_info(row) |
67 | 70 | parameter = self._extract_parameter(row) |
| 71 | + check = self._extract_check(row) |
68 | 72 |
|
69 | 73 | return TrestleRule( |
70 | 74 | name=rule_info[const.NAME], |
71 | 75 | description=rule_info[const.DESCRIPTION], |
72 | 76 | component=component_info, |
73 | 77 | parameter=parameter, |
74 | 78 | profile=profile, |
| 79 | + check=check, |
75 | 80 | ) |
76 | 81 |
|
77 | 82 | def _extract_rule_info(self, row: Dict[str, str]) -> Dict[str, str]: |
@@ -106,6 +111,16 @@ def _extract_parameter(self, row: Dict[str, str]) -> Optional[Parameter]: |
106 | 111 | ) |
107 | 112 | return None |
108 | 113 |
|
| 114 | + def _extract_check(self, row: Dict[str, str]) -> Optional[Check]: |
| 115 | + """Extract check information from a CSV row.""" |
| 116 | + check_name = row.get(csv_to_oscal_cd.CHECK_ID, None) |
| 117 | + if check_name: |
| 118 | + return Check( |
| 119 | + name=check_name, |
| 120 | + description=row.get(csv_to_oscal_cd.CHECK_DESCRIPTION, ""), |
| 121 | + ) |
| 122 | + return None |
| 123 | + |
109 | 124 | def _extract_component_info(self, row: Dict[str, str]) -> ComponentInfo: |
110 | 125 | """Extract component information from a CSV row.""" |
111 | 126 | return ComponentInfo( |
@@ -141,6 +156,12 @@ def transform(self, rule: TrestleRule) -> Dict[str, str]: |
141 | 156 | } |
142 | 157 | if rule.parameter is not None: |
143 | 158 | merged_dict.update(self._add_parameter(rule.parameter)) |
| 159 | + if rule.check is not None: |
| 160 | + check: Dict[str, str] = { |
| 161 | + CHECK_ID: rule.check.name, |
| 162 | + CHECK_DESCRIPTION: rule.check.description, |
| 163 | + } |
| 164 | + merged_dict.update(check) |
144 | 165 | return merged_dict |
145 | 166 |
|
146 | 167 | def _add_profile(self, profile: Profile) -> Dict[str, str]: |
|
0 commit comments