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
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 section Functions
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"]}]}
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"]}]
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"]}
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
).
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"}]
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}
Escape special LDAP characters in a string.
Example:
iex> Paddle.Parsing.ldap_escape("a=b#c\\")
'a\\=b\\#c\\\\'
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']
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']}}