Class: AbideDevUtils::CEM::HieraData::ResourceData::Benchmark
- Inherits:
-
Object
- Object
- AbideDevUtils::CEM::HieraData::ResourceData::Benchmark
- 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
-
#framework ⇒ Object
readonly
Returns the value of attribute framework.
-
#hiera_conf ⇒ Object
readonly
Returns the value of attribute hiera_conf.
-
#major_version ⇒ Object
readonly
Returns the value of attribute major_version.
-
#module_name ⇒ Object
readonly
Returns the value of attribute module_name.
-
#os_facts ⇒ Object
readonly
Returns the value of attribute os_facts.
-
#osfamily ⇒ Object
readonly
Returns the value of attribute osfamily.
-
#osname ⇒ Object
readonly
Returns the value of attribute osname.
Instance Method Summary collapse
- #add_rule(rule_hash) ⇒ Object
- #controls ⇒ Object
-
#initialize(osname, major_version, hiera_conf, module_name, framework: 'cis') ⇒ Benchmark
constructor
A new instance of Benchmark.
- #map(control_id, level: nil, profile: nil) ⇒ Object
- #map_data ⇒ Object
- #map_type(control_id) ⇒ Object
- #mapper ⇒ Object
- #resource_data ⇒ Object
- #resources ⇒ Object
- #rules_in_map(mtype, level: nil, profile: nil) ⇒ Object
- #title ⇒ Object
- #title_key ⇒ Object
- #version ⇒ Object
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
#framework ⇒ Object (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_conf ⇒ Object (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_version ⇒ Object (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_name ⇒ Object (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_facts ⇒ Object (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 |
#osfamily ⇒ Object (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 |
#osname ⇒ Object (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 |
#controls ⇒ Object
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_data ⇒ Object
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 |
#mapper ⇒ Object
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_data ⇒ Object
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 |
#resources ⇒ Object
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 |
#title ⇒ Object
95 96 97 |
# File 'lib/abide_dev_utils/cem/hiera_data/resource_data.rb', line 95 def title mapper.title end |
#title_key ⇒ Object
103 104 105 |
# File 'lib/abide_dev_utils/cem/hiera_data/resource_data.rb', line 103 def title_key @title_key ||= "#{title} #{version}" end |
#version ⇒ Object
99 100 101 |
# File 'lib/abide_dev_utils/cem/hiera_data/resource_data.rb', line 99 def version mapper.version end |