Puppet Function: postgresql::postgresql_acls_to_resources_hash
  
    - Defined in:
 
    - 
      lib/puppet/functions/postgresql/postgresql_acls_to_resources_hash.rb
    
 
  
  
    - Function type:
 
    - Ruby 4.x API
 
  
 
  Summary
  This internal function translates the ipv(4|6)acls format into a resource suitable for create_resources.
Overview
  
  
    
      
        postgresql::postgresql_acls_to_resources_hash(Array[String] $acls, String[1] $id, Integer[0] $offset) ⇒ Hash 
      
    
  
  
  
  
  
    
      
        
5
6
7
8
9
10
11
12
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
48
49
50
51
52
53
54
55
56
57
58
59 
       | 
      
        # File 'lib/puppet/functions/postgresql/postgresql_acls_to_resources_hash.rb', line 5
Puppet::Functions.create_function(:'postgresql::postgresql_acls_to_resources_hash') do
                    dispatch :default_impl do
    param 'Array[String]', :acls
    param 'String[1]', :id
    param 'Integer[0]', :offset
  end
  def default_impl(acls, id, offset)
    resources = {}
    acls.each do |acl|
      index = acls.index(acl)
      parts = acl.split
      unless parts.length >= 4
        raise(Puppet::ParseError, "postgresql::postgresql_acls_to_resources_hash(): acl line #{index} does not " \
          'have enough parts')
      end
      resource = {
        'type'     => parts[0],
        'database' => parts[1],
        'user'     => parts[2],
        'order'    => '%03d' % (offset + index),
      }
      if parts[0] == 'local'
        resource['auth_method'] = parts[3]
        if parts.length > 4
          resource['auth_option'] = parts.last(parts.length - 4).join(' ')
        end
      elsif %r{^\d}.match?(parts[4])
        resource['address'] = parts[3] + ' ' + parts[4]
        resource['auth_method'] = parts[5]
        resource['auth_option'] = parts.last(parts.length - 6).join(' ') if parts.length > 6
      else
        resource['address'] = parts[3]
        resource['auth_method'] = parts[4]
        resource['auth_option'] = parts.last(parts.length - 5).join(' ') if parts.length > 5
      end
      resources["postgresql class generated rule #{id} #{index}"] = resource
    end
    resources
  end
end
       |