Class: AbideDevUtils::Sce::HieraData::MappingData::Mapper

Inherits:
Object
  • Object
show all
Defined in:
lib/abide_dev_utils/sce/hiera_data/mapping_data.rb

Overview

Handles interacting with mapping data

Instance Attribute Summary collapse

Instance Method Summary collapse

Constructor Details

#initialize(module_name, framework, map_data) ⇒ Mapper

Returns a new instance of Mapper.



22
23
24
25
26
27
28
29
# File 'lib/abide_dev_utils/sce/hiera_data/mapping_data.rb', line 22

def initialize(module_name, framework, map_data)
  @module_name = module_name
  @framework = framework
  load_framework(@framework)
  @map_data = map_data.map { |_, v| MapData.new(v) }
  @cache = {}
  @rule_cache = {}
end

Instance Attribute Details

#frameworkObject (readonly)

Returns the value of attribute framework.



20
21
22
# File 'lib/abide_dev_utils/sce/hiera_data/mapping_data.rb', line 20

def framework
  @framework
end

#map_dataObject (readonly)

Returns the value of attribute map_data.



20
21
22
# File 'lib/abide_dev_utils/sce/hiera_data/mapping_data.rb', line 20

def map_data
  @map_data
end

#module_nameObject (readonly)

Returns the value of attribute module_name.



20
21
22
# File 'lib/abide_dev_utils/sce/hiera_data/mapping_data.rb', line 20

def module_name
  @module_name
end

Instance Method Details

#each_like(identifier) ⇒ Object



47
48
49
# File 'lib/abide_dev_utils/sce/hiera_data/mapping_data.rb', line 47

def each_like(identifier)
  identified_map_data(identifier)&.each { |key, val| yield key, val }
end

#each_with_array_like(identifier) ⇒ Object



51
52
53
# File 'lib/abide_dev_utils/sce/hiera_data/mapping_data.rb', line 51

def each_with_array_like(identifier)
  identified_map_data(identifier)&.each_with_object([]) { |(key, val), ary| yield [key, val], ary }
end

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



55
56
57
# File 'lib/abide_dev_utils/sce/hiera_data/mapping_data.rb', line 55

def get(control_id, level: nil, profile: nil)
  identified_map_data(control_id)&.get(control_id, level: level, profile: profile)
end

#levelsObject



39
40
41
# File 'lib/abide_dev_utils/sce/hiera_data/mapping_data.rb', line 39

def levels
  @levels ||= default_map_data.levels
end

#map_type(control_id) ⇒ Object



59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
# File 'lib/abide_dev_utils/sce/hiera_data/mapping_data.rb', line 59

def map_type(control_id)
  return control_id if ALL_TYPES.include?(control_id)

  case control_id
  when %r{^c[0-9_]+$}
    'hiera_title_num'
  when %r{^[0-9][0-9.]*$}
    'number'
  when %r{^[a-z][a-z0-9_]+$}
    'hiera_title'
  when %r{^V-[0-9]{6}$}
    'vulnid'
  else
    'title'
  end
end

#profilesObject



43
44
45
# File 'lib/abide_dev_utils/sce/hiera_data/mapping_data.rb', line 43

def profiles
  @profiles ||= default_map_data.profiles
end

#titleObject



31
32
33
# File 'lib/abide_dev_utils/sce/hiera_data/mapping_data.rb', line 31

def title
  @title ||= benchmark_data['title']
end

#versionObject



35
36
37
# File 'lib/abide_dev_utils/sce/hiera_data/mapping_data.rb', line 35

def version
  @version ||= benchmark_data['version']
end