Class: AbideDevUtils::CEM::HieraData::ResourceData::Resource

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

Overview

Represents a resource data resource statement

Instance Attribute Summary collapse

Instance Method Summary collapse

Constructor Details

#initialize(title, data, framework, mapper) ⇒ Resource

Returns a new instance of Resource.



16
17
18
19
20
21
22
# File 'lib/abide_dev_utils/cem/hiera_data/resource_data/resource.rb', line 16

def initialize(title, data, framework, mapper)
  @title = title
  @data = data
  @type = data['type']
  @framework = framework
  @mapper = mapper
end

Instance Attribute Details

#titleObject (readonly)

Returns the value of attribute title.



14
15
16
# File 'lib/abide_dev_utils/cem/hiera_data/resource_data/resource.rb', line 14

def title
  @title
end

#typeObject (readonly)

Returns the value of attribute type.



14
15
16
# File 'lib/abide_dev_utils/cem/hiera_data/resource_data/resource.rb', line 14

def type
  @type
end

Instance Method Details

#cem_optionsObject



28
29
30
# File 'lib/abide_dev_utils/cem/hiera_data/resource_data/resource.rb', line 28

def cem_options
  @cem_options ||= Parameters.new(data['cem_options'])
end

#cem_protectedObject



32
33
34
# File 'lib/abide_dev_utils/cem/hiera_data/resource_data/resource.rb', line 32

def cem_protected
  @cem_protected ||= Parameters.new(data['cem_protected'])
end

#controlsObject



24
25
26
# File 'lib/abide_dev_utils/cem/hiera_data/resource_data/resource.rb', line 24

def controls
  @controls ||= load_controls
end

#to_puppet_codeObject



50
51
52
53
54
55
56
57
58
59
60
61
62
63
# File 'lib/abide_dev_utils/cem/hiera_data/resource_data/resource.rb', line 50

def to_puppet_code
  parray = controls.map { |x| x.parameters.to_puppet_code if x.parameters.exist? }.flatten.compact.uniq
  return "#{type} { '#{title}': }" if parray.empty? || parray.all?(&:empty?) || parray.all?("\n")

  # if title == 'cem_linux::utils::packages::linux::auditd::time_change'
  #   require 'pry'
  #   binding.pry
  # end
  <<~EOPC
    #{type} { '#{title}':
    #{parray.join("\n")}
    }
  EOPC
end

#to_referenceObject



46
47
48
# File 'lib/abide_dev_utils/cem/hiera_data/resource_data/resource.rb', line 46

def to_reference
  "#{type.split('::').map(&:capitalize).join('::')}['#{title}']"
end

#to_stubbed_hObject



36
37
38
39
40
41
42
43
44
# File 'lib/abide_dev_utils/cem/hiera_data/resource_data/resource.rb', line 36

def to_stubbed_h
  {
    title: title,
    type: type,
    cem_options: cem_options.to_h,
    cem_protected: cem_protected.to_h,
    reference: to_reference,
  }
end