diff options
| author | luke <luke@980ebf18-57e1-0310-9a29-db15c13687c0> | 2006-06-13 23:41:04 +0000 |
|---|---|---|
| committer | luke <luke@980ebf18-57e1-0310-9a29-db15c13687c0> | 2006-06-13 23:41:04 +0000 |
| commit | 02d397c7c7d08ac6203f231032cc4ab6dcf70dd9 (patch) | |
| tree | c606fa76cd0582594f4343e5f01b9c12f1965a4f /lib/puppet/parser | |
| parent | 076e8889a7c566415cb6dca1019aaaa2f14ef8bb (diff) | |
| download | puppet-02d397c7c7d08ac6203f231032cc4ab6dcf70dd9.tar.gz puppet-02d397c7c7d08ac6203f231032cc4ab6dcf70dd9.tar.xz puppet-02d397c7c7d08ac6203f231032cc4ab6dcf70dd9.zip | |
abstracting out ldap connections so that there is a single method responsible for all of them and a single connection can be shared in all classes if necessary
git-svn-id: https://reductivelabs.com/svn/puppet/trunk@1270 980ebf18-57e1-0310-9a29-db15c13687c0
Diffstat (limited to 'lib/puppet/parser')
| -rw-r--r-- | lib/puppet/parser/interpreter.rb | 34 |
1 files changed, 22 insertions, 12 deletions
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 |
