From 7bef5b468ce5ad127485d35e58be63589963686c Mon Sep 17 00:00:00 2001 From: JoaoBastos023 Date: Wed, 20 Nov 2024 22:03:50 +0000 Subject: [PATCH] minor + reset db function --- delivery1/client/bin/rep_activate_subject | 2 +- delivery1/client/bin/rep_add_doc | 2 +- delivery1/client/bin/rep_add_subject | 2 +- delivery1/client/bin/rep_create_org | 4 +- delivery1/client/bin/rep_create_session | 4 +- delivery1/client/bin/rep_decrypt_file | 2 +- delivery1/client/bin/rep_delete_doc | 2 +- delivery1/client/bin/rep_get_doc_file | 2 +- delivery1/client/bin/rep_get_doc_metadata | 2 +- delivery1/client/bin/rep_get_file | 2 +- delivery1/client/bin/rep_list_docs | 2 +- delivery1/client/bin/rep_list_orgs | 2 +- delivery1/client/bin/rep_list_subjects | 4 +- delivery1/client/bin/rep_subject_credentials | 2 +- delivery1/client/bin/rep_suspend_subject | 2 +- delivery1/client/bin/reset_database | 42 ++++++++++++++++++++ delivery1/client/bin/subject.py | 0 17 files changed, 60 insertions(+), 18 deletions(-) create mode 100755 delivery1/client/bin/reset_database mode change 100644 => 100755 delivery1/client/bin/subject.py diff --git a/delivery1/client/bin/rep_activate_subject b/delivery1/client/bin/rep_activate_subject index cbc7854..1bec38c 100755 --- a/delivery1/client/bin/rep_activate_subject +++ b/delivery1/client/bin/rep_activate_subject @@ -14,7 +14,7 @@ logger.setLevel(logging.INFO) state = main(sys.argv) -BASE_DIR= os.path.join(os.path.expanduser('~'), '.sio/') +BASE_DIR = os.path.join(os.path.expanduser('~'), '.sio/') #session file - username def activateSubject(args): diff --git a/delivery1/client/bin/rep_add_doc b/delivery1/client/bin/rep_add_doc index a170ce3..209e72d 100755 --- a/delivery1/client/bin/rep_add_doc +++ b/delivery1/client/bin/rep_add_doc @@ -18,7 +18,7 @@ logger.setLevel(logging.INFO) state = main(sys.argv) -BASE_DIR= os.path.join(os.path.expanduser('~'), '.sio/') +BASE_DIR = os.path.join(os.path.expanduser('~'), '.sio/') # session file - document name - file def addDoc(args): diff --git a/delivery1/client/bin/rep_add_subject b/delivery1/client/bin/rep_add_subject index 854b3de..52b4d43 100755 --- a/delivery1/client/bin/rep_add_subject +++ b/delivery1/client/bin/rep_add_subject @@ -16,7 +16,7 @@ logger.setLevel(logging.INFO) state = main(sys.argv) -BASE_DIR= os.path.join(os.path.expanduser('~'), '.sio/') +BASE_DIR = os.path.join(os.path.expanduser('~'), '.sio/') # session file - username - name - email - credentials file def addSubject(args): diff --git a/delivery1/client/bin/rep_create_org b/delivery1/client/bin/rep_create_org index ace0959..71b9a1d 100755 --- a/delivery1/client/bin/rep_create_org +++ b/delivery1/client/bin/rep_create_org @@ -19,7 +19,7 @@ logger.setLevel(logging.INFO) state = main(sys.argv) -BASE_DIR= os.path.join(os.path.expanduser('~'), '.sio/') +BASE_DIR = os.path.join(os.path.expanduser('~'), '.sio/') # Create organization # organization - username - name - email - public key file @@ -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'https://{state['REP_ADDRESS']}/org/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 eb12fc8..126a947 100755 --- a/delivery1/client/bin/rep_create_session +++ b/delivery1/client/bin/rep_create_session @@ -17,7 +17,7 @@ logger.setLevel(logging.INFO) state = main(sys.argv) -BASE_DIR= os.path.join(os.path.expanduser('~'), '.sio/') +BASE_DIR = os.path.join(os.path.expanduser('~'), '.sio/') # org - username - password - credentials file - session file def createSession(args): @@ -49,7 +49,7 @@ def createSession(args): #print( type(json.dumps(session))) try: - req = requests.post(f'https://{state['REP_ADDRESS']}/user/login', 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 7e90d6c..9771c32 100755 --- a/delivery1/client/bin/rep_decrypt_file +++ b/delivery1/client/bin/rep_decrypt_file @@ -11,7 +11,7 @@ logging.basicConfig(format='%(levelname)s\t- %(message)s') logger = logging.getLogger() logger.setLevel(logging.INFO) -BASE_DIR= os.path.join(os.path.expanduser('~'), '.sio/') +BASE_DIR = os.path.join(os.path.expanduser('~'), '.sio/') #send to stdout contents of decrypted file # encrypted file - encryption metadata diff --git a/delivery1/client/bin/rep_delete_doc b/delivery1/client/bin/rep_delete_doc index 7f72d7b..4f78ec4 100755 --- a/delivery1/client/bin/rep_delete_doc +++ b/delivery1/client/bin/rep_delete_doc @@ -15,7 +15,7 @@ logger.setLevel(logging.INFO) state = main(sys.argv) -BASE_DIR= os.path.join(os.path.expanduser('~'), '.sio/') +BASE_DIR = os.path.join(os.path.expanduser('~'), '.sio/') # session file - document name def delDoc(args): diff --git a/delivery1/client/bin/rep_get_doc_file b/delivery1/client/bin/rep_get_doc_file index 1a0af30..c10059e 100755 --- a/delivery1/client/bin/rep_get_doc_file +++ b/delivery1/client/bin/rep_get_doc_file @@ -17,7 +17,7 @@ logger.setLevel(logging.INFO) state = main(sys.argv) -BASE_DIR= os.path.join(os.path.expanduser('~'), '.sio/') +BASE_DIR = os.path.join(os.path.expanduser('~'), '.sio/') # session file - document name - output file(optional) def getDoc(args): diff --git a/delivery1/client/bin/rep_get_doc_metadata b/delivery1/client/bin/rep_get_doc_metadata index bf5c6a8..257c07b 100755 --- a/delivery1/client/bin/rep_get_doc_metadata +++ b/delivery1/client/bin/rep_get_doc_metadata @@ -15,7 +15,7 @@ logger.setLevel(logging.INFO) state = main(sys.argv) -BASE_DIR= os.path.join(os.path.expanduser('~'), '.sio/') +BASE_DIR = os.path.join(os.path.expanduser('~'), '.sio/') # session file - document name def getDocMetadata(args): diff --git a/delivery1/client/bin/rep_get_file b/delivery1/client/bin/rep_get_file index f81cac8..a8f7d50 100755 --- a/delivery1/client/bin/rep_get_file +++ b/delivery1/client/bin/rep_get_file @@ -17,7 +17,7 @@ logger.setLevel(logging.INFO) state = main(sys.argv) -BASE_DIR= os.path.join(os.path.expanduser('~'), '.sio/') +BASE_DIR = os.path.join(os.path.expanduser('~'), '.sio/') #get file #file handle - file(optonal) diff --git a/delivery1/client/bin/rep_list_docs b/delivery1/client/bin/rep_list_docs index a3be21d..bd16aa0 100755 --- a/delivery1/client/bin/rep_list_docs +++ b/delivery1/client/bin/rep_list_docs @@ -15,7 +15,7 @@ logger.setLevel(logging.INFO) state = main(sys.argv) -BASE_DIR= os.path.join(os.path.expanduser('~'), '.sio/') +BASE_DIR = os.path.join(os.path.expanduser('~'), '.sio/') def validDate(input): try: diff --git a/delivery1/client/bin/rep_list_orgs b/delivery1/client/bin/rep_list_orgs index 22ab79b..147b881 100755 --- a/delivery1/client/bin/rep_list_orgs +++ b/delivery1/client/bin/rep_list_orgs @@ -18,7 +18,7 @@ state = main(sys.argv) def listOrganizations(): try: - orgs = requests.get(f'https://{state['REP_ADDRESS']}/org/list') + orgs = 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 6733da8..ccf4d49 100755 --- a/delivery1/client/bin/rep_list_subjects +++ b/delivery1/client/bin/rep_list_subjects @@ -14,7 +14,7 @@ logger.setLevel(logging.INFO) state = main(sys.argv) -BASE_DIR= os.path.join(os.path.expanduser('~'), '.sio/') +BASE_DIR = os.path.join(os.path.expanduser('~'), '.sio/') # session file - username(optional) def list_subjects(args): @@ -56,7 +56,7 @@ def list_subjects(args): else: try: - subjects = requests.get(f'https://{state['REP_ADDRESS']}/user/list', + subjects = requests.get(f'http://{state['REP_ADDRESS']}/user/list', json=json.dumps({}), headers={'Authorization': args.session['token']}) subjects.raise_for_status() diff --git a/delivery1/client/bin/rep_subject_credentials b/delivery1/client/bin/rep_subject_credentials index b020445..6cf0e7f 100755 --- a/delivery1/client/bin/rep_subject_credentials +++ b/delivery1/client/bin/rep_subject_credentials @@ -11,7 +11,7 @@ logging.basicConfig(format='%(levelname)s\t- %(message)s') logger = logging.getLogger() logger.setLevel(logging.INFO) -BASE_DIR= os.path.join(os.path.expanduser('~'), '.sio/') +BASE_DIR = os.path.join(os.path.expanduser('~'), '.sio/') # Generate a key pair for a subject # password - file for public key, file for private key diff --git a/delivery1/client/bin/rep_suspend_subject b/delivery1/client/bin/rep_suspend_subject index daef1cb..f8a5147 100755 --- a/delivery1/client/bin/rep_suspend_subject +++ b/delivery1/client/bin/rep_suspend_subject @@ -15,7 +15,7 @@ logger.setLevel(logging.INFO) state = main(sys.argv) -BASE_DIR= os.path.join(os.path.expanduser('~'), '.sio/') +BASE_DIR = os.path.join(os.path.expanduser('~'), '.sio/') # session file - username def suspendSubject(args): diff --git a/delivery1/client/bin/reset_database b/delivery1/client/bin/reset_database new file mode 100755 index 0000000..73b49bb --- /dev/null +++ b/delivery1/client/bin/reset_database @@ -0,0 +1,42 @@ +#!/bin/python3 +import os +import sys +import logging +import requests +import json +import argparse + +sys.path.append(os.path.abspath("../")) +from subject import main + +logging.basicConfig(format='%(levelname)s\t- %(message)s') +logger = logging.getLogger() +logger.setLevel(logging.INFO) + +state = main(sys.argv) + +def reset(args): + + parser = argparse.ArgumentParser() + + parser.add_argument("-k", '--key', nargs=1, help="Path to the key file") + parser.add_argument("-r", '--repo', nargs=1, help="Address:Port of the repository") + parser.add_argument("-v", '--verbose', help="Increase verbosity", action="store_true") + + parser.add_argument('password', nargs='?', default=None) + + args = parser.parse_args() + + if not args.password: + logger.error("Need password") + sys.exit(1) + + try: + req = requests.post(f'http://{state['REP_ADDRESS']}/reset',json=json.dumps({'password' : args.password})) + req.raise_for_status() + except requests.exceptions.RequestException as errex: + logger.error("Failed to obtain response from server.") + sys.exit(-1) + +if __name__ == '__main__': + reset(sys.argv[1:]) diff --git a/delivery1/client/bin/subject.py b/delivery1/client/bin/subject.py old mode 100644 new mode 100755