Puppet Function: linux_secured::delegate_to_validator

Defined in:
lib/puppet/functions/linux_secured/delegate_to_validator.rb
Function type:
Ruby 4.x API

Summary

This function uses its current scope te infer what CIS rule is called on what SID.

Overview

linux_secured::delegate_to_validator()Any

Returns:

  • (Any)


7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
# File 'lib/puppet/functions/linux_secured/delegate_to_validator.rb', line 7

Puppet::Functions.create_function('linux_secured::delegate_to_validator', Puppet::Functions::InternalFunction) do
  dispatch :delegate_to_validator do
    scope_param
  end

  def delegate_to_validator(scope)
    validator_ref  = scope.to_s.gsub('::Controls::','::Validators::').gsub(/^Scope\(|\)$/,'')
    validator_impl = scope.catalog.resources.select  { |e| e.to_s == validator_ref }.first
    validator_type = validator_ref.downcase.gsub(/\[.*\]/, '')
    name           = validator_ref.scan(/\[(.*)\]/).flatten.first
    #
    # If already in catalog do nothing
    #
    if validator_impl.nil? 
      create_resources(validator_type, { name => {}})
    else
      scope.debug "Validator already in catalog so skipping."
    end
  end

  def create_resources(type, resources)
    call_function('create_resources', type, resources)
  end
end