paddle v0.1.4 Paddle.Parsing View Source

Module composed of utility functions for translating between :eldap and Paddle representation.

Link to this section Summary

Functions

Convert an :eldap search result to a Paddle representation

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

Convert a Paddle entry to a given Paddle class object

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

Link to this section Types

Link to this type eldap_dn() View Source
eldap_dn() :: charlist()
Link to this type eldap_entry() View Source
eldap_entry() :: {:eldap_entry, eldap_dn(), [{charlist(), [charlist()]}]}

Link to this section Functions

Link to this function clean_eldap_search_results(arg, base) View Source
clean_eldap_search_results(
  {:ok, {:eldap_search_result, [eldap_entry()]}} | {:error, atom()},
  charlist()
) :: {:ok, [Paddle.ldap_entry()]} | {:error, Paddle.search_ldap_error()}

Convert an :eldap search result to a Paddle representation.

Also see clean_entries/1

Examples:

iex> eldap_entry = {:eldap_entry, 'uid=testuser,ou=People', [{'uid', ['testuser']}]}
iex> Paddle.Parsing.clean_eldap_search_results({:ok, {:eldap_search_result, [eldap_entry], []}}, '')
{:ok, [%{"dn" => "uid=testuser,ou=People", "uid" => ["testuser"]}]}

iex> Paddle.Parsing.clean_eldap_search_results({:ok, {:eldap_search_result, [], []}}, '')
{:error, :noSuchObject}

iex> Paddle.Parsing.clean_eldap_search_results({:error, :insufficientAccessRights}, '')
{:error, :insufficientAccessRights}

iex> eldap_entry = {:eldap_entry, 'uid=testuser,ou=People', [{'uid', ['testuser']}]}
iex> Paddle.Parsing.clean_eldap_search_results({:ok, {:eldap_search_result, [eldap_entry], []}}, 'ou=People')
{:ok, [%{"dn" => "uid=testuser", "uid" => ["testuser"]}]}
Link to this function clean_entries(entries, base) View Source
clean_entries([eldap_entry()], charlist()) :: [Paddle.ldap_entry()]

Get a binary map representation of several eldap entries.

The base argument corresponds to the DN base which should be stripped from the result’s "dn" attribute.

Example:

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

iex> Paddle.Parsing.clean_entries([{:eldap_entry, 'uid=testuser,ou=People', [{'uid', ['testuser']}]}], 'ou=People')
[%{"dn" => "uid=testuser", "uid" => ["testuser"]}]
Link to this function clean_entry(arg, base_length) View Source
clean_entry(eldap_entry(), integer()) :: Paddle.ldap_entry()

Get a binary map representation of a single eldap entry.

The base_length argument corresponds to the DN base length which should be stripped from the result’s "dn" attribute.

Example:

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

iex> Paddle.Parsing.clean_entry({:eldap_entry, 'uid=testuser,ou=People', [{'uid', ['testuser']}]}, 9)
%{"dn" => "uid=testuser", "uid" => ["testuser"]}
Link to this function construct_dn(subdn, base) View Source
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).

Link to this function dn_to_kwlist(dn) View Source
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"}]
Link to this function entry_to_class_object(entry, target) View Source
entry_to_class_object(Paddle.ldap_entry(), Paddle.Class.t()) :: Paddle.Class.t()

Convert a Paddle entry to a given Paddle class object.

Example:

iex> entry = %{"dn" => "uid=testuser,ou=People", "uid" => ["testuser"], "description" => ["hello"]}
iex> Paddle.Parsing.entry_to_class_object(entry, %MyApp.PosixAccount{})
%MyApp.PosixAccount{cn: nil, description: ["hello"], gecos: nil,
  gidNumber: nil, homeDirectory: nil, host: nil, l: nil,
  loginShell: nil, o: nil, ou: nil, seeAlso: nil, uid: ["testuser"],
  uidNumber: nil, userPassword: nil}
Link to this function ldap_escape(token) View Source
ldap_escape(charlist() | binary()) :: charlist()

Escape special LDAP characters in a string.

Example:

iex> Paddle.Parsing.ldap_escape("a=b#c\\")
'a\\=b\\#c\\\\'
Link to this function list_wrap(list) View Source
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']
Link to this function mod_convert(operation) View Source
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']}}