|
@@ -6,17 +6,17 @@ class Puppet::Provider::Openldap < Puppet::Provider
|
|
|
initvars
|
|
|
|
|
|
# Declare binaries that we use
|
|
|
- commands original_ldapadd: 'ldapadd',
|
|
|
- original_ldapmodify: 'ldapmodify',
|
|
|
- original_slapcat: 'slapcat'
|
|
|
+ commands cmd_ldapadd: 'ldapadd',
|
|
|
+ cmd_ldapmodify: 'ldapmodify',
|
|
|
+ cmd_slapcat: 'slapcat'
|
|
|
|
|
|
# Class-level wrapper methods for ldap binaries
|
|
|
def self.ldapadd(path)
|
|
|
- original_ldapadd('-cQY', 'EXTERNAL', '-H', 'ldapi:///', '-f', path)
|
|
|
+ cmd_ldapadd('-cQY', 'EXTERNAL', '-H', 'ldapi:///', '-f', path)
|
|
|
end
|
|
|
|
|
|
def self.ldapmodify(path)
|
|
|
- original_ldapmodify('-Y', 'EXTERNAL', '-H', 'ldapi:///', '-f', path)
|
|
|
+ cmd_ldapmodify('-Y', 'EXTERNAL', '-H', 'ldapi:///', '-f', path)
|
|
|
end
|
|
|
|
|
|
def self.slapcat(filter, dn = '', base = 'cn=config')
|
|
@@ -26,7 +26,7 @@ class Puppet::Provider::Openldap < Puppet::Provider
|
|
|
'-H', "ldap:///#{dn}???#{filter}"
|
|
|
]
|
|
|
|
|
|
- original_slapcat(*arguments)
|
|
|
+ cmd_slapcat(*arguments)
|
|
|
end
|
|
|
|
|
|
# Instance-level wrapper methods
|
|
@@ -83,4 +83,40 @@ class Puppet::Provider::Openldap < Puppet::Provider
|
|
|
def key_with_value(key, value)
|
|
|
"olc#{key}: #{value}\n"
|
|
|
end
|
|
|
+
|
|
|
+ # Turn LDIF output into an array of olc attributes
|
|
|
+ def self.get_lines(items)
|
|
|
+ items.strip
|
|
|
+ .gsub("\n ", '')
|
|
|
+ .split("\n")
|
|
|
+ .select { |e| e =~ %r{^olc} }
|
|
|
+ .map { |e| e.gsub(%r{^olc}, '') }
|
|
|
+ end
|
|
|
+
|
|
|
+ def get_lines(*args)
|
|
|
+ self.class.get_lines(*args)
|
|
|
+ end
|
|
|
+
|
|
|
+ # Turn LDIF output into a 2D array of entries
|
|
|
+ def self.get_entries(items)
|
|
|
+ items.strip
|
|
|
+ .split("\n\n")
|
|
|
+ .map do |p|
|
|
|
+ p.gsub("\n ", '')
|
|
|
+ .split("\n")
|
|
|
+ end
|
|
|
+ end
|
|
|
+
|
|
|
+ def get_entries(*args)
|
|
|
+ self.class.get_entries(*args)
|
|
|
+ end
|
|
|
+
|
|
|
+ # Split a line and get the last part
|
|
|
+ def self.last_of_split(line, by = ' ')
|
|
|
+ line.split(by, 2).last
|
|
|
+ end
|
|
|
+
|
|
|
+ def last_of_split(*args)
|
|
|
+ self.class.last_of_split(*args)
|
|
|
+ end
|
|
|
end
|