def process_desired_state(server_state, desired_state):
"""
Processes the user provided input file and determines any actions that need to happen because the server state is different than the desired state
:param server_state: The list of all users and their associated groups in the server
:param desired_state: The input provided by the user
:return: None
"""
group_id =[]
with open(desired_state) as csvDataFile:
csvReader = csv.reader(csvDataFile)
next(csvReader, None)
for email, lastname, firstname, groups in csvReader:
group_list = []
if groups != "":
group_list = groups.split(",")
group_list = [group.strip(' ') for group in group_list]
if email not in [user for user in server_state]:
actions[email] = {'action': 'add', 'groups': group_list, 'user_id':'', 'user_data': {'firstname': firstname, 'lastname': lastname, 'email': email, 'reset_password_required': True} }
else:
group_names_server = server_state[email]['groups'][0::2]
group_names_desired = groups.split(',')
group_names_desired = [group.strip(' ') for group in group_names_desired]
group_diff = [i for i in group_names_desired if i not in group_names_server]
if group_diff != [] and group_diff != ['']:
actions[email] = {'action': 'add to group', 'groups': group_diff, 'user_id': server_state[email]['user_id'] }
sync_users.py 文件源码
python
阅读 21
收藏 0
点赞 0
评论 0
评论列表
文章目录