Class: InspecTools::XCCDF

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

Overview

rubocop:disable Metrics/ClassLength rubocop:disable Metrics/AbcSize rubocop:disable Metrics/PerceivedComplexity rubocop:disable Metrics/CyclomaticComplexity rubocop:disable Metrics/BlockLength

Instance Method Summary collapse

Constructor Details

#initialize(xccdf, replace_tags = nil) ⇒ XCCDF

Returns a new instance of XCCDF.



14
15
16
17
18
19
20
21
# File 'lib/inspec_tools/xccdf.rb', line 14

def initialize(xccdf, 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))
  # @cci_items = HappyMapperTools::CCIAttributes::CCI_List.parse(File.read('./data/U_CCI_List.xml'))
  @benchmark = HappyMapperTools::StigAttributes::Benchmark.parse(@xccdf)
end

Instance Method Details

#publishedObject



78
79
80
# File 'lib/inspec_tools/xccdf.rb', line 78

def published
  @benchmark.release_date.release_date
end

#publisherObject



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

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



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
70
71
72
# File 'lib/inspec_tools/xccdf.rb', line 44

def to_attributes # rubocop:disable Metrics/AbcSize
  @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



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

def to_ckl
  # TODO: to_ckl
end

#to_csvObject



27
28
29
# File 'lib/inspec_tools/xccdf.rb', line 27

def to_csv
  # TODO: to_csv
end

#to_inspecObject



31
32
33
34
35
36
37
38
# File 'lib/inspec_tools/xccdf.rb', line 31

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