Skip to content
Snippets Groups Projects

Refactor ssh access agent

1 file
+ 11
11
Compare changes
  • Side-by-side
  • Inline
@@ -51,33 +51,33 @@ def ssh_access(ch, method, properties, body):
@@ -51,33 +51,33 @@ def ssh_access(ch, method, properties, body):
proc = Popen(['/usr/bin/groups', username], stdout=PIPE, stderr=PIPE)
proc = Popen(['/usr/bin/groups', username], stdout=PIPE, stderr=PIPE)
out,err = proc.communicate()
out,err = proc.communicate()
user_group_list = out.decode().strip().split(":")[1].split()
user_groups = out.decode().strip().split(":")[1].split()
lock_groups = rcfg.lock_groups
state_groups = rcfg.state_groups
"""
"""
Filter the lock group a user is in and assign to spl
Filter the lock group a user is in and assign to spl
lambda function returns common elements between two lists. For all
lambda function returns common elements between two lists. For all
the true values by returned lambda function for common elements
the true values by returned lambda function for common elements
corresponding values are included as a list by filter function.
corresponding values are included as a list by filter function.
"""
"""
spl_groups = list(filter(lambda x:x in list(lock_groups.values()),user_group_list))
user_state_groups = list(filter(lambda x:x in list(rcfg.state_groups.values()),user_groups))
# Depending on state add user to the group corresponding to state.
# Depending on state add user to the group corresponding to state.
# Remove user from lock_groups they are already part of.
# Remove user from user_state_groups they are already part of.
# eg: {"groups": { "add":[a,b,c], "remove":[d,e,f] }
# eg: {"groups": { "add":[a,b,c], "remove":[d,e,f] }
if state == 'certification':
if state == 'certification':
msg["groups"]["add"] = [lock_groups[state]]
msg["groups"]["add"] = [state_groups[state]]
msg["groups"]["remove"] = spl_groups
msg["groups"]["remove"] = user_state_groups
elif state == 'hold':
elif state == 'hold':
msg["groups"]["add"] = [lock_groups[state]]
msg["groups"]["add"] = [state_groups[state]]
msg["groups"]["remove"] = spl_groups
msg["groups"]["remove"] = user_state_groups
elif state == 'pre_certification':
elif state == 'pre_certification':
msg["groups"]["add"] = [lock_groups[state]]
msg["groups"]["add"] = [state_groups[state]]
msg["groups"]["remove"] = spl_groups
msg["groups"]["remove"] = user_state_groups
elif state == 'ok':
elif state == 'ok':
msg["groups"]["remove"] = spl_groups
msg["groups"]["remove"] = user_state_groups
# send a message to group_member.py agent
# send a message to group_member.py agent
logger.debug(f"sending msg to group agent: {msg}")
logger.debug(f"sending msg to group agent: {msg}")
Loading