diff --git a/delivery2/client/bin/rep_drop_role b/delivery2/client/bin/rep_drop_role index b099631..a4faad5 100644 --- a/delivery2/client/bin/rep_drop_role +++ b/delivery2/client/bin/rep_drop_role @@ -34,8 +34,6 @@ def dropRole(args): logger.error("Need session file and username.") 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.") @@ -45,7 +43,20 @@ def dropRole(args): with open(BASE_DIR + args.session, 'r') as f: args.session = json.load(f) - # TODO: + # Get roles in session + try: + req = requests.get(f'http://{state['REP_ADDRESS']}/role/session/list', headers={'Authorization': args.session['token']}) + req.raise_for_status() + except requests.exceptions.RequestException as errex: + logger.error("Failed to obtain response from server.") + sys.exit(-1) + + # Validate role name + roles = req.json() + if args.role not in roles.items(): + logger.error("Role does not exist.") + sys.exit(1) + try: req = requests.post(f'http://{state['REP_ADDRESS']}/role/session/drop/' + args.username + '/activate', headers={'Authorization': args.session['token']}) req.raise_for_status() @@ -53,5 +64,8 @@ def dropRole(args): logger.error("Failed to obtain response from server.") sys.exit(-1) + logger.info("You dropped the role %s", args.role) + sys.exit(0) + if __name__ == '__main__': dropRole(sys.argv[1:]) \ No newline at end of file diff --git a/delivery2/client/bin/rep_list_permission_roles b/delivery2/client/bin/rep_list_permission_roles index 3cf6404..c1827f8 100644 --- a/delivery2/client/bin/rep_list_permission_roles +++ b/delivery2/client/bin/rep_list_permission_roles @@ -35,9 +35,6 @@ def listPermissionRoles(args): logger.error("Need session file and permission.") sys.exit(1) - #Validate permission 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,11 @@ def listPermissionRoles(args): with open(BASE_DIR + args.session, 'r') as f: args.session = json.load(f) - # TODO: + #Validate permission name + if args.permission in ['ROLE_ACL', 'SUBJECT_NEW', 'SUBJECT_DOWN', 'SUBJECT_UP', 'DOC_NEW']: + logger.error("Permission does not exist.") + sys.exit(1) + try: req = requests.get(f'http://{state['REP_ADDRESS']}/role/perm/' + args.permission + '/roles', headers={'Authorization': args.session['token']}) req.raise_for_status() @@ -55,5 +56,11 @@ def listPermissionRoles(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__': listPermissionRoles(sys.argv[1:]) \ No newline at end of file diff --git a/delivery2/client/bin/rep_list_role_permissions b/delivery2/client/bin/rep_list_role_permissions index deb7554..96fd1be 100644 --- a/delivery2/client/bin/rep_list_role_permissions +++ b/delivery2/client/bin/rep_list_role_permissions @@ -44,7 +44,20 @@ def listRolePermissions(args): with open(BASE_DIR + args.session, 'r') as f: args.session = json.load(f) - # TODO: + # Get roles in session + try: + req = requests.get(f'http://{state['REP_ADDRESS']}/role/session/list', headers={'Authorization': args.session['token']}) + req.raise_for_status() + except requests.exceptions.RequestException as errex: + logger.error("Failed to obtain response from server.") + sys.exit(-1) + + # Validate role name + roles = req.json() + if args.role not in roles.items(): + logger.error("Role does not exist.") + sys.exit(1) + try: req = requests.get(f'http://{state['REP_ADDRESS']}/role/' + args.role + '/list/perms', headers={'Authorization': args.session['token']}) req.raise_for_status() @@ -52,5 +65,11 @@ def listRolePermissions(args): logger.error("Failed to obtain response from server.") sys.exit(-1) + perms = req.json() + for p in perms.items(): + sys.stdout.write(p) + + sys.exit(0) + if __name__ == '__main__': listRolePermissions(sys.argv[1:]) \ No newline at end of file diff --git a/delivery2/client/bin/rep_list_role_subjects b/delivery2/client/bin/rep_list_role_subjects index d4e994a..f89c056 100644 --- a/delivery2/client/bin/rep_list_role_subjects +++ b/delivery2/client/bin/rep_list_role_subjects @@ -34,9 +34,6 @@ def listRoleSubjects(args): if not args.session or not args.role: 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): @@ -47,7 +44,20 @@ def listRoleSubjects(args): with open(BASE_DIR + args.session, 'r') as f: args.session = json.load(f) - # TODO: + # Get roles in session + try: + req = requests.get(f'http://{state['REP_ADDRESS']}/role/session/list', headers={'Authorization': args.session['token']}) + req.raise_for_status() + except requests.exceptions.RequestException as errex: + logger.error("Failed to obtain response from server.") + sys.exit(-1) + + # Validate role name + roles = req.json() + if args.role not in roles.items(): + logger.error("Role does not exist.") + sys.exit(1) + try: req = requests.get(f'http://{state['REP_ADDRESS']}/role/' + args.role + '/list/users', headers={'Authorization': args.session['token']}) req.raise_for_status() @@ -55,5 +65,11 @@ def listRoleSubjects(args): logger.error("Failed to obtain response from server.") sys.exit(-1) + subjects = req.json() + for s in subjects.items(): + sys.stdout.write(s) + + sys.exit(0) + if __name__ == '__main__': listRoleSubjects(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 e1543c5..e93422b 100644 --- a/delivery2/client/bin/rep_list_subject_roles +++ b/delivery2/client/bin/rep_list_subject_roles @@ -44,7 +44,24 @@ def listSubjectRoles(args): with open(BASE_DIR + args.session, 'r') as f: args.session = json.load(f) - # TODO: + # Get list of subjects + try: + subjects = requests.get(f'http://{state['REP_ADDRESS']}/user/list', + json=json.dumps({}), + headers={'Authorization': args.session['token']}) + subjects.raise_for_status() + + except requests.exceptions.RequestException as errex: + logger.error("Failed to obtain response from server.") + sys.exit(-1) + + subjects = subjects.json() + + # Check if subject exists + if args.username not in subjects.items(): + logger.error("Subject not found.") + sys.exit(1) + try: req = requests.get(f'http://{state['REP_ADDRESS']}/user/' + args.username + '/roles', headers={'Authorization': args.session['token']}) req.raise_for_status()