Footprintless::Plugin::Ldap::Ldap; - The ldap client implementation
version 1.00
Standard way of getting an ldap client:
use Footprintless; my $ldap = Footprintless->new()->ldap('proj.env'); # Export: $ldap->with_connection(sub { $ldap->export_ldif('/tmp/export.ldif') }); # Import: $ldap->with_connection(sub { $ldap->import_ldif('/tmp/export.ldif') }); # Search: eval { $ldap->connect()->bind(); my @foo_users = $ldap->search_for_list({filter => '(mail=*@foo.com)'}); # do other things... }; my $error = $@; eval {$ldap->disconnect()}; die($error) if ($error);
This module is a convenience wrapper around Net::LDAP
that integrates with Footprintless and provides a bunch of useful LDAP manipulation functions.
A simple LDAP entity:
ldap => { # An admin user with permission to manipulate entries bind_dn => 'uid=admin,ou=system', # Password for bind_dn # password can also be specified directly at the top level... bind_options => { password => 'secret' }, # Base dn to use for all operations when not explicitly specified # by the operation options default_base => 'dc=foo,dc=com' # The hostname of the server hostname => 'public-ldap.foo.com', # The port (default 389 if secure == 0, 636 otherwise) port => 389, # O for LDAP (default), 1 for LDAPS secure => 0, # Optional ssh tunnel configuration, uses Footprintless::Tunnel tunnel_destination_hostname => 'internal-ldap.foo.com', tunnel_hostname => 'bastion-gateway.foo.com', tunnel_username => 'automationuser', },
Adds $entry
.
Adds $entry
if it does not exist, updates it otherwise.
Returns a dn by combining all of the @rdns
.
Binds to $dn
. If %options
are provided, they will be used in place to the configured connection options.
Connects to the server (does not perfom a bind). The %connect_options
are passed through to the Net::LDAP or Net::LDAPS constructor.
Passes through to "canonical_dn" in Net::LDAP::Util.
If %options
are provided, the options filter
and scope
will be used together with $base
to search for, and then delete entries. Otherwise, $base
will be deleted.
Disconnects from the server.
Passes through to "ldap_explode_dn" in Net::LDAP::Util.
Exports the data to $to
, which must be one of:
A refrence to a scalar to hold the LDIF data.
The name of a file to write the LDIF data to.
The supported options are, base
, scope
, filter
, and attrs
. They are used to search for the entries to export.
Imports the data from $from
, which must be one of:
A reference to a file handle to read LDIF data from.
A refrence to a scalar to holding the LDIF data.
An LDIF filename.
The supported options are:
A sub that gets run on each entry instead of add_or_update.
Returns a truthy value if currently connected.
Modifies the entry at $dn
according to %options
. The %options
are specified by modify in Net::Ldap
Searches for all entries matching $search_args
and calls $each_entry_callback
for each result.
Returns an ARRAY
of dn
's of all the containers under $base
.
Searches for all entries matching $search_args
. If $entry_mapper
is supplied it will be called for each entry. Otherwise, the entry itself will be used. All results will be aggregated into an ARRAY
or ARRAYREF
(depending on wantarray
) and returned.
Searches for all entries matching $search_args
. If $entry_mapper
is supplied it will be called for each entry and will be expected to return a tuple (ARRAY
of length 2), representing a key value pair. Otherwise, the entry dn
and the entry itself will be used as the key value pair. All results will be aggregated into a HASHREF
and returned.
Searches for a single entry matching $search_args
. If $entry_mapper
is supplied, it will be called with the entry, and the value returned will be returned. Otherwise, the entry itself will be returned.
Prints out a string containing connection information useful for debugging.
Unbinds the connection to the server.
Updates $entry
on the server.
Opens a connection, binds, calls $sub
, and disconnects. If an error occurred the disconnect will be executed and the error will be re-died.
Lucas Theisen <lucastheisen@pastdev.com>
This software is copyright (c) 2017 by Lucas Theisen.
This is free software; you can redistribute it and/or modify it under the same terms as the Perl 5 programming language system itself.
Please see those modules/websites for more information related to this module.