paddle v0.1.1 Paddle.Parsing

Module used to parse dn and other LDAP related stuffs.

Summary

Functions

Get a binary map representation of several eldap entries

Get a binary map representation of a single eldap entry

Construct a DN Erlang string based on a keyword list or a string

Tranform an LDAP DN to a keyword list

Escape special LDAP characters in a string

Wrap things in lists and convert binaries / atoms to charlists

Convert a user-friendly modify operation to an eldap operation

Functions

clean_entries(entries)
clean_entries([Paddle.eldap_entry]) :: [Paddle.ldap_entry]

Get a binary map representation of several eldap entries.

Example:

iex> Paddle.Parsing.clean_entries([{:eldap_entry, 'uid=testuser,ou=People', [{'uid', ['testuser']}]}])
[%{"dn" => "uid=testuser,ou=People", "uid" => ["testuser"]}]
clean_entry(arg)

Get a binary map representation of a single eldap entry.

Example:

iex> Paddle.Parsing.clean_entry({:eldap_entry, 'uid=testuser,ou=People', [{'uid', ['testuser']}]})
%{"dn" => "uid=testuser,ou=People", "uid" => ["testuser"]}
construct_dn(map, base \\ [])
construct_dn(keyword | [{binary, binary}], binary | charlist) :: charlist

Construct a DN Erlang string based on a keyword list or a string.

Examples:

iex> Paddle.Parsing.construct_dn(uid: "user", ou: "People")
'uid=user,ou=People'

iex> Paddle.Parsing.construct_dn([{"uid", "user"}, {"ou", "People"}], "dc=organisation,dc=org")
'uid=user,ou=People,dc=organisation,dc=org'

iex> Paddle.Parsing.construct_dn("uid=user,ou=People", "dc=organisation,dc=org")
'uid=user,ou=People,dc=organisation,dc=org'

Values are escaped.

Note: using a map is highly discouraged because the key / values may be reordered and because they can be mistaken for a class object (see Paddle.Class).

dn_to_kwlist(dn)
dn_to_kwlist(charlist | binary) :: [{binary, binary}]

Tranform an LDAP DN to a keyword list.

Well, not exactly a keyword list but a list like this:

[{"uid", "user"}, {"ou", "People"}, {"dc", "organisation"}, {"dc", "org"}]

Example:

iex> Paddle.Parsing.dn_to_kwlist("uid=user,ou=People,dc=organisation,dc=org")
[{"uid", "user"}, {"ou", "People"}, {"dc", "organisation"}, {"dc", "org"}]
ldap_escape(token)
ldap_escape(charlist | binary) :: charlist

Escape special LDAP characters in a string.

Example:

iex> Paddle.Parsing.ldap_escape("a=b#c\\")
'a\\=b\\#c\\\\'
list_wrap(list)
list_wrap(term) :: [charlist]

Wrap things in lists and convert binaries / atoms to charlists.

iex> Paddle.Parsing.list_wrap "hello"
['hello']

iex> Paddle.Parsing.list_wrap :hello
['hello']

iex> Paddle.Parsing.list_wrap ["hello", "world"]
['hello', 'world']
mod_convert(operation)
mod_convert(Paddle.mod) :: tuple

Convert a user-friendly modify operation to an eldap operation.

Examples:

iex> Paddle.Parsing.mod_convert {:add, {"description", "This is a description"}}
{:ModifyRequest_changes_SEQOF, :add,
 {:PartialAttribute, 'description', ['This is a description']}}

iex> Paddle.Parsing.mod_convert {:delete, "description"}
{:ModifyRequest_changes_SEQOF, :delete,
 {:PartialAttribute, 'description', []}}

iex> Paddle.Parsing.mod_convert {:replace, {"description", "This is a description"}}
{:ModifyRequest_changes_SEQOF, :replace,
 {:PartialAttribute, 'description', ['This is a description']}}