Class: InspecTools::XCCDF

Inherits:
Object show all
Defined in:
lib/inspec_tools/xccdf.rb

Instance Method Summary collapse

Constructor Details

#initialize(xccdf, use_vuln_id, replace_tags = nil) ⇒ XCCDF

Returns a new instance of XCCDF.



10
11
12
13
14
15
16
17
18
# File 'lib/inspec_tools/xccdf.rb', line 10

def initialize(xccdf, use_vuln_id, replace_tags = nil)
  @xccdf = xccdf
  @xccdf = replace_tags_in_xccdf(replace_tags, @xccdf) unless replace_tags.nil?
  cci_list_path = File.join(File.dirname(__FILE__), '../data/U_CCI_List.xml')
  @cci_items = HappyMapperTools::CCIAttributes::CCI_List.parse(File.read(cci_list_path))
  register_after_parse_callbacks
  @benchmark = HappyMapperTools::StigAttributes::Benchmark.parse(@xccdf)
  @use_vuln_id = use_vuln_id
end

Instance Method Details

#inject_metadata(metadata = '{}') ⇒ Object



79
80
81
82
83
84
# File 'lib/inspec_tools/xccdf.rb', line 79

def ( = '{}')
   = JSON.parse()
  .each do |key, value|
    @profile[key] = value
  end
end

#publishedObject



75
76
77
# File 'lib/inspec_tools/xccdf.rb', line 75

def published
  @benchmark.release_date.release_date
end

#publisherObject



71
72
73
# File 'lib/inspec_tools/xccdf.rb', line 71

def publisher
  @benchmark.reference.dc_publisher
end

#to_attributesObject

extracts non-InSpec attributes

TODO there may be more attributes we want to extract, see data/attributes.yml for example



41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
# File 'lib/inspec_tools/xccdf.rb', line 41

def to_attributes
  @attribute = {}

  @attribute['benchmark.title'] = @benchmark.title
  @attribute['benchmark.id'] = @benchmark.id
  @attribute['benchmark.description'] = @benchmark.description
  @attribute['benchmark.version'] = @benchmark.version

  @attribute['benchmark.status'] = @benchmark.status
  @attribute['benchmark.status.date'] = @benchmark.release_date.release_date

  @attribute['benchmark.notice.id'] = @benchmark.notice.id

  @attribute['benchmark.plaintext'] = @benchmark.plaintext.plaintext
  @attribute['benchmark.plaintext.id'] = @benchmark.plaintext.id

  @attribute['reference.href'] = @benchmark.reference.href
  @attribute['reference.dc.publisher'] = @benchmark.reference.dc_publisher
  @attribute['reference.dc.source'] = @benchmark.reference.dc_source
  @attribute['reference.dc.title'] = @benchmark.group[0].rule.reference.dc_title if !@benchmark.group[0].nil?
  @attribute['reference.dc.subject'] = @benchmark.group[0].rule.reference.dc_subject if !@benchmark.group[0].nil?
  @attribute['reference.dc.type'] = @benchmark.group[0].rule.reference.dc_type if !@benchmark.group[0].nil?
  @attribute['reference.dc.identifier'] = @benchmark.group[0].rule.reference.dc_identifier if !@benchmark.group[0].nil?

  @attribute['content_ref.name'] = @benchmark.group[0].rule.check.content_ref.name if !@benchmark.group[0].nil?
  @attribute['content_ref.href'] = @benchmark.group[0].rule.check.content_ref.href if !@benchmark.group[0].nil?

  @attribute
end

#to_cklObject



20
21
22
# File 'lib/inspec_tools/xccdf.rb', line 20

def to_ckl
  # TODO: to_ckl
end

#to_csvObject



24
25
26
# File 'lib/inspec_tools/xccdf.rb', line 24

def to_csv
  # TODO: to_csv
end

#to_inspecObject



28
29
30
31
32
33
34
35
# File 'lib/inspec_tools/xccdf.rb', line 28

def to_inspec
  @profile = {}
  @controls = []
  
  insert_controls
  @profile['sha256'] = Digest::SHA256.hexdigest @profile.to_s
  @profile
end