Skip to content
This repository was archived by the owner on Jul 1, 2022. It is now read-only.

Commit aee577a

Browse files
author
Rony Xavier
committed
Update plugin to get data from csv or xlsx; ignore entries with nil status
Signed-off-by: Rony Xavier <rxavier@mitre.org>
1 parent 1dbd72f commit aee577a

File tree

1 file changed

+39
-1
lines changed

1 file changed

+39
-1
lines changed

lib/inspec-reporter-json-hdf/reporter.rb

Lines changed: 39 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,7 @@
11

22
require 'inspec/plugin/v2'
33
require 'json'
4+
require 'roo'
45

56
VALID_FREQUENCY = %w[annually semiannually quarterly monthly every2weeks weekly every3days daily].freeze
67

@@ -123,7 +124,44 @@ def valid_status?(status)
123124

124125
def collect_attestations
125126
plugin_config = Inspec::Config.cached.fetch_plugin_config('inspec-reporter-json-hdf')
126-
attestations = plugin_config['attestations'] || []
127+
attestations = []
128+
if plugin_config['include-attestations-file']
129+
if File.exist?(plugin_config['include-attestations-file']['path'])
130+
if plugin_config['include-attestations-file']['type'].eql?('csv')
131+
sheet = Roo::Spreadsheet.open(plugin_config['include-attestations-file']['path'], extension: :csv).sheet(0)
132+
133+
attestations = sheet.parse(control_id: "Control_ID",
134+
explanation: "Explanation",
135+
frequency: "Frequency",
136+
status: "Status",
137+
updated: "Updated",
138+
updated_by: "Updated_By",
139+
clean:true
140+
)
141+
elsif plugin_config['include-attestations-file']['type'].eql?('xlsx')
142+
sheet = Roo::Spreadsheet.open(plugin_config['include-attestations-file']['path'], extension: :xlsx).sheet(0)
143+
144+
attestations = sheet.parse(control_id: "Control_ID",
145+
explanation: "Explanation",
146+
frequency: "Frequency",
147+
status: "Status",
148+
updated: "Updated",
149+
updated_by: "Updated_By",
150+
clean:true
151+
)
152+
attestations.map do |h|
153+
h[:updated] = h[:updated].to_s
154+
end
155+
else
156+
puts 'Warning: Invalid `include-attestations-file` type provided. Supported types: csv, xlsx'
157+
end
158+
else
159+
puts "Warning: Include Attestation File provided '#{plugin_config['include-attestations-file']['path']}' not found."
160+
end
161+
end
162+
attestations.map!{ |x| x.transform_keys(&:to_s) }
163+
attestations = attestations + (plugin_config['attestations'] || [])
164+
attestations.reject! { |x| x['status'].eql?("") || x['status'].nil? }
127165

128166
if attestations.empty?
129167
puts 'Warning: Attestations not provided; HDF will be generated without attestations.'

0 commit comments

Comments
 (0)