inspec-reporter-json-hdf 1.1.0.beta1 → 1.1.1

Sign up to get free protection for your applications and to get access to all the features.
checksums.yaml CHANGED
@@ -1,7 +1,7 @@
1
1
  ---
2
2
  SHA256:
3
- metadata.gz: 375c586fb5019a374276cbd7e78369e8297b75db012ade31ca84dbb607eae39c
4
- data.tar.gz: 5b63861c6c0304e4800f1e98b81c5e4b66c85f3ba0c7fcfdc42732c4c21f322b
3
+ metadata.gz: 8da7e4c1184a9e40b656eae008bb8543953f15e5434f34573879b6954d78127d
4
+ data.tar.gz: cfefb74fbb00461b676e8a66813304c2e8bc91b032f0d7f91b68a59746788478
5
5
  SHA512:
6
- metadata.gz: 37a2979dba233369c491e25404b21a5b1bcc8eae57c772f1125be4f4ac500fe43201334364b9f8f9b0501d1d590a13711e45c840635b8fe9ddba859e5d122675
7
- data.tar.gz: 16b920add79bf353a0a4113f3af93cf701c449b5cdeabc35e0883e2ae14854c3c3eab83e0a0d82852b84a1742816061f53d3bb90df7a34c9b87ae25744e69910
6
+ metadata.gz: 98c3b8e63c00d6781611860254975a9df39b2e75e0974549d191bcf6ccf5eaceda8edc9bede018af9e7a76fa82d99940b82a00c1a582f15f4a3dbac43eafdc9c
7
+ data.tar.gz: ca7da3c2ff919a93b505ffa087edcd62b5f347a0296494bd41a7971e6004ed2708fb97976c239362962b8c47c8092f431db452766638070ed98fbed2d56e66ab
@@ -9,6 +9,8 @@ VALID_STATUSES = %w[passed failed].freeze
9
9
 
10
10
  DATE_FORMAT = '%Y-%m-%d'.freeze
11
11
 
12
+ SUPPORTED_INCLUDE_TYPES = %w[csv xlsx].freeze
13
+
12
14
  module InspecPlugins::HdfReporter
13
15
  # Reporter Plugin Class
14
16
  class Reporter < Inspec.plugin(2, :reporter)
@@ -42,40 +44,24 @@ module InspecPlugins::HdfReporter
42
44
  private
43
45
 
44
46
  def apply_attestation(results, attestation)
45
- if results.empty?
46
- results = [{
47
- "code_desc": 'Manually verified Status provided through attestation',
48
- "run_time": 0.0,
49
- "start_time": DateTime.now.to_s,
50
- "status": attestation['status'],
51
- "message": attestation_message(attestation)
52
- }]
53
- else
54
- results.each do |result|
55
- result[:message] = 'Automated test returned as passed.' if result[:status].eql?('passed')
56
- result[:message] = result[:skip_message] if result[:status].eql?('skipped')
57
-
58
- result[:status] = attestation['status']
59
- result[:message] = result[:message] + attestation_message(attestation)
60
-
61
- if result[:backtrace]
62
- result[:message] = result[:message] + "\nbacktrace: #{result[:backtrace]}"
63
- result[:backtrace] = nil
64
- end
65
- end
66
- end
67
- results
47
+ results << {
48
+ "code_desc": 'Manually verified Status provided through attestation',
49
+ "run_time": 0.0,
50
+ "start_time": DateTime.now.to_s,
51
+ "status": attestation['status'],
52
+ "message": attestation_message(attestation)
53
+ }
68
54
  end
69
55
 
70
56
  def attestation_message(attestation)
71
- "
72
- Attestation:
73
- Status: #{attestation['status']}
74
- Explanation: #{attestation['explanation']}
75
- Updated: #{attestation['updated']}
76
- Updated By: #{attestation['updated_by']}
77
- Frequency: #{attestation['frequency']}
78
- "
57
+ [
58
+ 'Attestation:',
59
+ "Status: #{attestation['status']}",
60
+ "Explanation: #{attestation['explanation']}",
61
+ "Updated: #{attestation['updated']}",
62
+ "Updated By: #{attestation['updated_by']}",
63
+ "Frequency: #{attestation['frequency']}",
64
+ ].join("\n")
79
65
  end
80
66
 
81
67
  def attestation_expired?(date, frequency)
@@ -89,9 +75,9 @@ module InspecPlugins::HdfReporter
89
75
  when 'annually'
90
76
  parsed_date.next_year(1)
91
77
  when 'semiannually'
92
- parsed_date.next_year(0.5)
78
+ parsed_date.next_month(6)
93
79
  when 'quarterly'
94
- parsed_date.next_year(0.25)
80
+ parsed_date.next_month(3)
95
81
  when 'monthly'
96
82
  parsed_date.next_month(1)
97
83
  when 'every2weeks'
@@ -122,45 +108,46 @@ module InspecPlugins::HdfReporter
122
108
  status.is_a?(String) && VALID_STATUSES.include?(status.downcase)
123
109
  end
124
110
 
125
- def collect_attestations
126
- plugin_config = Inspec::Config.cached.fetch_plugin_config('inspec-reporter-json-hdf')
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'
111
+ def parse_include_file(include_file)
112
+ if File.exist?(include_file['path'])
113
+ if SUPPORTED_INCLUDE_TYPES.include?(include_file['type'])
114
+ sheet = Roo::Spreadsheet.open(include_file['path'], extension: include_file['type'].to_sym ).sheet(0)
115
+
116
+ attestations = sheet.parse(control_id: "Control_ID",
117
+ explanation: "Explanation",
118
+ frequency: "Frequency",
119
+ status: "Status",
120
+ updated: "Updated",
121
+ updated_by: "Updated_By",
122
+ clean:true
123
+ )
124
+ # Following is required to convert Datetime field returned by xlsx parser to string
125
+ attestations.map do |h|
126
+ h[:updated] = h[:updated].to_s
157
127
  end
158
128
  else
159
- puts "Warning: Include Attestation File provided '#{plugin_config['include-attestations-file']['path']}' not found."
129
+ puts "Warning: Invalid `include-attestations-file` type provided. Supported types: #{SUPPORTED_INCLUDE_TYPES.to_s}"
160
130
  end
131
+ else
132
+ puts "Warning: Include Attestation File provided '#{include_file['path']}' not found."
161
133
  end
134
+ attestations || []
135
+ end
136
+
137
+ def collect_attestations
138
+ plugin_config = Inspec::Config.cached.fetch_plugin_config('inspec-reporter-json-hdf')
139
+ attestations = []
140
+
141
+ # Parse Attestations from include file.
142
+ attestations = parse_include_file(plugin_config['include-attestations-file']) if plugin_config['include-attestations-file']
143
+
162
144
  attestations.map!{ |x| x.transform_keys(&:to_s) }
163
- attestations = attestations + (plugin_config['attestations'] || [])
145
+
146
+ # Merge inline Attestations from config file and `include file` with precedence to inline definitions.
147
+ attestations = (plugin_config['attestations'] || []) + attestations
148
+ attestations.uniq! {|e| e['control_id'] }
149
+
150
+ # Remove Attestations records without status provided.
164
151
  attestations.reject! { |x| x['status'].eql?("") || x['status'].nil? }
165
152
 
166
153
  if attestations.empty?
metadata CHANGED
@@ -1,14 +1,14 @@
1
1
  --- !ruby/object:Gem::Specification
2
2
  name: inspec-reporter-json-hdf
3
3
  version: !ruby/object:Gem::Version
4
- version: 1.1.0.beta1
4
+ version: 1.1.1
5
5
  platform: ruby
6
6
  authors:
7
7
  - Rony Xavier
8
8
  autorequire:
9
9
  bindir: bin
10
10
  cert_chain: []
11
- date: 2021-04-06 00:00:00.000000000 Z
11
+ date: 2021-04-13 00:00:00.000000000 Z
12
12
  dependencies:
13
13
  - !ruby/object:Gem::Dependency
14
14
  name: git-lite-version-bump
@@ -197,9 +197,9 @@ required_ruby_version: !ruby/object:Gem::Requirement
197
197
  version: '2.5'
198
198
  required_rubygems_version: !ruby/object:Gem::Requirement
199
199
  requirements:
200
- - - ">"
200
+ - - ">="
201
201
  - !ruby/object:Gem::Version
202
- version: 1.3.1
202
+ version: '0'
203
203
  requirements: []
204
204
  rubygems_version: 3.2.3
205
205
  signing_key: