Skip to content
Snippets Groups Projects
Commit a4369ece authored by Thomas Woerner's avatar Thomas Woerner
Browse files

ansible_freeipa_module.py: New gen add and intersection list functions

Two new functions have been added for member management in plugins:

gen_add_list(user_list, res_list)
    Generate the add list for addition of new members.

gen_intersection_list(user_list, res_list)
    Generate the intersection list for removal of existing members.

gen_add_list should be used to add new members with action: members and
state: present. It is returning the difference of the user and res list
if the user list is not None.

gen_intersection_list should be used to remove existing members with
action: members and state: absent. It is returning the intersection of
the user and res list if the user list is not None.
parent ef5708ef
No related branches found
No related tags found
No related merge requests found
...@@ -377,8 +377,17 @@ else: ...@@ -377,8 +377,17 @@ else:
return api.env.realm return api.env.realm
def gen_add_del_lists(user_list, res_list): def gen_add_del_lists(user_list, res_list):
"""Generate the lists for the addition and removal of members.""" """
# The user list is None, therefore the parameter should not be touched Generate the lists for the addition and removal of members.
This function should be used to apply a new user list as a set
operation without action: members.
For the addition of new and the removal of existing members with
action: members gen_add_list and gen_intersection_list should
be used.
"""
# The user list is None, no need to do anything, return empty lists
if user_list is None: if user_list is None:
return [], [] return [], []
...@@ -387,6 +396,38 @@ else: ...@@ -387,6 +396,38 @@ else:
return add_list, del_list return add_list, del_list
def gen_add_list(user_list, res_list):
"""
Generate add list for addition of new members.
This function should be used to add new members with action: members
and state: present.
It is returning the difference of the user and res list if the user
list is not None.
"""
# The user list is None, no need to do anything, return empty list
if user_list is None:
return []
return list(set(user_list or []) - set(res_list or []))
def gen_intersection_list(user_list, res_list):
"""
Generate the intersection list for removal of existing members.
This function should be used to remove existing members with
action: members and state: absent.
It is returning the intersection of the user and res list if the
user list is not None.
"""
# The user list is None, no need to do anything, return empty list
if user_list is None:
return []
return list(set(res_list or []).intersection(set(user_list or [])))
def encode_certificate(cert): def encode_certificate(cert):
""" """
Encode a certificate using base64. Encode a certificate using base64.
......
0% Loading or .
You are about to add 0 people to the discussion. Proceed with caution.
Please register or to comment