diff --git a/delivery2/client/bin/rep_acl_doc b/delivery2/client/bin/rep_acl_doc index 8cd01b5..5942665 100755 --- a/delivery2/client/bin/rep_acl_doc +++ b/delivery2/client/bin/rep_acl_doc @@ -70,6 +70,9 @@ def aclDoc(args): json=json.dumps(payload), headers={'Authorization': args.session['token']}) req.raise_for_status() + except requests.exceptions.HTTPError: + logger.error("%d: %s", req.status_code, req.json()['error']) + sys.exit(-1) except requests.exceptions.RequestException as errex: logger.error("Failed to obtain response from server.") sys.exit(-1) diff --git a/delivery2/client/bin/rep_activate_subject b/delivery2/client/bin/rep_activate_subject index 69a8377..db80828 100755 --- a/delivery2/client/bin/rep_activate_subject +++ b/delivery2/client/bin/rep_activate_subject @@ -44,6 +44,11 @@ def activateSubject(args): try: req = requests.post(f'http://{state['REP_ADDRESS']}/user/' + args.username + '/activate', headers={'Authorization': args.session['token']}) req.raise_for_status() + + except requests.exceptions.HTTPError: + logger.error("%d: %s", req.status_code, req.json()['error']) + sys.exit(-1) + except requests.exceptions.RequestException as errex: logger.error("Failed to obtain response from server.") sys.exit(-1) diff --git a/delivery2/client/bin/rep_add_doc b/delivery2/client/bin/rep_add_doc index 1b20aa1..c3006f8 100755 --- a/delivery2/client/bin/rep_add_doc +++ b/delivery2/client/bin/rep_add_doc @@ -60,6 +60,10 @@ def addDoc(args): req = requests.post(f'http://{state['REP_ADDRESS']}/file/upload/metadata', json=json.dumps(doc), headers={'Authorization': args.session['token']}) req.raise_for_status() + + except requests.exceptions.HTTPError: + logger.error("%d: %s", req.status_code, req.json()['error']) + sys.exit(-1) except requests.exceptions.RequestException as errex: logger.error("Failed to obtain response from server.") @@ -74,6 +78,10 @@ def addDoc(args): headers={'Authorization': args.session['token'], 'File-Checksum' : digest.get_hash(content)}) req.raise_for_status() + except requests.exceptions.HTTPError: + logger.error("%d: %s", req.status_code, req.json()['error']) + sys.exit(-1) + except requests.exceptions.RequestException as errex: logger.error("Failed to obtain response from server.") os.remove(BASE_DIR + 'encryptedText') diff --git a/delivery2/client/bin/rep_add_permission b/delivery2/client/bin/rep_add_permission index d6f2812..7605b1d 100755 --- a/delivery2/client/bin/rep_add_permission +++ b/delivery2/client/bin/rep_add_permission @@ -66,6 +66,11 @@ def addPermission(args): req = requests.post(f'http://{state['REP_ADDRESS']}/role/' + args.role + '/perm/add/' + args.value, headers={'Authorization': args.session['token']}) req.raise_for_status() + + except requests.exceptions.HTTPError: + logger.error("%d: %s", req.status_code, req.json()['error']) + sys.exit(-1) + except requests.exceptions.RequestException as errex: logger.error("Failed to obtain response from server.") sys.exit(-1) @@ -77,6 +82,11 @@ def addPermission(args): req = requests.post(f'http://{state['REP_ADDRESS']}/role/' + args.role + '/user/add/' + args.value, headers={'Authorization': args.session['token']}) req.raise_for_status() + + except requests.exceptions.HTTPError: + logger.error("%d: %s", req.status_code, req.json()['error']) + sys.exit(-1) + except requests.exceptions.RequestException as errex: logger.error("Failed to obtain response from server.") sys.exit(-1) diff --git a/delivery2/client/bin/rep_add_role b/delivery2/client/bin/rep_add_role index a4e199f..2c5fe7a 100755 --- a/delivery2/client/bin/rep_add_role +++ b/delivery2/client/bin/rep_add_role @@ -49,11 +49,16 @@ def addRole(args): json=json.dumps({'role' : args.role}), headers={'Authorization': args.session['token']}) req.raise_for_status() + + except requests.exceptions.HTTPError: + logger.error("%d: %s", req.status_code, req.json()['error']) + sys.exit(-1) + except requests.exceptions.RequestException as errex: logger.error("Failed to obtain response from server.") sys.exit(-1) - logger.info("Role added.") + logger.info("Role %s added.", args.role) sys.exit(0) if __name__ == '__main__': diff --git a/delivery2/client/bin/rep_add_subject b/delivery2/client/bin/rep_add_subject index 74e6498..ea820c9 100755 --- a/delivery2/client/bin/rep_add_subject +++ b/delivery2/client/bin/rep_add_subject @@ -59,12 +59,16 @@ def addSubject(args): req = requests.post(f'http://{state['REP_ADDRESS']}/user/create', json=json.dumps(subject), headers={'Authorization': args.session['token']}) req.raise_for_status() + except requests.exceptions.HTTPError: + logger.error("%d: %s", req.status_code, req.json()['error']) + sys.exit(-1) + except requests.exceptions.RequestException as errex: logger.error("Failed to obtain response from server.") sys.exit(-1) if req.status_code == 201: - logger.info('Subject added.') + logger.info('Subject %s added.', args.username) sys.exit(0) logger.error('Failed to add subject.') sys.exit(-1) diff --git a/delivery2/client/bin/rep_assume_role b/delivery2/client/bin/rep_assume_role index bddaeee..3bdc6dc 100755 --- a/delivery2/client/bin/rep_assume_role +++ b/delivery2/client/bin/rep_assume_role @@ -46,6 +46,11 @@ def assumeRole(args): try: req = requests.post(f'http://{state['REP_ADDRESS']}/role/session/assume/' + args.role, headers={'Authorization': args.session['token']}) req.raise_for_status() + + except requests.exceptions.HTTPError: + logger.error("%d: %s", req.status_code, req.json()['error']) + sys.exit(-1) + except requests.exceptions.RequestException as errex: logger.error("Failed to obtain response from server.") sys.exit(-1) diff --git a/delivery2/client/bin/rep_create_org b/delivery2/client/bin/rep_create_org index d027c0f..0967381 100755 --- a/delivery2/client/bin/rep_create_org +++ b/delivery2/client/bin/rep_create_org @@ -61,6 +61,11 @@ def createOrganization(args): try: req = requests.post(f'http://{state['REP_ADDRESS']}/org/create', json=json.dumps(input)) req.raise_for_status() + + except requests.exceptions.HTTPError: + logger.error("%d: %s", req.status_code, req.json()['error']) + sys.exit(-1) + except requests.exceptions.RequestException as errex: logger.error("Failed to obtain response from server.") sys.exit(-1) diff --git a/delivery2/client/bin/rep_delete_doc b/delivery2/client/bin/rep_delete_doc index 9e7efa9..07ebb12 100755 --- a/delivery2/client/bin/rep_delete_doc +++ b/delivery2/client/bin/rep_delete_doc @@ -50,6 +50,10 @@ def delDoc(args): req = requests.post(f'http://{state['REP_ADDRESS']}/file/delete/' + doc_name, headers={'Authorization': args.session['token']}) req.raise_for_status() + except requests.exceptions.HTTPError: + logger.error("%d: %s", req.status_code, req.json()['error']) + sys.exit(-1) + except requests.exceptions.RequestException as errex: logger.error("Failed to obtain response from server.") sys.exit(-1) diff --git a/delivery2/client/bin/rep_drop_role b/delivery2/client/bin/rep_drop_role index de8298b..8141fc2 100755 --- a/delivery2/client/bin/rep_drop_role +++ b/delivery2/client/bin/rep_drop_role @@ -46,6 +46,11 @@ def dropRole(args): try: req = requests.post(f'http://{state['REP_ADDRESS']}/role/session/drop/' + args.role, headers={'Authorization': args.session['token']}) req.raise_for_status() + + except requests.exceptions.HTTPError: + logger.error("%d: %s", req.status_code, req.json()['error']) + sys.exit(-1) + except requests.exceptions.RequestException as errex: logger.error("Failed to obtain response from server.") sys.exit(-1) diff --git a/delivery2/client/bin/rep_get_doc_file b/delivery2/client/bin/rep_get_doc_file index ec2c3cd..7f659bc 100755 --- a/delivery2/client/bin/rep_get_doc_file +++ b/delivery2/client/bin/rep_get_doc_file @@ -54,6 +54,10 @@ def getDoc(args): metadata = requests.get(f'http://{state['REP_ADDRESS']}/file/get/' + doc_name + '/metadata', headers={'Authorization': args.session['token']}) metadata.raise_for_status() + except requests.exceptions.HTTPError: + logger.error("%d: %s", metadata.status_code, metadata.json()['error']) + sys.exit(-1) + except requests.exceptions.RequestException as errex: logger.error("Failed to obtain response from server.") sys.exit(1) @@ -65,6 +69,11 @@ def getDoc(args): try: file = requests.get(f'http://{state['REP_ADDRESS']}/file/get/' + metadata['file_handle'] + '/content') file.raise_for_status() + + except requests.exceptions.HTTPError: + logger.error("%d: %s", file.status_code, file.json()['error']) + sys.exit(-1) + except requests.exceptions.RequestException as errex: logger.error("Failed to obtain response from server.") sys.exit(-1) diff --git a/delivery2/client/bin/rep_get_doc_metadata b/delivery2/client/bin/rep_get_doc_metadata index 502b754..69676d1 100755 --- a/delivery2/client/bin/rep_get_doc_metadata +++ b/delivery2/client/bin/rep_get_doc_metadata @@ -50,6 +50,11 @@ def getDocMetadata(args): try: metadata = requests.get(f'http://{state['REP_ADDRESS']}/file/get/' + doc_name + '/metadata', headers={'Authorization': args.session['token']}) metadata.raise_for_status() + + except requests.exceptions.HTTPError: + logger.error("%d: %s", metadata.status_code, metadata.json()['error']) + sys.exit(-1) + except requests.exceptions.RequestException as errex: logger.error("Failed to obtain response from server.") sys.exit(-1) diff --git a/delivery2/client/bin/rep_get_file b/delivery2/client/bin/rep_get_file index 635a12b..96c533b 100755 --- a/delivery2/client/bin/rep_get_file +++ b/delivery2/client/bin/rep_get_file @@ -41,6 +41,11 @@ def getFile(args): try: file = requests.get(f'http://{state['REP_ADDRESS']}/file/get/' + args.filehandle + '/content') file.raise_for_status() + + except requests.exceptions.HTTPError: + logger.error("%d: %s", file.status_code, file.json()['error']) + sys.exit(-1) + except requests.exceptions.RequestException as errex: logger.error("Failed to obtain response from server.") sys.exit(-1) diff --git a/delivery2/client/bin/rep_list_docs b/delivery2/client/bin/rep_list_docs index 0d706c4..1ea4539 100755 --- a/delivery2/client/bin/rep_list_docs +++ b/delivery2/client/bin/rep_list_docs @@ -66,6 +66,10 @@ def list_docs(args): headers={'Authorization': args.session['token']}) subjects.raise_for_status() + except requests.exceptions.HTTPError: + logger.error("%d: %s", subjects.status_code, subjects.json()['error']) + sys.exit(-1) + except requests.exceptions.RequestException as errex: logger.error("Failed to obtain response from server.") sys.exit(-1) @@ -84,6 +88,11 @@ def list_docs(args): headers={'Authorization': args.session['token']}) subjects.raise_for_status() + except requests.exceptions.HTTPError: + logger.error("%d: %s", subjects.status_code, subjects + .json()['error']) + sys.exit(-1) + except requests.exceptions.RequestException as errex: logger.error("Failed to obtain response from server.") sys.exit(-1) @@ -102,6 +111,10 @@ def list_docs(args): headers={'Authorization': args.session['token']}) subjects.raise_for_status() + except requests.exceptions.HTTPError: + logger.error("%d: %s", subjects.status_code, subjects.json()['error']) + sys.exit(-1) + except requests.exceptions.RequestException as errex: logger.error("Failed to obtain response from server.") sys.exit(-1) @@ -113,6 +126,10 @@ def list_docs(args): subjects = requests.get(f'http://{state['REP_ADDRESS']}/file/list', json=json.dumps({}), headers={'Authorization': args.session['token']}) subjects.raise_for_status() + except requests.exceptions.HTTPError: + logger.error("%d: %s", subjects.status_code, subjects.json()['error']) + sys.exit(-1) + except requests.exceptions.RequestException as errex: logger.error("Failed to obtain response from server.") sys.exit(-1) diff --git a/delivery2/client/bin/rep_list_orgs b/delivery2/client/bin/rep_list_orgs index 364057d..b46eb3d 100755 --- a/delivery2/client/bin/rep_list_orgs +++ b/delivery2/client/bin/rep_list_orgs @@ -21,6 +21,10 @@ def listOrganizations(): orgs = requests.get(f'http://{state['REP_ADDRESS']}/org/list') orgs.raise_for_status() + except requests.exceptions.HTTPError: + logger.error("%d: %s", orgs.status_code, orgs.json()['error']) + sys.exit(-1) + except requests.exceptions.RequestException as errex: logger.error("Failed to obtain response from server.") sys.exit(-1) diff --git a/delivery2/client/bin/rep_list_permission_roles b/delivery2/client/bin/rep_list_permission_roles index b635f49..0b3e489 100755 --- a/delivery2/client/bin/rep_list_permission_roles +++ b/delivery2/client/bin/rep_list_permission_roles @@ -47,6 +47,11 @@ def listPermissionRoles(args): try: req = requests.get(f'http://{state['REP_ADDRESS']}/role/perm/' + args.permission + '/roles', headers={'Authorization': args.session['token']}) req.raise_for_status() + + except requests.exceptions.HTTPError: + logger.error("%d: %s", req.status_code, req.json()['error']) + sys.exit(-1) + except requests.exceptions.RequestException as errex: logger.error("Failed to obtain response from server.") sys.exit(-1) diff --git a/delivery2/client/bin/rep_list_role_permissions b/delivery2/client/bin/rep_list_role_permissions index 51fde64..c1ba190 100755 --- a/delivery2/client/bin/rep_list_role_permissions +++ b/delivery2/client/bin/rep_list_role_permissions @@ -47,6 +47,11 @@ def listRolePermissions(args): try: req = requests.get(f'http://{state['REP_ADDRESS']}/role/' + args.role + '/list/perms', headers={'Authorization': args.session['token']}) req.raise_for_status() + + except requests.exceptions.HTTPError: + logger.error("%d: %s", req.status_code, req.json()['error']) + sys.exit(-1) + except requests.exceptions.RequestException as errex: logger.error("Failed to obtain response from server.") sys.exit(-1) diff --git a/delivery2/client/bin/rep_list_role_subjects b/delivery2/client/bin/rep_list_role_subjects index ca5c633..79a5b8a 100755 --- a/delivery2/client/bin/rep_list_role_subjects +++ b/delivery2/client/bin/rep_list_role_subjects @@ -47,6 +47,11 @@ def listRoleSubjects(args): try: req = requests.get(f'http://{state['REP_ADDRESS']}/role/' + args.role + '/list/users', headers={'Authorization': args.session['token']}) req.raise_for_status() + + except requests.exceptions.HTTPError: + logger.error("%d: %s", req.status_code, req.json()['error']) + sys.exit(-1) + except requests.exceptions.RequestException as errex: logger.error("Failed to obtain response from server.") sys.exit(-1) diff --git a/delivery2/client/bin/rep_list_roles b/delivery2/client/bin/rep_list_roles index b03d1d2..b30b653 100755 --- a/delivery2/client/bin/rep_list_roles +++ b/delivery2/client/bin/rep_list_roles @@ -47,6 +47,11 @@ def listRoles(args): try: req = requests.get(f'http://{state['REP_ADDRESS']}/role/session/list', headers={'Authorization': args.session['token']}) req.raise_for_status() + + except requests.exceptions.HTTPError: + logger.error("%d: %s", req.status_code, req.json()['error']) + sys.exit(-1) + except requests.exceptions.RequestException as errex: logger.error("Failed to obtain response from server.") sys.exit(-1) diff --git a/delivery2/client/bin/rep_list_subject_roles b/delivery2/client/bin/rep_list_subject_roles index f0d86b9..8a26c84 100755 --- a/delivery2/client/bin/rep_list_subject_roles +++ b/delivery2/client/bin/rep_list_subject_roles @@ -47,6 +47,11 @@ def listSubjectRoles(args): try: req = requests.get(f'http://{state['REP_ADDRESS']}/user/' + args.username + '/roles', headers={'Authorization': args.session['token']}) req.raise_for_status() + + except requests.exceptions.HTTPError: + logger.error("%d: %s", req.status_code, req.json()['error']) + sys.exit(-1) + except requests.exceptions.RequestException as errex: logger.error("Failed to obtain response from server.") sys.exit(-1) diff --git a/delivery2/client/bin/rep_list_subjects b/delivery2/client/bin/rep_list_subjects index a89d650..0475ffa 100755 --- a/delivery2/client/bin/rep_list_subjects +++ b/delivery2/client/bin/rep_list_subjects @@ -50,6 +50,10 @@ def list_subjects(args): headers={'Authorization': args.session['token']}) subjects.raise_for_status() + except requests.exceptions.HTTPError: + logger.error("%d: %s", subjects.status_code, subjects.json()['error']) + sys.exit(-1) + except requests.exceptions.RequestException as errex: logger.error("Failed to obtain response from server.") sys.exit(-1) @@ -61,6 +65,10 @@ def list_subjects(args): headers={'Authorization': args.session['token']}) subjects.raise_for_status() + except requests.exceptions.HTTPError: + logger.error("%d: %s", subjects.status_code, subjects.json()['error']) + sys.exit(-1) + except requests.exceptions.RequestException as errex: logger.error("Failed to obtain response from server.") sys.exit(-1) diff --git a/delivery2/client/bin/rep_reactivate_role b/delivery2/client/bin/rep_reactivate_role index ac42803..4192c9a 100755 --- a/delivery2/client/bin/rep_reactivate_role +++ b/delivery2/client/bin/rep_reactivate_role @@ -48,6 +48,11 @@ def reactivateRole(args): try: req = requests.post(f'http://{state['REP_ADDRESS']}/role/' + args.role + '/activate', headers={'Authorization': args.session['token']}) req.raise_for_status() + + except requests.exceptions.HTTPError: + logger.error("%d: %s", req.status_code, req.json()['error']) + sys.exit(-1) + except requests.exceptions.RequestException as errex: logger.error("Failed to obtain response from server.") sys.exit(-1) diff --git a/delivery2/client/bin/rep_remove_permission b/delivery2/client/bin/rep_remove_permission index d828c6d..b7860c6 100755 --- a/delivery2/client/bin/rep_remove_permission +++ b/delivery2/client/bin/rep_remove_permission @@ -44,7 +44,7 @@ def removePermission(args): with open(BASE_DIR + args.session, 'r') as f: args.session = json.load(f) - isPerm = False; isUsername = False + isPerm = False # query for permission if args.value in [ @@ -65,26 +65,33 @@ def removePermission(args): req = requests.post(f'http://{state['REP_ADDRESS']}/role/' + args.role + '/perm/remove/' + args.value, headers={'Authorization': args.session['token']}) req.raise_for_status() + + except requests.exceptions.HTTPError: + logger.error("%d: %s", req.status_code, req.json()['error']) + sys.exit(-1) + except requests.exceptions.RequestException as errex: logger.error("Failed to obtain response from server.") sys.exit(-1) logger.info("Permission removed from role successfully.") sys.exit(0) - elif isUsername: + else: try: req = requests.post(f'http://{state['REP_ADDRESS']}/role/' + args.role + '/user/remove/' + args.value, headers={'Authorization': args.session['token']}) req.raise_for_status() + + except requests.exceptions.HTTPError: + logger.error("%d: %s", req.status_code, req.json()['error']) + sys.exit(-1) + except requests.exceptions.RequestException as errex: logger.error("Failed to obtain response from server.") sys.exit(-1) logger.info("Subject removed from role successfully.") sys.exit(0) - else: - logger.error("Invalid permission or username.") - sys.exit(1) if __name__ == '__main__': diff --git a/delivery2/client/bin/rep_suspend_role b/delivery2/client/bin/rep_suspend_role index 07fec61..0de5f07 100755 --- a/delivery2/client/bin/rep_suspend_role +++ b/delivery2/client/bin/rep_suspend_role @@ -48,6 +48,11 @@ def suspendRole(args): try: req = requests.post(f'http://{state['REP_ADDRESS']}/role/' + args.role + '/suspend', headers={'Authorization': args.session['token']}) req.raise_for_status() + + except requests.exceptions.HTTPError: + logger.error("%d: %s", req.status_code, req.json()['error']) + sys.exit(-1) + except requests.exceptions.RequestException as errex: logger.error("Failed to obtain response from server.") sys.exit(-1) diff --git a/delivery2/client/bin/rep_suspend_subject b/delivery2/client/bin/rep_suspend_subject index e550970..bd2464f 100755 --- a/delivery2/client/bin/rep_suspend_subject +++ b/delivery2/client/bin/rep_suspend_subject @@ -45,6 +45,11 @@ def suspendSubject(args): try: req = requests.post(f'http://{state['REP_ADDRESS']}/user/' + args.username + '/suspend', headers={'Authorization': args.session['token']}) req.raise_for_status() + + except requests.exceptions.HTTPError: + logger.error("%d: %s", req.status_code, req.json()['error']) + sys.exit(-1) + except requests.exceptions.RequestException as errex: logger.error("Failed to obtain response from server.") sys.exit(-1) diff --git a/delivery2/client/bin/reset_database b/delivery2/client/bin/reset_database index 45fda21..46175b3 100755 --- a/delivery2/client/bin/reset_database +++ b/delivery2/client/bin/reset_database @@ -34,6 +34,11 @@ def reset(args): try: req = requests.post(f'http://{state['REP_ADDRESS']}/reset',json=json.dumps({'password' : args.password})) req.raise_for_status() + + except requests.exceptions.HTTPError: + logger.error("%d: %s", req.status_code, req.json()['error']) + sys.exit(-1) + except requests.exceptions.RequestException as errex: logger.error("Failed to obtain response from server.") sys.exit(-1)