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

Modify to accept state as arg and send msg based on state.

parent 377a8315
No related branches found
No related tags found
2 merge requests!147Merge previous default branch feat-cod-rmq into main,!119Feat account management
...@@ -4,11 +4,11 @@ import rc_util ...@@ -4,11 +4,11 @@ import rc_util
import argparse import argparse
import signal import signal
import uuid import uuid
import import rc_util
parser = argparse.ArgumentParser(description = "Account management driver script") parser = argparse.ArgumentParser(description = "Account management driver script")
parser.add_argument("username", help="Username that should be locked/unlocked") parser.add_argument("username", help="Username that should be locked/unlocked")
parser.add_argument("action", help="Choose lock or unlock action to be taken") parser.add_argument("state", help="Choose from states (ok,block,certify) to put the user in")
parser.add_argument("service", nargs='*', help="List one or more services to be blocked") parser.add_argument("service", nargs='*', help="List one or more services to be blocked")
parser.add_argument( parser.add_argument(
"-a", "--all", help="Block all services") "-a", "--all", help="Block all services")
...@@ -22,7 +22,7 @@ args = parser.parse_args() ...@@ -22,7 +22,7 @@ args = parser.parse_args()
timeout = 60 timeout = 60
username = args.username username = args.username
action = args.action state = args.state
service = args.service service = args.service
corr_id = str(uuid.uuid4()) corr_id = str(uuid.uuid4())
...@@ -30,6 +30,13 @@ callback_queue = rc_rmq.bind_queue(exclusive=True) ...@@ -30,6 +30,13 @@ callback_queue = rc_rmq.bind_queue(exclusive=True)
msg = {} msg = {}
if state == 'block' or state == 'certify':
action = lock
elif state == 'ok':
action = unlock
else:
print("Invalid state provided. Check the help menu.")
if args.all is not None: if args.all is not None:
# send a broadcast message to all agents # send a broadcast message to all agents
rc_rmq.publish_msg( rc_rmq.publish_msg(
...@@ -40,26 +47,15 @@ if args.all is not None: ...@@ -40,26 +47,15 @@ if args.all is not None:
) )
else: else:
for each_service in service: for each_service in service:
if action == 'lock': rc_rmq.publish_msg(
rc_rmq.publish_msg( {
{ "routing_key": f"{service}.{username}",
"routing_key": f"{service}.{username}", "props": pika.BasicProperties(
"props": pika.BasicProperties( correlation_id=corr_id, reply_to=callback_queue
correlation_id=corr_id, reply_to=callback_queue ),
), "msg": {"username": username, "action": action, "service": service},
"msg": {"username": username, "action": action, "service": service}, }
} )
)
elif action == 'unlock':
rc_rmq.publish_msg(
{
"routing_key": f"{service}.{username}",
"props": pika.BasicProperties(
correlation_id=corr_id, reply_to=callback_queue
),
"msg": {"username": username, "action": action, "service": service},
}
)
def timeout_handler(signum, frame): def timeout_handler(signum, frame):
print("Process timeout, there's some issue with agents") print("Process timeout, there's some issue with agents")
......
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