Module: HardeningStdlib

Extended by:
HardeningStdlib
Included in:
HardeningStdlib
Defined in:
lib/puppet/parser/functions/merge_hardening.rb

Instance Method Summary collapse

Instance Method Details

#deep_merge_hardening(user_param, hardening_param, name) ⇒ Object



13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
# File 'lib/puppet/parser/functions/merge_hardening.rb', line 13

def deep_merge_hardening user_param, hardening_param, name
  # merge hashes
  if user_param.instance_of? Hash and
    hardening_param.instance_of? Hash

    # do a manual merge since we need to see what is set
    # or gets overwritten
    hardening_param.each do |k,v|
      # only set the hardening parameter, if the user
      # didn't define it himself
      if not user_param.key? k
        user_param[k] = v
        next
      end

      user_param[k] = deep_merge_hardening user_param[k], hardening_param[k], "#{name}[#{k}]"
    end

  else

    # merge simple values
    if user_param.nil?
      user_param = hardening_param
    end

    if user_param != hardening_param
      Puppet.warning "Hardening parameters: you already defined '#{name}' as '#{user_param}'. "+
        "Hardening recommends to use '#{hardening_param}'."
    end

  end

  # finally return the merged result
  user_param
end