Skip to content
Snippets Groups Projects
Commit e781343f authored by Eesaan Atluri's avatar Eesaan Atluri
Browse files

Improved logging, comments.

parent be0e2644
No related branches found
No related tags found
No related merge requests found
...@@ -17,7 +17,6 @@ logger = rc_util.get_logger(args) ...@@ -17,7 +17,6 @@ logger = rc_util.get_logger(args)
# Instantiate rabbitmq object # Instantiate rabbitmq object
rc_rmq = RCRMQ({"exchange": rcfg.Exchange, "exchange_type": "topic"}) rc_rmq = RCRMQ({"exchange": rcfg.Exchange, "exchange_type": "topic"})
print("ssh_agent entered")
def ssh_access(ch, method, properties, body): def ssh_access(ch, method, properties, body):
msg = json.loads(body) msg = json.loads(body)
...@@ -32,10 +31,9 @@ def ssh_access(ch, method, properties, body): ...@@ -32,10 +31,9 @@ def ssh_access(ch, method, properties, body):
try: try:
# check if it's a response from group_member_agent # check if it's a response from group_member_agent
if routing_key == task: if routing_key == task:
print("routing_key matches") logger.debug(f"corr_id sent by group_member agent: {properties.correlation_id}")
print(f"corr_id sent by group_member agent: {properties.correlation_id}")
if corr_id == properties.correlation_id: if corr_id == properties.correlation_id:
print(f'group_member agent confirmation msg["success"]: {msg["success"]}') logger.debug(f'group_member agent confirmation msg["success"]: {msg["success"]}')
# forward confirmation response to acct_mgmt_workflow agent # forward confirmation response to acct_mgmt_workflow agent
rc_rmq.publish_msg( rc_rmq.publish_msg(
{ {
...@@ -47,7 +45,7 @@ def ssh_access(ch, method, properties, body): ...@@ -47,7 +45,7 @@ def ssh_access(ch, method, properties, body):
else: else:
corr_id = str(uuid.uuid4()) corr_id = str(uuid.uuid4())
print(f'corr_id generated: {corr_id}') logger.debug(f'corr_id generated: {corr_id}')
msg["groups"] = {} msg["groups"] = {}
proc = Popen(['/usr/bin/groups', username], stdout=PIPE, stderr=PIPE) proc = Popen(['/usr/bin/groups', username], stdout=PIPE, stderr=PIPE)
...@@ -65,28 +63,24 @@ def ssh_access(ch, method, properties, body): ...@@ -65,28 +63,24 @@ def ssh_access(ch, method, properties, body):
# 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 lock_groups they are already part of.
# eg: {"groups": { "add":[a,b,c], "remove":[d,e,f] }
if state == 'certification': if state == 'certification':
# eg: {"groups": { "add":[a,b,c], "remove":[d,e,f] }
msg["groups"]["add"] = [lock_groups[state]] msg["groups"]["add"] = [lock_groups[state]]
msg["groups"]["remove"] = spl_groups msg["groups"]["remove"] = spl_groups
elif state == 'hold': elif state == 'hold':
# eg: {"groups": { "add":[a,b,c], "remove":[d,e,f] }
msg["groups"]["add"] = [lock_groups[state]] msg["groups"]["add"] = [lock_groups[state]]
msg["groups"]["remove"] = spl_groups msg["groups"]["remove"] = spl_groups
elif state == 'pre_certification': elif state == 'pre_certification':
# eg: {"groups": { "add":[a,b,c], "remove":[d,e,f] }
msg["groups"]["add"] = [lock_groups[state]] msg["groups"]["add"] = [lock_groups[state]]
msg["groups"]["remove"] = spl_groups msg["groups"]["remove"] = spl_groups
elif state == 'ok': elif state == 'ok':
msg["groups"]["remove"] = spl_groups msg["groups"]["remove"] = spl_groups
# send a message to group_member.py agent # send a message to group_member.py agent
logger.info(f"Request sent to add/remove user {username} to spl groups") logger.debug(f"sending msg to group agent: {msg}")
print(f"sending msg to group agent {msg}")
rc_rmq.publish_msg( rc_rmq.publish_msg(
{ {
"routing_key": f'group_member.{queuename}', "routing_key": f'group_member.{queuename}',
...@@ -97,6 +91,7 @@ def ssh_access(ch, method, properties, body): ...@@ -97,6 +91,7 @@ def ssh_access(ch, method, properties, body):
"msg": msg "msg": msg
} }
) )
logger.info(f"Request sent to add/remove user {username} to/from spl groups")
except Exception: except Exception:
msg["success"] = False msg["success"] = False
......
0% Loading or .
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment