Class: AbideDevUtils::CEM::Benchmark
- Inherits:
-
Object
- Object
- AbideDevUtils::CEM::Benchmark
- Defined in:
- lib/abide_dev_utils/cem/benchmark.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.
Class Method Summary collapse
-
.benchmarks_from_puppet_module(pupmod, ignore_all_errors: false, ignore_framework_mismatch: true) ⇒ Array<AbideDevUtils::CEM::Benchmark>
Creates Benchmark objects from a Puppet module.
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.
317 318 319 320 321 322 323 324 325 326 327 328 |
# File 'lib/abide_dev_utils/cem/benchmark.rb', line 317 def initialize(osname, major_version, hiera_conf, module_name, framework: 'cis') @osname = osname @major_version = major_version @os_facts = AbideDevUtils::Ppt::FacterUtils::FactSets.new.find_by_fact_value_tuples(['os.name', @osname], ['os.release.major', @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.
315 316 317 |
# File 'lib/abide_dev_utils/cem/benchmark.rb', line 315 def framework @framework end |
#hiera_conf ⇒ Object (readonly)
Returns the value of attribute hiera_conf.
315 316 317 |
# File 'lib/abide_dev_utils/cem/benchmark.rb', line 315 def hiera_conf @hiera_conf end |
#major_version ⇒ Object (readonly)
Returns the value of attribute major_version.
315 316 317 |
# File 'lib/abide_dev_utils/cem/benchmark.rb', line 315 def major_version @major_version end |
#module_name ⇒ Object (readonly)
Returns the value of attribute module_name.
315 316 317 |
# File 'lib/abide_dev_utils/cem/benchmark.rb', line 315 def module_name @module_name end |
#os_facts ⇒ Object (readonly)
Returns the value of attribute os_facts.
315 316 317 |
# File 'lib/abide_dev_utils/cem/benchmark.rb', line 315 def os_facts @os_facts end |
#osfamily ⇒ Object (readonly)
Returns the value of attribute osfamily.
315 316 317 |
# File 'lib/abide_dev_utils/cem/benchmark.rb', line 315 def osfamily @osfamily end |
#osname ⇒ Object (readonly)
Returns the value of attribute osname.
315 316 317 |
# File 'lib/abide_dev_utils/cem/benchmark.rb', line 315 def osname @osname end |
Class Method Details
.benchmarks_from_puppet_module(pupmod, ignore_all_errors: false, ignore_framework_mismatch: true) ⇒ Array<AbideDevUtils::CEM::Benchmark>
Creates Benchmark objects from a Puppet module
334 335 336 337 338 339 340 341 342 343 344 345 346 347 348 349 350 351 352 353 354 355 356 357 358 359 360 361 362 363 364 365 366 367 368 369 370 371 372 373 |
# File 'lib/abide_dev_utils/cem/benchmark.rb', line 334 def self.benchmarks_from_puppet_module(pupmod, ignore_all_errors: false, ignore_framework_mismatch: true) frameworks = pupmod.hiera_conf.local_hiera_files(hierarchy_name: 'Mapping Data').each_with_object([]) do |hf, ary| parts = hf.path.split(pupmod.hiera_conf.default_datadir)[-1].split('/') ary << parts[2] unless ary.include?(parts[2]) end pupmod.supported_os.each_with_object([]) do |supp_os, ary| osname, majver = supp_os.split('::') if majver.is_a?(Array) majver.sort.each do |v| frameworks.each do |fw| benchmark = Benchmark.new(osname, v, pupmod.hiera_conf, pupmod.name(strip_namespace: true), framework: fw) benchmark.controls ary << benchmark rescue AbideDevUtils::Errors::MappingDataFrameworkMismatchError => e raise e unless ignore_all_errors || ignore_framework_mismatch rescue StandardError => e raise e unless ignore_all_errors end end else frameworks.each do |fw| benchmark = Benchmark.new(osname, majver, pupmod.hiera_conf, pupmod.name(strip_namespace: true), framework: fw) benchmark.controls ary << benchmark rescue AbideDevUtils::Errors::MappingDataFrameworkMismatchError => e raise e unless ignore_all_errors || ignore_framework_mismatch rescue StandardError => e raise e unless ignore_all_errors end end end end |
Instance Method Details
#add_rule(rule_hash) ⇒ Object
409 410 411 |
# File 'lib/abide_dev_utils/cem/benchmark.rb', line 409 def add_rule(rule_hash) @rules << rule_hash end |
#controls ⇒ Object
381 382 383 |
# File 'lib/abide_dev_utils/cem/benchmark.rb', line 381 def controls @controls ||= resources.map(&:controls).flatten.sort end |
#map(control_id, level: nil, profile: nil) ⇒ Object
433 434 435 |
# File 'lib/abide_dev_utils/cem/benchmark.rb', line 433 def map(control_id, level: nil, profile: nil) mapper.get(control_id, level: level, profile: profile) end |
#map_data ⇒ Object
389 390 391 |
# File 'lib/abide_dev_utils/cem/benchmark.rb', line 389 def map_data mapper.map_data end |
#map_type(control_id) ⇒ Object
437 438 439 |
# File 'lib/abide_dev_utils/cem/benchmark.rb', line 437 def map_type(control_id) mapper.map_type(control_id) end |
#mapper ⇒ Object
385 386 387 |
# File 'lib/abide_dev_utils/cem/benchmark.rb', line 385 def mapper @mapper ||= AbideDevUtils::CEM::Mapping::Mapper.new(module_name, framework, load_mapping_data) end |
#resource_data ⇒ Object
393 394 395 |
# File 'lib/abide_dev_utils/cem/benchmark.rb', line 393 def resource_data @resource_data ||= load_resource_data end |
#resources ⇒ Object
375 376 377 378 379 |
# File 'lib/abide_dev_utils/cem/benchmark.rb', line 375 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
413 414 415 416 417 418 419 420 421 422 423 424 425 426 427 428 429 430 431 |
# File 'lib/abide_dev_utils/cem/benchmark.rb', line 413 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
397 398 399 |
# File 'lib/abide_dev_utils/cem/benchmark.rb', line 397 def title mapper.title end |
#title_key ⇒ Object
405 406 407 |
# File 'lib/abide_dev_utils/cem/benchmark.rb', line 405 def title_key @title_key ||= "#{title} #{version}" end |
#version ⇒ Object
401 402 403 |
# File 'lib/abide_dev_utils/cem/benchmark.rb', line 401 def version mapper.version end |