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 13 def self.instances 14 list = manager.search 15 return [] unless list 16 17 list.collect { |entry| new(entry) } 18 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 22 def self.manages(*args) 23 @manager = Puppet::Util::Ldap::Manager.new 24 @manager.manages(*args) 25 26 # Set up our getter/setter methods. 27 mk_resource_methods 28 @manager 29 end
new(*args)
click to toggle source
Calls superclass method
Puppet::Provider::new
# File lib/puppet/provider/ldap.rb 80 def initialize(*args) 81 raise(Puppet::DevError, _("No LDAP Configuration defined for %{class_name}") % { class_name: self.class }) unless self.class.manager 82 raise(Puppet::DevError, _("Invalid LDAP Configuration defined for %{class_name}") % { class_name: self.class }) unless self.class.manager.valid? 83 super 84 85 @property_hash = @property_hash.inject({}) do |result, ary| 86 param, values = ary 87 88 # Skip any attributes we don't manage. 89 next result unless self.class.resource_type.valid_parameter?(param) 90 91 paramclass = self.class.resource_type.attrclass(param) 92 93 unless values.is_a?(Array) 94 result[param] = values 95 next result 96 end 97 98 # Only use the first value if the attribute class doesn't manage 99 # arrays of values. 100 if paramclass.superclass == Puppet::Parameter or paramclass.array_matching == :first 101 result[param] = values[0] 102 else 103 result[param] = values 104 end 105 result 106 end 107 108 # Make a duplicate, so that we have a copy for comparison 109 # at the end. 110 @ldap_properties = @property_hash.dup 111 end
prefetch(resources)
click to toggle source
Query all of our resources from ldap.
# File lib/puppet/provider/ldap.rb 32 def self.prefetch(resources) 33 resources.each do |name, resource| 34 result = manager.find(name) 35 if result 36 result[:ensure] = :present 37 resource.provider = new(result) 38 else 39 resource.provider = new(:ensure => :absent) 40 end 41 end 42 end
Public Instance Methods
create()
click to toggle source
# File lib/puppet/provider/ldap.rb 48 def create 49 @property_hash[:ensure] = :present 50 self.class.resource_type.validproperties.each do |property| 51 val = resource.should(property) 52 if val 53 if property.to_s == 'gid' 54 self.gid = val 55 else 56 @property_hash[property] = val 57 end 58 end 59 end 60 end
delete()
click to toggle source
# File lib/puppet/provider/ldap.rb 62 def delete 63 @property_hash[:ensure] = :absent 64 end
exists?()
click to toggle source
# File lib/puppet/provider/ldap.rb 66 def exists? 67 @property_hash[:ensure] != :absent 68 end
flush()
click to toggle source
Apply our changes to ldap, yo.
# File lib/puppet/provider/ldap.rb 71 def flush 72 # Just call the manager's update() method. 73 @property_hash.delete(:groups) 74 @ldap_properties.delete(:groups) 75 manager.update(name, ldap_properties, properties) 76 @property_hash.clear 77 @ldap_properties.clear 78 end
ldap_properties()
click to toggle source
Return the current state of ldap.
# File lib/puppet/provider/ldap.rb 114 def ldap_properties 115 @ldap_properties.dup 116 end
manager()
click to toggle source
# File lib/puppet/provider/ldap.rb 44 def manager 45 self.class.manager 46 end
properties()
click to toggle source
Return (and look up if necessary) the desired state.
# File lib/puppet/provider/ldap.rb 119 def properties 120 if @property_hash.empty? 121 @property_hash = query || {:ensure => :absent} 122 @property_hash[:ensure] = :absent if @property_hash.empty? 123 end 124 @property_hash.dup 125 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 131 def query 132 # Use the module function. 133 attributes = manager.find(name) 134 unless attributes 135 @ldap_properties = {} 136 return nil 137 end 138 139 @ldap_properties = attributes 140 @ldap_properties.dup 141 end