Class: Puppet::Provider::Ldap
- Inherits:
-
Puppet::Provider
- Object
- Puppet::Provider
- Puppet::Provider::Ldap
- Defined in:
- lib/puppet/provider/ldap.rb
Overview
The base class for LDAP providers.
Constant Summary
Constants inherited from Puppet::Provider
Constants included from Util::Logging
Util::Logging::FILE_AND_LINE, Util::Logging::FILE_NO_LINE, Util::Logging::MM, Util::Logging::NO_FILE_LINE, Util::Logging::SUPPRESS_FILE_LINE
Constants included from Util
Util::AbsolutePathPosix, Util::AbsolutePathWindows, Util::DEFAULT_POSIX_MODE, Util::DEFAULT_WINDOWS_MODE
Constants included from Util::POSIX
Util::POSIX::LOCALE_ENV_VARS, Util::POSIX::USER_ENV_VARS
Constants included from Util::SymbolicFileMode
Util::SymbolicFileMode::SetGIDBit, Util::SymbolicFileMode::SetUIDBit, Util::SymbolicFileMode::StickyBit, Util::SymbolicFileMode::SymbolicMode, Util::SymbolicFileMode::SymbolicSpecialToBit
Constants included from Util::Docs
Class Attribute Summary collapse
- .manager ⇒ Object readonly
Attributes inherited from Puppet::Provider
Attributes included from Util::Docs
Class Method Summary collapse
-
.instances ⇒ Object
Look up all instances at our location.
-
.manages(*args) ⇒ Object
Specify the ldap manager for this provider, which is used to figure out how we actually interact with ldap.
-
.prefetch(resources) ⇒ Object
Query all of our resources from ldap.
Instance Method Summary collapse
- #create ⇒ Object
- #delete ⇒ Object
- #exists? ⇒ Boolean
-
#flush ⇒ Object
Apply our changes to ldap, yo.
-
#initialize(*args) ⇒ Ldap
constructor
A new instance of Ldap.
-
#ldap_properties ⇒ Object
Return the current state of ldap.
- #manager ⇒ Object
-
#properties ⇒ Object
Return (and look up if necessary) the desired state.
-
#query ⇒ Object
Collect the current attributes from ldap.
Methods inherited from Puppet::Provider
#<=>, #clear, command, #command, commands, declared_feature?, default?, default_match, defaultfor, execfail, #execfail, execpipe, #execpipe, execute, #execute, fact_match, feature_match, #get, has_command, initvars, #inspect, mk_resource_methods, #name, optional_commands, post_resource_eval, #set, specificity, supports_parameter?, #to_s
Methods included from Util::Logging
#clear_deprecation_warnings, #debug, #deprecation_warning, #format_exception, #get_deprecation_offender, #log_and_raise, #log_deprecations_to_file, #log_exception, #puppet_deprecation_warning, #send_log, setup_facter_logging!, #warn_once
Methods included from Util
absolute_path?, benchmark, chuser, clear_environment, default_env, deterministic_rand, deterministic_rand_int, exit_on_fail, get_env, get_environment, logmethods, merge_environment, path_to_uri, pretty_backtrace, replace_file, safe_posix_fork, set_env, symbolizehash, thinmark, uri_encode, uri_query_encode, uri_to_path, which, withenv, withumask
Methods included from Util::POSIX
#get_posix_field, #gid, #idfield, #methodbyid, #methodbyname, #search_posix_field, #uid
Methods included from Util::SymbolicFileMode
#normalize_symbolic_mode, #symbolic_mode_to_int, #valid_symbolic_mode?
Methods included from Util::Docs
#desc, #dochook, #doctable, #markdown_definitionlist, #markdown_header, #nodoc?, #pad, scrub
Methods included from Util::Warnings
clear_warnings, debug_once, notice_once, warnonce
Methods included from Confiner
#confine, #confine_collection, #suitable?
Methods included from Util::Errors
#adderrorcontext, #devfail, #error_context, #exceptwrap, #fail
Constructor Details
#initialize(*args) ⇒ Ldap
Returns a new instance of Ldap.
76 77 78 79 80 81 82 83 84 85 86 87 88 89 90 91 92 93 94 95 96 97 98 99 100 101 102 103 104 105 106 107 |
# 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 |
Class Attribute Details
.manager ⇒ Object (readonly)
8 9 10 |
# File 'lib/puppet/provider/ldap.rb', line 8 def manager @manager end |
Class Method Details
.instances ⇒ Object
Look up all instances at our location. Yay.
12 13 14 15 16 |
# File 'lib/puppet/provider/ldap.rb', line 12 def self.instances return [] unless list = manager.search list.collect { |entry| new(entry) } end |
.manages(*args) ⇒ Object
Specify the ldap manager for this provider, which is used to figure out how we actually interact with ldap.
20 21 22 23 24 25 26 27 |
# 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 |
.prefetch(resources) ⇒ Object
Query all of our resources from ldap.
30 31 32 33 34 35 36 37 38 39 |
# 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 |
Instance Method Details
#create ⇒ Object
45 46 47 48 49 50 51 52 53 54 55 56 |
# 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 ⇒ Object
58 59 60 |
# File 'lib/puppet/provider/ldap.rb', line 58 def delete @property_hash[:ensure] = :absent end |
#exists? ⇒ Boolean
62 63 64 |
# File 'lib/puppet/provider/ldap.rb', line 62 def exists? @property_hash[:ensure] != :absent end |
#flush ⇒ Object
Apply our changes to ldap, yo.
67 68 69 70 71 72 73 74 |
# 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 ⇒ Object
Return the current state of ldap.
110 111 112 |
# File 'lib/puppet/provider/ldap.rb', line 110 def ldap_properties @ldap_properties.dup end |
#manager ⇒ Object
41 42 43 |
# File 'lib/puppet/provider/ldap.rb', line 41 def manager self.class.manager end |
#properties ⇒ Object
Return (and look up if necessary) the desired state.
115 116 117 118 119 120 121 |
# 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 ⇒ Object
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.
127 128 129 130 131 132 133 134 135 136 |
# 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 |