From 88808df92102942bcd045a9fbce8f6099692d3f7 Mon Sep 17 00:00:00 2001 From: JoaoBastos023 Date: Tue, 19 Nov 2024 19:06:54 +0000 Subject: [PATCH] Changed dict keys to match APIs --- delivery1/client/bin/rep_activate_subject | 4 ++-- delivery1/client/bin/rep_add_doc | 10 ++++++---- delivery1/client/bin/rep_add_subject | 4 ++-- delivery1/client/bin/rep_create_org | 2 +- delivery1/client/bin/rep_create_session | 4 ++-- delivery1/client/bin/rep_decrypt_file | 5 +---- delivery1/client/bin/rep_delete_doc | 4 ++-- delivery1/client/bin/rep_get_doc_file | 4 ++-- delivery1/client/bin/rep_get_doc_metadata | 4 ++-- delivery1/client/bin/rep_get_file | 2 +- delivery1/client/bin/rep_list_docs | 20 +++++++++++++------- delivery1/client/bin/rep_list_orgs | 2 +- delivery1/client/bin/rep_list_subjects | 6 ++++-- delivery1/client/bin/rep_subject_credentials | 5 +++++ delivery1/client/bin/rep_suspend_subject | 4 ++-- 15 files changed, 46 insertions(+), 34 deletions(-) diff --git a/delivery1/client/bin/rep_activate_subject b/delivery1/client/bin/rep_activate_subject index d114190..20fcb7a 100755 --- a/delivery1/client/bin/rep_activate_subject +++ b/delivery1/client/bin/rep_activate_subject @@ -36,9 +36,9 @@ def activateSubject(args): logger.error("File '" + args.session + "' not found.") sys.exit(-1) - subject = {'username' : args[1], 'status' : 'activate'} + subject = {'session_file' : args.session, 'username' : args.username} try: - req = requests.post(f'http://{state['REP_ADDRESS']}/subject/', json=json.dumps(subject)) + req = requests.post(f'http://{state['REP_ADDRESS']}/user/activate', json=json.dumps(subject)) req.raise_for_status() except requests.exceptions.RequestException as errex: logger.error("Failed to obtain response from server.") diff --git a/delivery1/client/bin/rep_add_doc b/delivery1/client/bin/rep_add_doc index 730fd95..8ecf0a6 100755 --- a/delivery1/client/bin/rep_add_doc +++ b/delivery1/client/bin/rep_add_doc @@ -43,17 +43,19 @@ def addDoc(args): logger.error("File '" + args.file + "' not found") sys.exit(-1) - + # Get pub key + pubkey = encryption_functs.load_public_key(state['PUB_KEY']) + #encrypt content with open(args.file, 'rb') as f: content = f.read() - content = encryption_functs.encrypt_file(state['REP_PUB_KEY'], content) + content = encryption_functs.encrypt_file(pubkey, content) - doc = {'name' : args.name, 'content' : content} + doc = {'session_file' : args.session, 'document_name' : args.name, 'content' : content} try: - req = requests.post(f'http://{state['REP_ADDRESS']}/document/delete', json=json.dumps(doc)) + req = requests.post(f'http://{state['REP_ADDRESS']}/file/upload', json=json.dumps(doc)) req.raise_for_status() except requests.exceptions.RequestException as errex: diff --git a/delivery1/client/bin/rep_add_subject b/delivery1/client/bin/rep_add_subject index cb47a7c..82ab8f1 100755 --- a/delivery1/client/bin/rep_add_subject +++ b/delivery1/client/bin/rep_add_subject @@ -45,10 +45,10 @@ def addSubject(args): logger.error("File '" + args.file + "' not found") sys.exit(-1) - subject = {'username' : args.username, 'name' : args.name, 'email' : args.email, 'credentials' : args.credentials} + subject = {'session_file' : args.session, 'username' : args.username, 'name' : args.name, 'email' : args.email, 'credentials_file' : args.credentials} try: - req = requests.post(f'http://{state['REP_ADDRESS']}/subject/add', json=json.dumps(subject)) + req = requests.post(f'http://{state['REP_ADDRESS']}/user/create', json=json.dumps(subject)) req.raise_for_status() except requests.exceptions.RequestException as errex: diff --git a/delivery1/client/bin/rep_create_org b/delivery1/client/bin/rep_create_org index e1d723c..35d6ffd 100755 --- a/delivery1/client/bin/rep_create_org +++ b/delivery1/client/bin/rep_create_org @@ -59,7 +59,7 @@ def createOrganization(args): input = {'name' : args.org, 'username' : args.username, 'full_name' : args.name, 'email' : args.email, 'public_key' : pubKey} try: - req = requests.post(f'http://{state['REP_ADDRESS']}/organization/create', json=json.dumps(input)) + req = requests.post(f'http://{state['REP_ADDRESS']}/org/create', json=json.dumps(input)) req.raise_for_status() except requests.exceptions.RequestException as errex: logger.error("Failed to obtain response from server.") diff --git a/delivery1/client/bin/rep_create_session b/delivery1/client/bin/rep_create_session index 78e9a61..7e4ef0b 100755 --- a/delivery1/client/bin/rep_create_session +++ b/delivery1/client/bin/rep_create_session @@ -43,10 +43,10 @@ def createSession(args): logger.error("File '" + args.credentials + "' not found.") sys.exit(-1) - session = {'organization' : args.org, 'username' : args.username, 'password' : args.password, 'credentials' : args.credentials} + session = {'org' : args.org, 'username' : args.username, 'password' : args.password, 'credentials_file' : args.credentials} try: - req = requests.post(f'http://{state['REP_ADDRESS']}/session/create', json=json.dumps(session)) + req = requests.post(f'http://{state['REP_ADDRESS']}/user/login', json=json.dumps(session)) req.raise_for_status() except requests.exceptions.RequestException as errex: logger.error("Failed to obtain response from server") diff --git a/delivery1/client/bin/rep_decrypt_file b/delivery1/client/bin/rep_decrypt_file index c1b493e..6df535e 100755 --- a/delivery1/client/bin/rep_decrypt_file +++ b/delivery1/client/bin/rep_decrypt_file @@ -34,14 +34,11 @@ def decryptFile(args): logger.error("File '" + args.metadata + "' not found.") sys.exit(-1) - #Get private key to decrypt - privateKey = decryption_functs.load_private_key(args.metadata) - #Decrypt file with open(args.encrypted, 'rb') as f: content = f.read() - content = decryption_functs.decrypt_file(privateKey, content) + content = decryption_functs.decrypt_file('privateKey', content) # Send decrypted content to stdout sys.stdout.write(content) diff --git a/delivery1/client/bin/rep_delete_doc b/delivery1/client/bin/rep_delete_doc index 2a734df..28702d3 100755 --- a/delivery1/client/bin/rep_delete_doc +++ b/delivery1/client/bin/rep_delete_doc @@ -36,9 +36,9 @@ def delDoc(args): logger.error("File '" + args.session + "' not found.") sys.exit(-1) - doc = {'name' : args.name} + doc = {'session_file' : args.session, 'document_name' : args.name} try: - req = requests.post(f'http://{state['REP_ADDRESS']}/document/delete', json=json.dumps(doc)) + req = requests.post(f'http://{state['REP_ADDRESS']}/file/delete', json=json.dumps(doc)) req.raise_for_status() except requests.exceptions.RequestException as errex: diff --git a/delivery1/client/bin/rep_get_doc_file b/delivery1/client/bin/rep_get_doc_file index 6e8f860..7933e20 100755 --- a/delivery1/client/bin/rep_get_doc_file +++ b/delivery1/client/bin/rep_get_doc_file @@ -37,10 +37,10 @@ def getDoc(args): logger.error("File '" + args.session + "' not found.") sys.exit(-1) - doc = {'session' : args.session, 'name' : args.name} + doc = {'session_file' : args.session, 'document_name' : args.name} try: - req = requests.post(f'http://{state['REP_ADDRESS']}/subject/', json=json.dumps(doc)) + req = requests.post(f'http://{state['REP_ADDRESS']}/file/get', json=json.dumps(doc)) req.raise_for_status() except requests.exceptions.RequestException as errex: logger.error("Failed to obtain response from server.") diff --git a/delivery1/client/bin/rep_get_doc_metadata b/delivery1/client/bin/rep_get_doc_metadata index 565df25..8eb2fd0 100755 --- a/delivery1/client/bin/rep_get_doc_metadata +++ b/delivery1/client/bin/rep_get_doc_metadata @@ -39,10 +39,10 @@ def getDocMetadata(args): logger.error("File '" + args.session + "' not found.") sys.exit(-1) - doc = {'session' : args.session, 'name' : args.name} + doc = {'session_file' : args.session, 'document_name' : args.name} try: - req = requests.post(f'http://{state['REP_ADDRESS']}/document/metadata', json=json.dumps(doc)) + req = requests.post(f'http://{state['REP_ADDRESS']}/file/metadata', json=json.dumps(doc)) req.raise_for_status() except requests.exceptions.RequestException as errex: diff --git a/delivery1/client/bin/rep_get_file b/delivery1/client/bin/rep_get_file index 40f0d1a..3eb6df2 100755 --- a/delivery1/client/bin/rep_get_file +++ b/delivery1/client/bin/rep_get_file @@ -41,7 +41,7 @@ def getFile(args): logger.error("File '" + args.filehandle + "' not found" ) try: - file = requests.get(f'http://{state['REP_ADDRESS']}/file'), params = {"file_handle" : args.filehandle} + file = requests.get(f'http://{state['REP_ADDRESS']}/file', json=json.dumps({"file_handle" : args.filehandle})) file.raise_for_status() except requests.exceptions.RequestException as errex: logger.error("Failed to obtain response from server.") diff --git a/delivery1/client/bin/rep_list_docs b/delivery1/client/bin/rep_list_docs index bee43e3..3a8981b 100755 --- a/delivery1/client/bin/rep_list_docs +++ b/delivery1/client/bin/rep_list_docs @@ -52,8 +52,10 @@ def list_docs(args): validDate(args.newerThan) try: - subjects = requests.get(f'http://{state['REP_ADDRESS']}/user/list', - json=json.dumps({'username' : args.username, 'newerThan' : args.newerThan})) + subjects = requests.get(f'http://{state['REP_ADDRESS']}/file/list', + json=json.dumps({'session_file' : args.session, 'username' : args.username, + 'datetime' : {'value' : args.newerThan, 'relation' : 'nt'} + })) subjects.raise_for_status() except requests.exceptions.RequestException as errex: @@ -66,8 +68,10 @@ def list_docs(args): validDate(args.equalTo) try: - subjects = requests.get(f'http://{state['REP_ADDRESS']}/user/list', - json=json.dumps({'username' : args.username, 'equalTo' : args.equalTo})) + subjects = requests.get(f'http://{state['REP_ADDRESS']}/file/list', + json=json.dumps({'session_file' : args.session, 'username' : args.username, + 'datetime' : {'value' : args.equalTo, 'relation' : 'eq'} + })) subjects.raise_for_status() except requests.exceptions.RequestException as errex: @@ -80,8 +84,10 @@ def list_docs(args): validDate(args.olderThan) try: - subjects = requests.get(f'http://{state['REP_ADDRESS']}/user/list', - json=json.dumps({'username' : args.username, 'olderThan' : args.olderThan})) + subjects = requests.get(f'http://{state['REP_ADDRESS']}/file/list', + json=json.dumps({'session_file' : args.session, 'username' : args.username, + 'datetime' : {'value' : args.olderThan, 'relation' : 'ot'} + })) subjects.raise_for_status() except requests.exceptions.RequestException as errex: @@ -92,7 +98,7 @@ def list_docs(args): else: try: - subjects = requests.get(f'http://{state['REP_ADDRESS']}/user/list') + subjects = requests.get(f'http://{state['REP_ADDRESS']}/file/list', json=json.dumps({'session_file' : args.session})) subjects.raise_for_status() except requests.exceptions.RequestException as errex: diff --git a/delivery1/client/bin/rep_list_orgs b/delivery1/client/bin/rep_list_orgs index 135c742..13b1b97 100755 --- a/delivery1/client/bin/rep_list_orgs +++ b/delivery1/client/bin/rep_list_orgs @@ -19,7 +19,7 @@ state = main(sys.argv) def listOrganizations(): try: - orgs = json.loads(requests.get(f'http://{state['REP_ADDRESS']}/organization/list')) + orgs = json.loads(requests.get(f'http://{state['REP_ADDRESS']}/org/list')) orgs.raise_for_status() except requests.exceptions.RequestException as errex: diff --git a/delivery1/client/bin/rep_list_subjects b/delivery1/client/bin/rep_list_subjects index e3f4160..57336be 100755 --- a/delivery1/client/bin/rep_list_subjects +++ b/delivery1/client/bin/rep_list_subjects @@ -36,7 +36,8 @@ def list_subjects(args): if args.username: try: - subjects = json.loads(requests.get(f'http://{state['REP_ADDRESS']}/subject/list', json=json.dumps({'username' : args.username}))) + subjects = json.loads(requests.get(f'http://{state['REP_ADDRESS']}/user/list', + json=json.dumps({'session_file' : args.session, 'username' : args.username}))) subjects.raise_for_status() except requests.exceptions.RequestException as errex: @@ -45,7 +46,8 @@ def list_subjects(args): else: try: - subjects = json.loads(requests.get(f'http://{state['REP_ADDRESS']}/subject/list')) + subjects = json.loads(requests.get(f'http://{state['REP_ADDRESS']}/user/list'), + json=json.dumps({'session_file' : args.session})) subjects.raise_for_status() except requests.exceptions.RequestException as errex: diff --git a/delivery1/client/bin/rep_subject_credentials b/delivery1/client/bin/rep_subject_credentials index 731fae6..94cb4a8 100755 --- a/delivery1/client/bin/rep_subject_credentials +++ b/delivery1/client/bin/rep_subject_credentials @@ -1,4 +1,5 @@ #!/bin/python3 +import os import sys import logging import argparse @@ -29,6 +30,10 @@ def generateKeyPair(args): #Generate the key pair key_pair.generate_key_pair(args.pubfile, args.privfile, 2048, args.password) + #Save key files in environment + os.environ['PRIV_KEY'] = args.privfile + os.environ['PUB_KEY'] = args.pubfile + return 0 if __name__ == '__main__': diff --git a/delivery1/client/bin/rep_suspend_subject b/delivery1/client/bin/rep_suspend_subject index 6708ce5..6d14865 100755 --- a/delivery1/client/bin/rep_suspend_subject +++ b/delivery1/client/bin/rep_suspend_subject @@ -36,8 +36,8 @@ def suspendSubject(args): logger.error("File '" + args.session + "' not found.") sys.exit(-1) - subject = {'username' : args.username, 'status' : 'suspend'} - req = requests.post(f'http://{state['REP_ADDRESS']}/subject/', json=json.dumps(subject)) + subject = {'session_file' : args.session, 'username' : args.username} + req = requests.post(f'http://{state['REP_ADDRESS']}/user/suspend', json=json.dumps(subject)) if __name__ == '__main__': suspendSubject(sys.argv[1:]) \ No newline at end of file