diff --git a/delivery2/client/bin/rep_add_role b/delivery2/client/bin/rep_add_role index 75d5601..b12f604 100644 --- a/delivery2/client/bin/rep_add_role +++ b/delivery2/client/bin/rep_add_role @@ -34,9 +34,6 @@ def addRole(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,6 @@ def addRole(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/create/', json=json.dumps({'role' : args.role}), @@ -57,5 +53,8 @@ def addRole(args): logger.error("Failed to obtain response from server.") sys.exit(-1) + logger.info("Role added.") + sys.exit(0) + if __name__ == '__main__': addRole(sys.argv[1:]) \ No newline at end of file diff --git a/delivery2/client/bin/rep_add_subject b/delivery2/client/bin/rep_add_subject index 0ff3c2c..9cc4b75 100755 --- a/delivery2/client/bin/rep_add_subject +++ b/delivery2/client/bin/rep_add_subject @@ -63,6 +63,7 @@ def addSubject(args): logger.error("Failed to obtain response from server.") sys.exit(-1) + logger.info('Subject added.') sys.exit(0) if __name__ == '__main__': diff --git a/delivery2/client/bin/rep_assume_role b/delivery2/client/bin/rep_assume_role index d5b1f61..8b547c2 100644 --- a/delivery2/client/bin/rep_assume_role +++ b/delivery2/client/bin/rep_assume_role @@ -34,9 +34,6 @@ def assumeRole(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.") @@ -46,6 +43,21 @@ def assumeRole(args): with open(BASE_DIR + args.session, 'r') as f: args.session = json.load(f) + # 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) + + # TODO: try: req = requests.post(f'http://{state['REP_ADDRESS']}/role/session/assume/' + args.role, headers={'Authorization': args.session['token']}) @@ -54,5 +66,8 @@ def assumeRole(args): logger.error("Failed to obtain response from server.") sys.exit(-1) + logger.info("You assumed the role %s.", args.role) + sys.exit(0) + if __name__ == '__main__': assumeRole(sys.argv[1:]) \ No newline at end of file