Class: AbideDevUtils::Sce::Generate::Reference::MarkdownGenerator

Inherits:
Object
  • Object
show all
Defined in:
lib/abide_dev_utils/sce/generate/reference.rb

Overview

Generates a markdown reference doc

Constant Summary collapse

SPECIAL_CONTROL_IDS =
%w[dependent sce_options sce_protected].freeze

Instance Method Summary collapse

Constructor Details

#initialize(benchmarks, module_name, file: 'REFERENCE.md', opts: {}) ⇒ MarkdownGenerator

Returns a new instance of MarkdownGenerator.



72
73
74
75
76
77
78
# File 'lib/abide_dev_utils/sce/generate/reference.rb', line 72

def initialize(benchmarks, module_name, file: 'REFERENCE.md', opts: {})
  @benchmarks = benchmarks
  @module_name = module_name
  @file = file
  @opts = opts
  @md = AbideDevUtils::Markdown.new(@file)
end

Instance Method Details

#generate(doc_title = 'Reference') ⇒ Object



80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
# File 'lib/abide_dev_utils/sce/generate/reference.rb', line 80

def generate(doc_title = 'Reference')
  @strings = Strings.new(opts: @opts)
  md.add_title(doc_title)
  benchmarks.each do |benchmark|
    unless @opts[:quiet]
      progress_bar = AbideDevUtils::Output.progress(title: "Generating Markdown for #{benchmark.title_key}",
                                                    total: benchmark.controls.length)
    end
    md.add_h1(benchmark.title_key)
    benchmark.controls.each do |control|
      next if SPECIAL_CONTROL_IDS.include? control.id
      next if benchmark.framework == 'stig' && control.id_map_type != 'vulnid'

      control_md = ControlMarkdown.new(control, @md, @strings, @module_name, benchmark.framework, opts: @opts)
      control_md.generate! if control_md.verify_profile_and_level_selections
      progress_bar.increment unless @opts[:quiet]
    rescue StandardError => e
      raise "Failed to generate markdown for control #{control.id}. Original message: #{e.message}"
    end
  end

  if @module_name.split('-').last == 'sce_linux'
    md.add_h1('List of known CIS control sections that use plans and tasks:')
    md.add_ul('Red Hat Enterprise Linux 7: Section 6.2', indent: 1)
    md.add_ul('Red Hat Enterprise Linux 8: Section 6.2', indent: 1)
    md.add_ul('Red Hat Enterprise Linux 9: Section 7.2', indent: 1)
    md.add_ul('Oracle Linux 7: Section 6.2', indent: 1)
    md.add_ul('Oracle Linux 8: Section 6.2', indent: 1)
    md.add_ul('Oracle Linux 9: Section 7.2', indent: 1)
    md.add_ul('Rocky Linux 8: Section 6.2', indent: 1)
    md.add_ul('Rocky Linux 9: Section 7.2', indent: 1)
    md.add_ul('AlmaLinux 8: Section 6.2', indent: 1)
    md.add_ul('AlmaLinux 9: Section 7.2', indent: 1)
    md.add_ul('Ubuntu 20.04: Section 6.2', indent: 1)
    md.add_ul('Ubuntu 22.04: Section 7.2', indent: 1)
  end

  AbideDevUtils::Output.simple("Saving markdown to #{@file}") unless @opts[:quiet]
  md.to_file
end