Skip to content

Commit

Permalink
Add all .csv fields to the generated oscal
Browse files Browse the repository at this point in the history
Include all of the .csv fields in the generated oscal by using a list of
properties under each control.

Signed-off-by: Donald Hunter <[email protected]>
  • Loading branch information
donaldh committed May 10, 2024
1 parent 3dc0a6f commit 946fa60
Showing 1 changed file with 25 additions and 3 deletions.
28 changes: 25 additions & 3 deletions csv_to_oscal.py
Original file line number Diff line number Diff line change
Expand Up @@ -11,8 +11,8 @@
from uuid import uuid4

from trestle.oscal.catalog import Catalog, Control
from trestle.oscal.common import Metadata

from trestle.oscal.common import Metadata, Property
from pydantic.error_wrappers import ValidationError

class CloudNativeControlCsvRow(NamedTuple):
origin_doc: str
Expand Down Expand Up @@ -65,11 +65,33 @@ def transform_csv(csv_rows: list[list[str]]) -> list[CloudNativeControlCsvRow]:
sys.exit(1)


def sanitize_value(value: str) -> str:
value = value.removeprefix("\n").removesuffix(" ").replace("\n", ", ")
return value


def create_catalog(controls: list[CloudNativeControlCsvRow]) -> Catalog:
oscal_controls = []

for idx, c in enumerate(controls):
oscal_control = Control(id=f"control-{idx+1}", title=c.title)
props = []
try:
props.append(Property(name="section", value=c.section))
props.append(Property(name="assurance-level", value=c.assurance_level))
props.append(Property(name="risk-categories", value=c.risk_categories))
if c.implementation:
value = sanitize_value(c.implementation)
props.append(Property(name="description", value=value))
if c.nist_sp80053_refs:
value = sanitize_value(c.nist_sp80053_refs)
props.append(Property(name="refs", value=value))
except ValidationError as e:
print(c)
raise e
oscal_control = Control(id=f"control-{idx+1}",
title=c.title,
class_=c.origin_doc.replace(' ', '-'),
props=props)
oscal_controls.append(oscal_control)

timestamp = datetime.now()
Expand Down

0 comments on commit 946fa60

Please sign in to comment.