diff --git a/delivery2/client/bin/rep_list_roles b/delivery2/client/bin/rep_list_roles index 8c68ec6..f47ef09 100755 --- a/delivery2/client/bin/rep_list_roles +++ b/delivery2/client/bin/rep_list_roles @@ -31,13 +31,10 @@ def listRoles(args): args = parser.parse_args() #Check number of arguments - if not args.session or not args.role: - logger.error("Need session file and username.") + if not args.session: + logger.error("Need session file.") sys.exit(1) - #Validate role name - #TODO - # Check for session file if not os.path.isfile(BASE_DIR + args.session): logger.error("File '" + args.session + "' not found.") @@ -47,7 +44,6 @@ def listRoles(args): with open(BASE_DIR + args.session, 'r') as f: args.session = json.load(f) - # TODO: try: req = requests.get(f'http://{state['REP_ADDRESS']}/role/session/list', headers={'Authorization': args.session['token']}) req.raise_for_status() @@ -55,5 +51,18 @@ def listRoles(args): logger.error("Failed to obtain response from server.") sys.exit(-1) + roles = req.json() + + if not args.role: + for r in roles.items(): + sys.stdout.write(r) + sys.exit(0) + elif args.role not in roles.items(): + logger.error("Role %s does not exist.", args.role) + sys.exit(1) + else: + logger.info("Role %s exists.", args.role) + sys.exit(0) + if __name__ == '__main__': listRoles(sys.argv[1:]) \ No newline at end of file diff --git a/delivery2/client/bin/rep_list_subject_roles b/delivery2/client/bin/rep_list_subject_roles index e93422b..53d72eb 100755 --- a/delivery2/client/bin/rep_list_subject_roles +++ b/delivery2/client/bin/rep_list_subject_roles @@ -69,5 +69,11 @@ def listSubjectRoles(args): logger.error("Failed to obtain response from server.") sys.exit(-1) + roles = req.json() + for r in roles.items(): + sys.stdout.write(r) + + sys.exit(0) + if __name__ == '__main__': listSubjectRoles(sys.argv[1:]) \ No newline at end of file diff --git a/delivery2/client/bin/rep_reactivate_role b/delivery2/client/bin/rep_reactivate_role index ba61ddb..71b52f2 100755 --- a/delivery2/client/bin/rep_reactivate_role +++ b/delivery2/client/bin/rep_reactivate_role @@ -5,6 +5,7 @@ import logging import requests import json import argparse +import subprocess from subject import main @@ -36,7 +37,11 @@ def reactivateRole(args): sys.exit(1) #Validate role name - #TODO + process = subprocess.Popen(f"./rep_list_roles {args.role}", shell=True) + process.wait() + if process.returncode != 0: + logger.error("Role does not exist.") + sys.exit(1) # Check for session file if not os.path.isfile(BASE_DIR + args.session): @@ -47,7 +52,6 @@ def reactivateRole(args): with open(BASE_DIR + args.session, 'r') as f: args.session = json.load(f) - # TODO: try: req = requests.post(f'http://{state['REP_ADDRESS']}/role/' + args.role + '/activate', headers={'Authorization': args.session['token']}) req.raise_for_status() @@ -55,5 +59,8 @@ def reactivateRole(args): logger.error("Failed to obtain response from server.") sys.exit(-1) + logger.info("Role %s has been reactivated.", args.role) + sys.exit(0) + if __name__ == '__main__': reactivateRole(sys.argv[1:]) \ No newline at end of file diff --git a/delivery2/client/bin/rep_suspend_role b/delivery2/client/bin/rep_suspend_role index c730220..d9f2fdd 100755 --- a/delivery2/client/bin/rep_suspend_role +++ b/delivery2/client/bin/rep_suspend_role @@ -5,6 +5,7 @@ import logging import requests import json import argparse +import subprocess from subject import main @@ -35,9 +36,6 @@ def suspendRole(args): logger.error("Need session file and role.") sys.exit(1) - #Validate role name - #TODO - # Check for session file if not os.path.isfile(BASE_DIR + args.session): logger.error("File '" + args.session + "' not found.") @@ -47,7 +45,13 @@ def suspendRole(args): with open(BASE_DIR + args.session, 'r') as f: args.session = json.load(f) - # TODO: + #Validate role name + process = subprocess.Popen(f"./rep_list_roles {args.role}", shell=True) + process.wait() + if process.returncode != 0: + logger.error("Role does not exist.") + sys.exit(1) + try: req = requests.post(f'http://{state['REP_ADDRESS']}/role/' + args.role + '/suspend', headers={'Authorization': args.session['token']}) req.raise_for_status() @@ -55,5 +59,8 @@ def suspendRole(args): logger.error("Failed to obtain response from server.") sys.exit(-1) + logger.info("Role %s has been suspended.", args.role) + sys.exit(0) + if __name__ == '__main__': suspendRole(sys.argv[1:]) \ No newline at end of file