Class: Puppet::Util::Ldap::Connection
- Defined in:
- lib/vendor/puppet/util/ldap/connection.rb
Instance Attribute Summary collapse
-
#connection ⇒ Object
readonly
Returns the value of attribute connection.
-
#host ⇒ Object
Returns the value of attribute host.
-
#password ⇒ Object
Returns the value of attribute password.
-
#port ⇒ Object
Returns the value of attribute port.
-
#reset ⇒ Object
Returns the value of attribute reset.
-
#ssl ⇒ Object
Returns the value of attribute ssl.
-
#user ⇒ Object
Returns the value of attribute user.
Class Method Summary collapse
-
.instance ⇒ Object
Return a default connection, using our default settings.
Instance Method Summary collapse
- #close ⇒ Object
-
#initialize(host, port, options = {}) ⇒ Connection
constructor
A new instance of Connection.
-
#name ⇒ Object
Create a per-connection unique name.
-
#reset? ⇒ Boolean
Should we reset the connection?.
-
#start ⇒ Object
Start our ldap connection.
Constructor Details
#initialize(host, port, options = {}) ⇒ Connection
Returns a new instance of Connection.
34 35 36 37 38 39 40 41 42 43 44 45 46 |
# File 'lib/vendor/puppet/util/ldap/connection.rb', line 34 def initialize(host, port, = {}) raise Puppet::Error, "Could not set up LDAP Connection: Missing ruby/ldap libraries" unless Puppet.features.ldap? @host, @port = host, port .each do |param, value| begin send(param.to_s + "=", value) rescue raise ArgumentError, "LDAP connections do not support #{param} parameters" end end end |
Instance Attribute Details
#connection ⇒ Object (readonly)
Returns the value of attribute connection.
6 7 8 |
# File 'lib/vendor/puppet/util/ldap/connection.rb', line 6 def connection @connection end |
#host ⇒ Object
Returns the value of attribute host.
4 5 6 |
# File 'lib/vendor/puppet/util/ldap/connection.rb', line 4 def host @host end |
#password ⇒ Object
Returns the value of attribute password.
4 5 6 |
# File 'lib/vendor/puppet/util/ldap/connection.rb', line 4 def password @password end |
#port ⇒ Object
Returns the value of attribute port.
4 5 6 |
# File 'lib/vendor/puppet/util/ldap/connection.rb', line 4 def port @port end |
#reset ⇒ Object
Returns the value of attribute reset.
4 5 6 |
# File 'lib/vendor/puppet/util/ldap/connection.rb', line 4 def reset @reset end |
#ssl ⇒ Object
Returns the value of attribute ssl.
4 5 6 |
# File 'lib/vendor/puppet/util/ldap/connection.rb', line 4 def ssl @ssl end |
#user ⇒ Object
Returns the value of attribute user.
4 5 6 |
# File 'lib/vendor/puppet/util/ldap/connection.rb', line 4 def user @user end |
Class Method Details
.instance ⇒ Object
Return a default connection, using our default settings.
9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 |
# File 'lib/vendor/puppet/util/ldap/connection.rb', line 9 def self.instance ssl = if Puppet[:ldaptls] :tls elsif Puppet[:ldapssl] true else false end = {} [:ssl] = ssl if user = Puppet.settings[:ldapuser] and user != "" [:user] = user if pass = Puppet.settings[:ldappassword] and pass != "" [:password] = pass end end new(Puppet[:ldapserver], Puppet[:ldapport], ) end |
Instance Method Details
#close ⇒ Object
30 31 32 |
# File 'lib/vendor/puppet/util/ldap/connection.rb', line 30 def close connection.unbind if connection.bound? end |
#name ⇒ Object
Create a per-connection unique name.
49 50 51 |
# File 'lib/vendor/puppet/util/ldap/connection.rb', line 49 def name [host, port, user, password, ssl].collect { |p| p.to_s }.join("/") end |
#reset? ⇒ Boolean
Should we reset the connection?
54 55 56 |
# File 'lib/vendor/puppet/util/ldap/connection.rb', line 54 def reset? reset end |
#start ⇒ Object
Start our ldap connection.
59 60 61 62 63 64 65 66 67 68 69 70 71 72 73 |
# File 'lib/vendor/puppet/util/ldap/connection.rb', line 59 def start case ssl when :tls @connection = LDAP::SSLConn.new(host, port, true) when true @connection = LDAP::SSLConn.new(host, port) else @connection = LDAP::Conn.new(host, port) end @connection.set_option(LDAP::LDAP_OPT_PROTOCOL_VERSION, 3) @connection.set_option(LDAP::LDAP_OPT_REFERRALS, LDAP::LDAP_OPT_ON) @connection.simple_bind(user, password) rescue => detail raise Puppet::Error, "Could not connect to LDAP: #{detail}" end |