diff options
-rwxr-xr-x | bin/puppetrun | 10 | ||||
-rw-r--r-- | lib/puppet/parser/interpreter.rb | 34 |
2 files changed, 23 insertions, 21 deletions
diff --git a/bin/puppetrun b/bin/puppetrun index 0351b4cbc..2bec5d029 100755 --- a/bin/puppetrun +++ b/bin/puppetrun @@ -104,15 +104,7 @@ end def setupldap begin - if Puppet[:ldapssl] - @ldap = LDAP::SSLConn.new(Puppet[:ldapserver], Puppet[:ldapport]) - elsif Puppet[:ldaptls] - @ldap = LDAP::SSLConn.new(Puppet[:ldapserver], Puppet[:ldapport], true) - else - @ldap = LDAP::Conn.new(Puppet[:ldapserver], Puppet[:ldapport]) - end - @ldap.set_option(LDAP::LDAP_OPT_PROTOCOL_VERSION, 3) - @ldap.simple_bind(Puppet[:ldapuser], Puppet[:ldappassword]) + @ldap = Puppet::Parser::Interpreter.ldap() rescue => detail $stderr.puts "Could not connect to LDAP: %s" % detail exit(34) diff --git a/lib/puppet/parser/interpreter.rb b/lib/puppet/parser/interpreter.rb index 7bfb25ea4..daf8accf0 100644 --- a/lib/puppet/parser/interpreter.rb +++ b/lib/puppet/parser/interpreter.rb @@ -56,6 +56,27 @@ module Puppet # just shorten the constant path a bit, using what amounts to an alias AST = Puppet::Parser::AST + # Create an ldap connection. This is a class method so others can call + # it and use the same variables and such. + def self.ldap + unless defined? @ldap and @ldap + if Puppet[:ldapssl] + @ldap = LDAP::SSLConn.new(Puppet[:ldapserver], Puppet[:ldapport]) + elsif Puppet[:ldaptls] + @ldap = LDAP::SSLConn.new( + Puppet[:ldapserver], Puppet[:ldapport], true + ) + else + @ldap = LDAP::Conn.new(Puppet[:ldapserver], Puppet[:ldapport]) + end + @ldap.set_option(LDAP::LDAP_OPT_PROTOCOL_VERSION, 3) + @ldap.set_option(LDAP::LDAP_OPT_REFERRALS, LDAP::LDAP_OPT_ON) + @ldap.simple_bind(Puppet[:ldapuser], Puppet[:ldappassword]) + end + + return @ldap + end + # create our interpreter def initialize(hash) if @code = hash[:Code] @@ -126,18 +147,7 @@ module Puppet return end begin - if Puppet[:ldapssl] - @ldap = LDAP::SSLConn.new(Puppet[:ldapserver], Puppet[:ldapport]) - elsif Puppet[:ldaptls] - @ldap = LDAP::SSLConn.new( - Puppet[:ldapserver], Puppet[:ldapport], true - ) - else - @ldap = LDAP::Conn.new(Puppet[:ldapserver], Puppet[:ldapport]) - end - @ldap.set_option(LDAP::LDAP_OPT_PROTOCOL_VERSION, 3) - @ldap.set_option(LDAP::LDAP_OPT_REFERRALS, LDAP::LDAP_OPT_ON) - @ldap.simple_bind(Puppet[:ldapuser], Puppet[:ldappassword]) + @ldap = self.class.ldap() rescue => detail raise Puppet::Error, "Could not connect to LDAP: %s" % detail end |