abide_dev_utils 0.12.1 → 0.12.2

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
checksums.yaml CHANGED
@@ -1,7 +1,7 @@
1
1
  ---
2
2
  SHA256:
3
- metadata.gz: d6f05434761a55369ffb231c1573ba627aa5c9ebef29d198ccfa16c422d05c48
4
- data.tar.gz: 534968456e7eefca691fa6a3cdc46a170dc3ee12060261225fc35adadbc27d18
3
+ metadata.gz: 1e93a77cf4142b06ee4d41863ef2d0b737d21d37306b57082aa316f2731de5e9
4
+ data.tar.gz: 9b49e05aa575884d54efed8fd70b5662712845c083a8b59caeccf406a19f5633
5
5
  SHA512:
6
- metadata.gz: b9907ee602b3367d4692b5c2102f0c769614f33d22980d5b8c0a14ea7dd15ac19947800eed399e6d68215ea2c21ab670b233209bf62e79399795fc5cc0ca68c2
7
- data.tar.gz: edbeac0d044795300b42ac1ddd70623abc9c9e7d322ecf1e5d6356c8b4f875a31e31e02c96397b0bc9ee1a6a815fa342401916d9f87696f0ad68f0bd9d887b75
6
+ metadata.gz: 51316ad752020f3b2297acbdc4bb328c5275d03e499721ee12381aaac5da3a6e77ecb9efeb0ffa4b3b6bb512154dbb4b36bf249f4816944a0110d3ceeb871b2b
7
+ data.tar.gz: 40b83d7be09ccb1349650617548276f6f34e266fe2e590e8c1b28b8e9c44f4499c93652abf9e254d77469fec9c98e9394a1ae2f4b2d3f0921827c3ce302dfb7e
data/Gemfile.lock CHANGED
@@ -1,7 +1,7 @@
1
1
  PATH
2
2
  remote: .
3
3
  specs:
4
- abide_dev_utils (0.12.1)
4
+ abide_dev_utils (0.12.2)
5
5
  amatch (~> 0.4)
6
6
  cmdparse (~> 3.0)
7
7
  facterdb (>= 1.18)
@@ -120,7 +120,11 @@ module AbideDevUtils
120
120
  private
121
121
 
122
122
  def heading_builder
123
- @md.add_h2("#{@control.number} - #{@control.title}")
123
+ if @framework == 'stig'
124
+ @md.add_h2(@control.id)
125
+ else
126
+ @md.add_h2("#{@control.number} - #{@control.title}")
127
+ end
124
128
  end
125
129
 
126
130
  def control_has_valid_params?
@@ -216,12 +220,13 @@ module AbideDevUtils
216
220
  end
217
221
  return if out_str.empty?
218
222
 
219
- out_str.unshift(" #{@control.title.dump}:")
223
+ @control.title.nil? ? out_str.unshift(" #{@control.id.dump}:") : out_str.unshift(" #{@control.title.dump}:")
220
224
  out_str.unshift(' control_configs:')
221
225
  out_str.unshift("#{@module_name}::config:")
222
226
  @md.add_ul('Hiera Configuration Example:')
223
227
  @md.add_code_block(out_str.join("\n"), language: 'yaml')
224
228
  rescue StandardError => e
229
+ require 'pry'; binding.pry
225
230
  err_msg = [
226
231
  "Failed to generate config example for control #{@control.id}",
227
232
  "Error: #{e.message}",
@@ -6,13 +6,13 @@ require 'abide_dev_utils/cem/hiera_data/mapping_data/mixins'
6
6
  module AbideDevUtils
7
7
  module CEM
8
8
  module Mapping
9
- ALL_TYPES = %w[hiera_title_num number hiera_title vulnid title].freeze
9
+ ALL_TYPES = %w[hiera_title_num number hiera_title title vulnid ruleid].freeze
10
10
  FRAMEWORK_TYPES = {
11
11
  'cis' => %w[hiera_title_num number hiera_title title],
12
- 'stig' => %w[hiera_title_num number hiera_title vulnid title],
12
+ 'stig' => %w[vulnid ruleid],
13
13
  }.freeze
14
14
  CIS_TYPES = %w[hiera_title_num number hiera_title title].freeze
15
- STIG_TYPES = %w[hiera_title_num number hiera_title vulnid title].freeze
15
+ STIG_TYPES = %w[vulnid ruleid].freeze
16
16
 
17
17
  # Represents a single map data file
18
18
  class MapData
@@ -168,6 +168,8 @@ module AbideDevUtils
168
168
  'hiera_title'
169
169
  when %r{^V-[0-9]{6}$}
170
170
  'vulnid'
171
+ when %r{^SV-[0-9]+r[0-9]+_rule$}
172
+ 'ruleid'
171
173
  else
172
174
  'title'
173
175
  end
@@ -22,6 +22,7 @@ module Abide
22
22
  add_command(JiraGetIssueCommand.new)
23
23
  add_command(JiraNewIssueCommand.new)
24
24
  add_command(JiraFromCoverageCommand.new)
25
+ add_command(JiraFromXccdfCommand.new)
25
26
  end
26
27
  end
27
28
 
@@ -113,5 +114,26 @@ module Abide
113
114
  end
114
115
  end
115
116
  end
117
+
118
+ class JiraFromXccdfCommand < CmdParse::Command
119
+ CMD_NAME = 'from_xccdf'
120
+ CMD_SHORT = 'Creates a parent issue with subtasks from a xccdf file'
121
+ CMD_LONG = 'Creates a parent issue with subtasks for a benchmark and any uncovered controls'
122
+ def initialize
123
+ super(CMD_NAME, takes_commands: false)
124
+ short_desc(CMD_SHORT)
125
+ long_desc(CMD_LONG)
126
+ argument_desc(PATH: 'An XCCDF file from the abide puppet ticket coverage command', PROJECT: 'A Jira project')
127
+ options.on('-d', '--dry-run', 'Print to console instead of saving objects') { |_| @data[:dry_run] = true }
128
+ end
129
+
130
+ def execute(path, project)
131
+ Abide::CLI::VALIDATE.file(path)
132
+ @data[:dry_run] = false if @data[:dry_run].nil?
133
+ client = JIRA.client(options: {})
134
+ proj = JIRA.project(client, project)
135
+ JIRA.new_issues_from_xccdf(client, proj, path, dry_run: @data[:dry_run])
136
+ end
137
+ end
116
138
  end
117
139
  end
@@ -135,6 +135,36 @@ module AbideDevUtils
135
135
  end
136
136
  end
137
137
 
138
+ def self.new_issues_from_xccdf(client, project, xccdf_path, dry_run: false)
139
+ dr_prefix = dry_run ? 'DRY RUN: ' : ''
140
+ i_attrs = all_project_issues_attrs(project)
141
+
142
+ xccdf = AbideDevUtils::XCCDF::Benchmark.new(xccdf_path)
143
+
144
+ summaries = summaries_from_xccdf(xccdf)
145
+ summaries.each do |profile_summary, control_summaries|
146
+ if summary_exist?(profile_summary, i_attrs)
147
+ AbideDevUtils::Output.simple("#{dr_prefix}Skipping #{profile_summary} as it already exists")
148
+ next
149
+ end
150
+
151
+ parent = new_issue(client, project.attrs['key'], profile_summary, dry_run: dry_run)
152
+ AbideDevUtils::Output.simple("#{dr_prefix}Created parent issue #{profile_summary}")
153
+ parent_issue = issue(client, parent.attrs['key']) unless parent.respond_to?(:dummy)
154
+ AbideDevUtils::Output.simple("#{dr_prefix}Creating subtasks, this can take a while...")
155
+ progress = AbideDevUtils::Output.progress(title: "#{dr_prefix}Creating Subtasks", total: nil)
156
+ control_summaries.each do |control_summary|
157
+ next if summary_exist?(control_summary, i_attrs)
158
+
159
+ progress.title = "#{dr_prefix}#{control_summary}"
160
+ new_subtask(client, parent_issue, control_summary, dry_run: dry_run)
161
+ progress.increment
162
+ end
163
+ final_text = "#{dr_prefix}Created #{control_summaries.count} subtasks for #{profile_summary}"
164
+ puts "\r\033[K#{final_text}\n"
165
+ end
166
+ end
167
+
138
168
  # def self.new_issues_from_comply_report(client, project, report, dry_run: false)
139
169
  # dr_prefix = dry_run ? 'DRY RUN: ' : ''
140
170
  # i_attrs = all_project_issues_attrs(project)
@@ -177,6 +207,21 @@ module AbideDevUtils
177
207
  summaries.transform_keys { |k| "#{COV_PARENT_SUMMARY_PREFIX}#{benchmark}-#{k}"}
178
208
  end
179
209
 
210
+ def self.summaries_from_xccdf(xccdf)
211
+ summaries = {}
212
+ facter_os = xccdf.facter_benchmark.join('-')
213
+ xccdf.profiles.each do |profile|
214
+ summaries["#{COV_PARENT_SUMMARY_PREFIX}#{facter_os} - #{profile.level} #{profile.title}"] = profile.controls.collect do |control|
215
+ summary = "#{COV_CHILD_SUMMARY_PREFIX}#{control.vulnid} - #{control.title}"
216
+ if summary.length > 255
217
+ summary = summary[0..251] + '...'
218
+ end
219
+ summary
220
+ end
221
+ end
222
+ summaries
223
+ end
224
+
180
225
  # def self.summaries_from_comply_report(report)
181
226
  # summaries = {}
182
227
  # report.each do |_, v|
@@ -1,5 +1,5 @@
1
1
  # frozen_string_literal: true
2
2
 
3
3
  module AbideDevUtils
4
- VERSION = "0.12.1"
4
+ VERSION = "0.12.2"
5
5
  end
@@ -157,7 +157,8 @@ module AbideDevUtils
157
157
  raise AbideDevUtils::Errors::ControlPartsError, control
158
158
  end
159
159
  rule_id = group.xpath('Rule/@id').first.value
160
- return [vuln_id, rule_id]
160
+ title = group.xpath('Rule/title').text
161
+ return [vuln_id, rule_id, title]
161
162
  else
162
163
  raise AbideDevUtils::Errors::ControlPartsError, control
163
164
  end
@@ -658,8 +659,8 @@ module AbideDevUtils
658
659
  class StigControl < XccdfElement
659
660
  def initialize(control, benchmark)
660
661
  super(control, benchmark)
661
- @vulnid, @ruleid = control_parts(control_profile_text(control))
662
- properties :vulnid, :ruleid
662
+ @vulnid, @ruleid, @title = control_parts(control_profile_text(control))
663
+ properties :vulnid, :ruleid, :title
663
664
  end
664
665
  end
665
666
 
metadata CHANGED
@@ -1,14 +1,14 @@
1
1
  --- !ruby/object:Gem::Specification
2
2
  name: abide_dev_utils
3
3
  version: !ruby/object:Gem::Version
4
- version: 0.12.1
4
+ version: 0.12.2
5
5
  platform: ruby
6
6
  authors:
7
7
  - abide-team
8
8
  autorequire:
9
9
  bindir: exe
10
10
  cert_chain: []
11
- date: 2022-08-22 00:00:00.000000000 Z
11
+ date: 2022-10-17 00:00:00.000000000 Z
12
12
  dependencies:
13
13
  - !ruby/object:Gem::Dependency
14
14
  name: nokogiri