Skip to content

Commit

Permalink
chg: dev: make new_csv_hdrs a list again, add ID column
Browse files Browse the repository at this point in the history
* save chk script and update default oscal.yaml

Signed-off-by: Steve Arnold <sarnold@vctlabs.com>
  • Loading branch information
sarnold committed Apr 19, 2024
1 parent 8016b71 commit 96f9bf8
Show file tree
Hide file tree
Showing 3 changed files with 27 additions and 2 deletions.
23 changes: 23 additions & 0 deletions scripts/xform_idchk.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,23 @@
"""
Simple consumer test.
"""

from natsort import os_sorted

from ymltoxml.templates import xform_id
from ymltoxml.utils import text_file_reader

OPTS = {
'file_encoding': 'utf-8',
'output_format': 'raw',
'default_csv_hdr': None,
}

# read in some json "column data"
data = text_file_reader('tests/data/OE-expanded-profile-all-ids.txt', OPTS)
if data[0].isupper():
lc_ids = [xform_id(x) for x in data]

# spit out lowercase id format
for ctl in os_sorted(lc_ids):
print(ctl)
2 changes: 1 addition & 1 deletion src/ymltoxml/data/oscal.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -9,7 +9,7 @@ default_ssg_glob: 'nist_rhcos4.yml'
default_ssg_path: 'ext/content/controls'
default_lookup_key: 'controls'
default_csv_hdr: null
new_csv_header: 'New Header'
new_csv_hdrs: []
input_format: null
output_format: 'json'
preserve_quotes: true
Expand Down
4 changes: 3 additions & 1 deletion src/ymltoxml/oscal.py
Original file line number Diff line number Diff line change
Expand Up @@ -41,7 +41,8 @@ def csv_append_id_data(in_ids, prog_opts, uargs): # pragma: no cover
writer = csv.writer(open(new_opath, 'w', newline='', encoding='utf-8'))
reader = csv.reader(open(uargs.munge, 'r', newline='', encoding='utf-8'))
headers = next(reader)
headers.append(prog_opts['new_csv_header'])
for hdr in prog_opts['new_csv_hdrs']:
headers.append(hdr)
writer.writerow(headers)

for ctl in reader:
Expand All @@ -50,6 +51,7 @@ def csv_append_id_data(in_ids, prog_opts, uargs): # pragma: no cover
ctl.append('Y')
else:
ctl.append('N')
ctl.append(ctl_id)
writer.writerow(ctl)


Expand Down

0 comments on commit 96f9bf8

Please sign in to comment.