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.



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

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

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



84
85
86
87
88
89
# File 'lib/inspec_tools/xccdf.rb', line 84

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

#publishedObject



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

def published
  @benchmark.release_date.release_date
end

#publisherObject



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

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



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
73
74
# File 'lib/inspec_tools/xccdf.rb', line 46

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



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

def to_ckl
  # TODO: to_ckl
end

#to_csvObject



29
30
31
# File 'lib/inspec_tools/xccdf.rb', line 29

def to_csv
  # TODO: to_csv
end

#to_inspecObject



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

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