Class: AbideDevUtils::Sce::Benchmark

Inherits:
Object
  • Object
show all
Defined in:
lib/abide_dev_utils/sce/benchmark.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.



341
342
343
344
345
346
347
348
349
350
351
352
353
354
355
356
357
358
359
# File 'lib/abide_dev_utils/sce/benchmark.rb', line 341

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 = {}
  @mapper = AbideDevUtils::Sce::Mapping::Mapper.new(@module_name, @framework, load_mapping_data)
  @resource_data = load_resource_data
  @resources = @resource_data["#{module_name}::resources"].each_with_object([]) do |(rtitle, rdata), arr|
    arr << Resource.new(rtitle, rdata, framework, mapper)
  end
  @controls = resources.map(&:controls).flatten.sort
end

Instance Attribute Details

#controlsObject (readonly) Also known as: rules

Returns the value of attribute controls.



336
337
338
# File 'lib/abide_dev_utils/sce/benchmark.rb', line 336

def controls
  @controls
end

#frameworkObject (readonly)

Returns the value of attribute framework.



336
337
338
# File 'lib/abide_dev_utils/sce/benchmark.rb', line 336

def framework
  @framework
end

#hiera_confObject (readonly)

Returns the value of attribute hiera_conf.



336
337
338
# File 'lib/abide_dev_utils/sce/benchmark.rb', line 336

def hiera_conf
  @hiera_conf
end

#major_versionObject (readonly)

Returns the value of attribute major_version.



336
337
338
# File 'lib/abide_dev_utils/sce/benchmark.rb', line 336

def major_version
  @major_version
end

#mapperObject (readonly)

Returns the value of attribute mapper.



336
337
338
# File 'lib/abide_dev_utils/sce/benchmark.rb', line 336

def mapper
  @mapper
end

#module_nameObject (readonly)

Returns the value of attribute module_name.



336
337
338
# File 'lib/abide_dev_utils/sce/benchmark.rb', line 336

def module_name
  @module_name
end

#os_factsObject (readonly)

Returns the value of attribute os_facts.



336
337
338
# File 'lib/abide_dev_utils/sce/benchmark.rb', line 336

def os_facts
  @os_facts
end

#osfamilyObject (readonly)

Returns the value of attribute osfamily.



336
337
338
# File 'lib/abide_dev_utils/sce/benchmark.rb', line 336

def osfamily
  @osfamily
end

#osnameObject (readonly)

Returns the value of attribute osname.



336
337
338
# File 'lib/abide_dev_utils/sce/benchmark.rb', line 336

def osname
  @osname
end

#resource_dataObject (readonly)

Returns the value of attribute resource_data.



336
337
338
# File 'lib/abide_dev_utils/sce/benchmark.rb', line 336

def resource_data
  @resource_data
end

#resourcesObject (readonly)

Returns the value of attribute resources.



336
337
338
# File 'lib/abide_dev_utils/sce/benchmark.rb', line 336

def resources
  @resources
end

Instance Method Details

#add_rule(rule_hash) ⇒ Object



377
378
379
# File 'lib/abide_dev_utils/sce/benchmark.rb', line 377

def add_rule(rule_hash)
  @rules << rule_hash
end

#inspectObject



413
414
415
# File 'lib/abide_dev_utils/sce/benchmark.rb', line 413

def inspect
  "#<#{self.class.name}:#{object_id} title: #{title}, version: #{version}, module_name: #{module_name}, framework: #{framework}>"
end

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



401
402
403
# File 'lib/abide_dev_utils/sce/benchmark.rb', line 401

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

#map_dataObject



361
362
363
# File 'lib/abide_dev_utils/sce/benchmark.rb', line 361

def map_data
  mapper.map_data
end

#map_type(control_id) ⇒ Object



405
406
407
# File 'lib/abide_dev_utils/sce/benchmark.rb', line 405

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

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



381
382
383
384
385
386
387
388
389
390
391
392
393
394
395
396
397
398
399
# File 'lib/abide_dev_utils/sce/benchmark.rb', line 381

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



365
366
367
# File 'lib/abide_dev_utils/sce/benchmark.rb', line 365

def title
  mapper.title
end

#title_keyObject



373
374
375
# File 'lib/abide_dev_utils/sce/benchmark.rb', line 373

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

#to_sObject



409
410
411
# File 'lib/abide_dev_utils/sce/benchmark.rb', line 409

def to_s
  title
end

#versionObject



369
370
371
# File 'lib/abide_dev_utils/sce/benchmark.rb', line 369

def version
  mapper.version
end