1 module Puppet::Parser::Functions
2 newfunction(:postgresql_acls_to_resources_hash, :type => :rvalue, :doc => <<-EOS
3 This internal function translates the ipv(4|6)acls format into a resource
4 suitable for create_resources. It is not intended to be used outside of the
5 postgresql internal classes/defined resources.
7 This function accepts an array of strings that are pg_hba.conf rules. It
8 will return a hash that can be fed into create_resources to create multiple
9 individual pg_hba_rule resources.
11 The second parameter is an identifier that will be included in the namevar
12 to provide uniqueness. It must be a string.
14 The third parameter is an order offset, so you can start the order at an
15 arbitrary starting point.
18 func_name = "postgresql_acls_to_resources_hash()"
20 raise(Puppet::ParseError, "#{func_name}: Wrong number of arguments " +
21 "given (#{args.size} for 3)") if args.size != 3
24 raise(Puppet::ParseError, "#{func_name}: first argument must be an array") \
25 unless acls.instance_of? Array
28 raise(Puppet::ParseError, "#{func_name}: second argument must be a string") \
29 unless id.instance_of? String
32 raise(Puppet::ParseError, "#{func_name}: third argument must be a number") \
33 unless offset.instance_of? Fixnum
37 index = acls.index(acl)
41 raise(Puppet::ParseError, "#{func_name}: acl line #{index} does not " +
42 "have enough parts") unless parts.length >= 4
46 'database' => parts[1],
48 'order' => format('%03d', offset + index),
50 if parts[0] == 'local' then
51 resource['auth_method'] = parts[3]
52 if parts.length > 4 then
53 resource['auth_option'] = parts.last(parts.length - 4).join(" ")
57 resource['address'] = parts[3] + ' ' + parts[4]
58 resource['auth_method'] = parts[5]
60 if parts.length > 6 then
61 resource['auth_option'] = parts.last(parts.length - 6).join(" ")
64 resource['address'] = parts[3]
65 resource['auth_method'] = parts[4]
67 if parts.length > 5 then
68 resource['auth_option'] = parts.last(parts.length - 5).join(" ")
72 resources["postgresql class generated rule #{id} #{index}"] = resource