class Puppet::Provider::Ldap

The base class for LDAP providers.

Attributes

manager[R]

Public Class Methods

instances() click to toggle source

Look up all instances at our location. Yay.

   # File lib/puppet/provider/ldap.rb
12 def self.instances
13   list = manager.search
14   return [] unless list
15 
16   list.collect { |entry| new(entry) }
17 end
manages(*args) click to toggle source

Specify the ldap manager for this provider, which is used to figure out how we actually interact with ldap.

   # File lib/puppet/provider/ldap.rb
21 def self.manages(*args)
22   @manager = Puppet::Util::Ldap::Manager.new
23   @manager.manages(*args)
24 
25   # Set up our getter/setter methods.
26   mk_resource_methods
27   @manager
28 end
new(*args) click to toggle source
Calls superclass method Puppet::Provider::new
    # File lib/puppet/provider/ldap.rb
 79 def initialize(*args)
 80   raise(Puppet::DevError, _("No LDAP Configuration defined for %{class_name}") % { class_name: self.class }) unless self.class.manager
 81   raise(Puppet::DevError, _("Invalid LDAP Configuration defined for %{class_name}") % { class_name: self.class }) unless self.class.manager.valid?
 82   super
 83 
 84   @property_hash = @property_hash.inject({}) do |result, ary|
 85     param, values = ary
 86 
 87     # Skip any attributes we don't manage.
 88     next result unless self.class.resource_type.valid_parameter?(param)
 89 
 90     paramclass = self.class.resource_type.attrclass(param)
 91 
 92     unless values.is_a?(Array)
 93       result[param] = values
 94       next result
 95     end
 96 
 97     # Only use the first value if the attribute class doesn't manage
 98     # arrays of values.
 99     if paramclass.superclass == Puppet::Parameter or paramclass.array_matching == :first
100       result[param] = values[0]
101     else
102       result[param] = values
103     end
104     result
105   end
106 
107   # Make a duplicate, so that we have a copy for comparison
108   # at the end.
109   @ldap_properties = @property_hash.dup
110 end
prefetch(resources) click to toggle source

Query all of our resources from ldap.

   # File lib/puppet/provider/ldap.rb
31 def self.prefetch(resources)
32   resources.each do |name, resource|
33     result = manager.find(name)
34     if result
35       result[:ensure] = :present
36       resource.provider = new(result)
37     else
38       resource.provider = new(:ensure => :absent)
39     end
40   end
41 end

Public Instance Methods

create() click to toggle source
   # File lib/puppet/provider/ldap.rb
47 def create
48   @property_hash[:ensure] = :present
49   self.class.resource_type.validproperties.each do |property|
50     val = resource.should(property)
51     if val
52       if property.to_s == 'gid'
53         self.gid = val
54       else
55         @property_hash[property] = val
56       end
57     end
58   end
59 end
delete() click to toggle source
   # File lib/puppet/provider/ldap.rb
61 def delete
62   @property_hash[:ensure] = :absent
63 end
exists?() click to toggle source
   # File lib/puppet/provider/ldap.rb
65 def exists?
66   @property_hash[:ensure] != :absent
67 end
flush() click to toggle source

Apply our changes to ldap, yo.

   # File lib/puppet/provider/ldap.rb
70 def flush
71   # Just call the manager's update() method.
72   @property_hash.delete(:groups)
73   @ldap_properties.delete(:groups)
74   manager.update(name, ldap_properties, properties)
75   @property_hash.clear
76   @ldap_properties.clear
77 end
ldap_properties() click to toggle source

Return the current state of ldap.

    # File lib/puppet/provider/ldap.rb
113 def ldap_properties
114   @ldap_properties.dup
115 end
manager() click to toggle source
   # File lib/puppet/provider/ldap.rb
43 def manager
44   self.class.manager
45 end
properties() click to toggle source

Return (and look up if necessary) the desired state.

    # File lib/puppet/provider/ldap.rb
118 def properties
119   if @property_hash.empty?
120     @property_hash = query || {:ensure => :absent}
121     @property_hash[:ensure] = :absent if @property_hash.empty?
122   end
123   @property_hash.dup
124 end
query() click to toggle source

Collect the current attributes from ldap. Returns the results, but also stores the attributes locally, so we have something to compare against when we update. LAK:NOTE This is normally not used, because we rely on prefetching.

    # File lib/puppet/provider/ldap.rb
130 def query
131   # Use the module function.
132   attributes = manager.find(name)
133   unless attributes
134     @ldap_properties = {}
135     return nil
136   end
137 
138   @ldap_properties = attributes
139   @ldap_properties.dup
140 end