Class: AbideDevUtils::CEM::HieraData::ResourceData::Benchmark

Inherits:
Object
  • Object
show all
Defined in:
lib/abide_dev_utils/cem/hiera_data/resource_data.rb

Overview

Repesents a benchmark based on resource and mapping data

Instance Attribute Summary collapse

Instance Method Summary collapse

Constructor Details

#initialize(osname, major_version, hiera_conf, module_name, framework: 'cis') ⇒ Benchmark

Returns a new instance of Benchmark.



61
62
63
64
65
66
67
68
69
70
71
# File 'lib/abide_dev_utils/cem/hiera_data/resource_data.rb', line 61

def initialize(osname, major_version, hiera_conf, module_name, framework: 'cis')
  @osname = osname
  @major_version = major_version
  @os_facts = AbideDevUtils::Ppt::FacterUtils.recursive_facts_for_os(@osname, @major_version)
  @osfamily = @os_facts['os']['family']
  @hiera_conf = hiera_conf
  @module_name = module_name
  @framework = framework
  @map_cache = {}
  @rules_in_map = {}
end

Instance Attribute Details

#frameworkObject (readonly)

Returns the value of attribute framework.



59
60
61
# File 'lib/abide_dev_utils/cem/hiera_data/resource_data.rb', line 59

def framework
  @framework
end

#hiera_confObject (readonly)

Returns the value of attribute hiera_conf.



59
60
61
# File 'lib/abide_dev_utils/cem/hiera_data/resource_data.rb', line 59

def hiera_conf
  @hiera_conf
end

#major_versionObject (readonly)

Returns the value of attribute major_version.



59
60
61
# File 'lib/abide_dev_utils/cem/hiera_data/resource_data.rb', line 59

def major_version
  @major_version
end

#module_nameObject (readonly)

Returns the value of attribute module_name.



59
60
61
# File 'lib/abide_dev_utils/cem/hiera_data/resource_data.rb', line 59

def module_name
  @module_name
end

#os_factsObject (readonly)

Returns the value of attribute os_facts.



59
60
61
# File 'lib/abide_dev_utils/cem/hiera_data/resource_data.rb', line 59

def os_facts
  @os_facts
end

#osfamilyObject (readonly)

Returns the value of attribute osfamily.



59
60
61
# File 'lib/abide_dev_utils/cem/hiera_data/resource_data.rb', line 59

def osfamily
  @osfamily
end

#osnameObject (readonly)

Returns the value of attribute osname.



59
60
61
# File 'lib/abide_dev_utils/cem/hiera_data/resource_data.rb', line 59

def osname
  @osname
end

Instance Method Details

#add_rule(rule_hash) ⇒ Object



107
108
109
# File 'lib/abide_dev_utils/cem/hiera_data/resource_data.rb', line 107

def add_rule(rule_hash)
  @rules << rule_hash
end

#controlsObject



79
80
81
# File 'lib/abide_dev_utils/cem/hiera_data/resource_data.rb', line 79

def controls
  @controls ||= resources.map(&:controls).flatten.sort
end

#map(control_id, level: nil, profile: nil) ⇒ Object



131
132
133
# File 'lib/abide_dev_utils/cem/hiera_data/resource_data.rb', line 131

def map(control_id, level: nil, profile: nil)
  mapper.get(control_id, level: level, profile: profile)
end

#map_dataObject



87
88
89
# File 'lib/abide_dev_utils/cem/hiera_data/resource_data.rb', line 87

def map_data
  mapper.map_data
end

#map_type(control_id) ⇒ Object



135
136
137
# File 'lib/abide_dev_utils/cem/hiera_data/resource_data.rb', line 135

def map_type(control_id)
  mapper.map_type(control_id)
end

#mapperObject



83
84
85
# File 'lib/abide_dev_utils/cem/hiera_data/resource_data.rb', line 83

def mapper
  @mapper ||= AbideDevUtils::CEM::HieraData::MappingData::Mapper.new(module_name, framework, load_mapping_data)
end

#resource_dataObject



91
92
93
# File 'lib/abide_dev_utils/cem/hiera_data/resource_data.rb', line 91

def resource_data
  @resource_data ||= load_resource_data
end

#resourcesObject



73
74
75
76
77
# File 'lib/abide_dev_utils/cem/hiera_data/resource_data.rb', line 73

def resources
  @resources ||= resource_data["#{module_name}::resources"].each_with_object([]) do |(rtitle, rdata), arr|
    arr << Resource.new(rtitle, rdata, framework, mapper)
  end
end

#rules_in_map(mtype, level: nil, profile: nil) ⇒ Object



111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
# File 'lib/abide_dev_utils/cem/hiera_data/resource_data.rb', line 111

def rules_in_map(mtype, level: nil, profile: nil)
  real_mtype = map_type(mtype)
  cache_key = [real_mtype, level, profile].compact.join('-')
  return @rules_in_map[cache_key] if @rules_in_map.key?(cache_key)

  all_rim = mapper.each_with_array_like(real_mtype) do |(lvl, profs), arr|
    next if lvl == 'benchmark' || (!level.nil? && lvl != level)

    profs.each do |prof, maps|
      next if !profile.nil? && prof != profile

      # CIS and STIG differ in that STIG does not have profiles
      control_ids = maps.respond_to?(:keys) ? maps.keys : prof
      arr << control_ids
    end
  end
  @rules_in_map[cache_key] = all_rim.flatten.uniq
  @rules_in_map[cache_key]
end

#titleObject



95
96
97
# File 'lib/abide_dev_utils/cem/hiera_data/resource_data.rb', line 95

def title
  mapper.title
end

#title_keyObject



103
104
105
# File 'lib/abide_dev_utils/cem/hiera_data/resource_data.rb', line 103

def title_key
  @title_key ||= "#{title} #{version}"
end

#versionObject



99
100
101
# File 'lib/abide_dev_utils/cem/hiera_data/resource_data.rb', line 99

def version
  mapper.version
end