inspec_tools 2.3.6 → 2.3.7

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: 83f3edc68686aa22483f4f17080a176122ed5d3b8c41c0a1f47a68062aa04b4d
4
- data.tar.gz: 6c140e38354f7decc791db6829bbcff2bf845d256d9860769514d62c17cf50c6
3
+ metadata.gz: a9633cda4bf3fedc9702dd91ba4ed6b40b68ec8e054eb87ad6ca32d32dfc11e5
4
+ data.tar.gz: 22f5ab86d76ccbc7f7fc0a684371b791c26f9771e369be54c359121d8c28f4d3
5
5
  SHA512:
6
- metadata.gz: 21875ca95036a401be3eb22ef782b1d92f12869fa6cf32183a80d8dd951e9ab95196458485c3437d4be8f902d8a6def3d5da2c411d517e40020cd4b3ad013a1b
7
- data.tar.gz: 5879c557fcf781bec5a44a637160bedd981450b071b72e8155d7046aad8adba8cefbe93f4b92f6d5be666b1d88363328e392a5fdddc271383ca6c087ccb34f8a
6
+ metadata.gz: 0e50a5db32e542cd5a66b8bab09a8613c9b8b6ea62513d073a3eb71717397d5c54cf3ccea2c48dd3c0dbc21dbb5d0f9c550744bb8ed6f27f37335a88b0184ea8
7
+ data.tar.gz: af786d30584f7bf79108b44d9cb653e7673c2716ea7ce72f24fa1c494b4dfc7801f032aeca8829c23f5a1ed9ca8be542b5bf7f4d72fa315400a0b0d1349a3c64
@@ -27,6 +27,11 @@ module HappyMapperTools
27
27
  # Class Asset maps from the 'SI_DATA' from Checklist XML file using HappyMapper
28
28
  class SiData
29
29
  include HappyMapper
30
+
31
+ def initialize(name, data)
32
+ self.name = name
33
+ self.data = data
34
+ end
30
35
  tag 'SI_DATA'
31
36
  element :name, String, tag: 'SID_NAME'
32
37
  element :data, String, tag: 'SID_DATA'
@@ -35,6 +40,11 @@ module HappyMapperTools
35
40
  # Class Asset maps from the 'STIG_INFO' from Checklist XML file using HappyMapper
36
41
  class StigInfo
37
42
  include HappyMapper
43
+
44
+ def initialize(si_data)
45
+ self.si_data = si_data
46
+ end
47
+
38
48
  tag 'STIG_INFO'
39
49
  has_many :si_data, SiData, tag: 'SI_DATA'
40
50
  end
@@ -68,6 +78,11 @@ module HappyMapperTools
68
78
  # Class Asset maps from the 'iSTIG' from Checklist XML file using HappyMapper
69
79
  class IStig
70
80
  include HappyMapper
81
+
82
+ def initialize(stig_info, vulns)
83
+ self.stig_info = stig_info
84
+ self.vuln = vulns
85
+ end
71
86
  tag 'iSTIG'
72
87
  has_one :stig_info, StigInfo, tag: 'STIG_INFO'
73
88
  has_many :vuln, Vuln, tag: 'VULN'
@@ -76,6 +91,10 @@ module HappyMapperTools
76
91
  # Class Asset maps from the 'STIGS' from Checklist XML file using HappyMapper
77
92
  class Stigs
78
93
  include HappyMapper
94
+
95
+ def initialize(istig)
96
+ self.istig = istig
97
+ end
79
98
  tag 'STIGS'
80
99
  has_one :istig, IStig, tag: 'iSTIG'
81
100
  end
@@ -61,6 +61,25 @@ module InspecTools
61
61
 
62
62
  private
63
63
 
64
+ def topmost_profile_name
65
+ find_topmost_profile_name(0)
66
+ end
67
+
68
+ def find_topmost_profile_name(index, parent_name = nil)
69
+ # Return nil when the index is out of bounds.
70
+ # nil returned here will set the profile name to '' in the calling functions.
71
+ return nil if index > @json['profiles'].length - 1
72
+
73
+ # No parent profile means this is the parent
74
+ if !@json['profiles'][index].key?('parent_profile') && (@json['profiles'][index]['name'] == parent_name || index.zero?)
75
+ # For the initial case, parent_name will be nil, and if we are already at the parent index is also zero
76
+ return @json['profiles'][index]['name']
77
+ end
78
+
79
+ parent_name = @json['profiles'][index]['parent_profile']
80
+ find_topmost_profile_name(index + 1, parent_name)
81
+ end
82
+
64
83
  ###
65
84
  # This method converts an inspec json to an array of arrays
66
85
  #
@@ -111,28 +130,19 @@ module InspecTools
111
130
  end
112
131
 
113
132
  def generate_ckl
114
- stigs = HappyMapperTools::StigChecklist::Stigs.new
115
- istig = HappyMapperTools::StigChecklist::IStig.new
116
-
117
133
  vuln_list = []
118
134
  @data.keys.each do |control_id|
119
135
  vuln_list.push(generate_vuln_data(@data[control_id]))
120
136
  end
121
137
 
122
- si_data = HappyMapperTools::StigChecklist::SiData.new
123
- si_data.name = 'stigid'
124
- si_data.data = ''
125
- if !@metadata['stigid'].nil?
126
- si_data.data = @metadata['stigid']
127
- end
138
+ si_data_data = @metadata['stigid'] || topmost_profile_name || ''
139
+ si_data_stigid = HappyMapperTools::StigChecklist::SiData.new('stigid', si_data_data)
140
+ si_data_title = HappyMapperTools::StigChecklist::SiData.new('title', si_data_data)
128
141
 
129
- stig_info = HappyMapperTools::StigChecklist::StigInfo.new
130
- stig_info.si_data = si_data
131
- istig.stig_info = stig_info
142
+ stig_info = HappyMapperTools::StigChecklist::StigInfo.new([si_data_stigid, si_data_title])
132
143
 
133
- istig.vuln = vuln_list
134
- stigs.istig = istig
135
- @checklist.stig = stigs
144
+ istig = HappyMapperTools::StigChecklist::IStig.new(stig_info, vuln_list)
145
+ @checklist.stig = HappyMapperTools::StigChecklist::Stigs.new(istig)
136
146
 
137
147
  @checklist.asset = generate_asset
138
148
  end
metadata CHANGED
@@ -1,7 +1,7 @@
1
1
  --- !ruby/object:Gem::Specification
2
2
  name: inspec_tools
3
3
  version: !ruby/object:Gem::Version
4
- version: 2.3.6
4
+ version: 2.3.7
5
5
  platform: ruby
6
6
  authors:
7
7
  - Robert Thew
@@ -11,7 +11,7 @@ authors:
11
11
  autorequire:
12
12
  bindir: exe
13
13
  cert_chain: []
14
- date: 2021-05-27 00:00:00.000000000 Z
14
+ date: 2021-06-07 00:00:00.000000000 Z
15
15
  dependencies:
16
16
  - !ruby/object:Gem::Dependency
17
17
  name: colorize