# 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, line 12
    def self.instances
      return [] unless list = manager.search

      list.collect { |entry| new(entry) }
    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, line 20
    def self.manages(*args)
      @manager = Puppet::Util::Ldap::Manager.new
      @manager.manages(*args)

      # Set up our getter/setter methods.
      mk_resource_methods
      @manager
    end

new(*args) click to toggle source
Calls superclass method Puppet::Provider.new

    # File lib/puppet/provider/ldap.rb, line 76
    def initialize(*args)
      raise(Puppet::DevError, "No LDAP Configuration defined for #{self.class}") unless self.class.manager
      raise(Puppet::DevError, "Invalid LDAP Configuration defined for #{self.class}") unless self.class.manager.valid?
      super

      @property_hash = @property_hash.inject({}) do |result, ary|
        param, values = ary

        # Skip any attributes we don't manage.
        next result unless self.class.resource_type.valid_parameter?(param)

        paramclass = self.class.resource_type.attrclass(param)

        unless values.is_a?(Array)
          result[param] = values
          next result
        end

        # Only use the first value if the attribute class doesn't manage
        # arrays of values.
        if paramclass.superclass == Puppet::Parameter or paramclass.array_matching == :first
          result[param] = values[0]
        else
          result[param] = values
        end
        result
      end

      # Make a duplicate, so that we have a copy for comparison
      # at the end.
      @ldap_properties = @property_hash.dup
    end

prefetch(resources) click to toggle source

Query all of our resources from ldap.

    # File lib/puppet/provider/ldap.rb, line 30
    def self.prefetch(resources)
      resources.each do |name, resource|
        if result = manager.find(name)
          result[:ensure] = :present
          resource.provider = new(result)
        else
          resource.provider = new(:ensure => :absent)
        end
      end
    end

### Public Instance Methods

create() click to toggle source

    # File lib/puppet/provider/ldap.rb, line 45
    def create
      @property_hash[:ensure] = :present
      self.class.resource_type.validproperties.each do |property|
        if val = resource.should(property)
          if property.to_s == 'gid'
            self.gid = val
          else
            @property_hash[property] = val
          end
        end
      end
    end

delete() click to toggle source

    # File lib/puppet/provider/ldap.rb, line 58
    def delete
      @property_hash[:ensure] = :absent
    end

exists?() click to toggle source

    # File lib/puppet/provider/ldap.rb, line 62
    def exists?
      @property_hash[:ensure] != :absent
    end

flush() click to toggle source

Apply our changes to ldap, yo.

    # File lib/puppet/provider/ldap.rb, line 67
    def flush
      # Just call the manager's update() method.
      @property_hash.delete(:groups)
      @ldap_properties.delete(:groups)
      manager.update(name, ldap_properties, properties)
      @property_hash.clear
      @ldap_properties.clear
    end

ldap_properties() click to toggle source

Return the current state of ldap.

    # File lib/puppet/provider/ldap.rb, line 110
    def ldap_properties
      @ldap_properties.dup
    end

manager() click to toggle source

    # File lib/puppet/provider/ldap.rb, line 41
    def manager
      self.class.manager
    end

properties() click to toggle source

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

    # File lib/puppet/provider/ldap.rb, line 115
    def properties
      if @property_hash.empty?
        @property_hash = query || {:ensure => :absent}
        @property_hash[:ensure] = :absent if @property_hash.empty?
      end
      @property_hash.dup
    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, line 127
    def query
      # Use the module function.
      unless attributes = manager.find(name)
        @ldap_properties = {}
        return nil
      end

      @ldap_properties = attributes
      @ldap_properties.dup
    end