minor + reset db function

This commit is contained in:
JoaoBastos023 2024-11-20 22:03:50 +00:00
parent ae9ae8b510
commit 7bef5b468c
17 changed files with 60 additions and 18 deletions

View File

@ -14,7 +14,7 @@ logger.setLevel(logging.INFO)
state = main(sys.argv) 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 #session file - username
def activateSubject(args): def activateSubject(args):

View File

@ -18,7 +18,7 @@ logger.setLevel(logging.INFO)
state = main(sys.argv) 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 # session file - document name - file
def addDoc(args): def addDoc(args):

View File

@ -16,7 +16,7 @@ logger.setLevel(logging.INFO)
state = main(sys.argv) 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 # session file - username - name - email - credentials file
def addSubject(args): def addSubject(args):

View File

@ -19,7 +19,7 @@ logger.setLevel(logging.INFO)
state = main(sys.argv) state = main(sys.argv)
BASE_DIR= os.path.join(os.path.expanduser('~'), '.sio/') BASE_DIR = os.path.join(os.path.expanduser('~'), '.sio/')
# Create organization # Create organization
# organization - username - name - email - public key file # 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} input = {'name' : args.org, 'username' : args.username, 'full_name' : args.name, 'email' : args.email, 'public_key' : pubKey}
try: 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() req.raise_for_status()
except requests.exceptions.RequestException as errex: except requests.exceptions.RequestException as errex:
logger.error("Failed to obtain response from server.") logger.error("Failed to obtain response from server.")

View File

@ -17,7 +17,7 @@ logger.setLevel(logging.INFO)
state = main(sys.argv) 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 # org - username - password - credentials file - session file
def createSession(args): def createSession(args):
@ -49,7 +49,7 @@ def createSession(args):
#print( type(json.dumps(session))) #print( type(json.dumps(session)))
try: 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() req.raise_for_status()
except requests.exceptions.RequestException as errex: except requests.exceptions.RequestException as errex:
logger.error("Failed to obtain response from server") logger.error("Failed to obtain response from server")

View File

@ -11,7 +11,7 @@ logging.basicConfig(format='%(levelname)s\t- %(message)s')
logger = logging.getLogger() logger = logging.getLogger()
logger.setLevel(logging.INFO) 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 #send to stdout contents of decrypted file
# encrypted file - encryption metadata # encrypted file - encryption metadata

View File

@ -15,7 +15,7 @@ logger.setLevel(logging.INFO)
state = main(sys.argv) 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 # session file - document name
def delDoc(args): def delDoc(args):

View File

@ -17,7 +17,7 @@ logger.setLevel(logging.INFO)
state = main(sys.argv) 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) # session file - document name - output file(optional)
def getDoc(args): def getDoc(args):

View File

@ -15,7 +15,7 @@ logger.setLevel(logging.INFO)
state = main(sys.argv) 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 # session file - document name
def getDocMetadata(args): def getDocMetadata(args):

View File

@ -17,7 +17,7 @@ logger.setLevel(logging.INFO)
state = main(sys.argv) state = main(sys.argv)
BASE_DIR= os.path.join(os.path.expanduser('~'), '.sio/') BASE_DIR = os.path.join(os.path.expanduser('~'), '.sio/')
#get file #get file
#file handle - file(optonal) #file handle - file(optonal)

View File

@ -15,7 +15,7 @@ logger.setLevel(logging.INFO)
state = main(sys.argv) 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): def validDate(input):
try: try:

View File

@ -18,7 +18,7 @@ state = main(sys.argv)
def listOrganizations(): def listOrganizations():
try: 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() orgs.raise_for_status()
except requests.exceptions.RequestException as errex: except requests.exceptions.RequestException as errex:

View File

@ -14,7 +14,7 @@ logger.setLevel(logging.INFO)
state = main(sys.argv) 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) # session file - username(optional)
def list_subjects(args): def list_subjects(args):
@ -56,7 +56,7 @@ def list_subjects(args):
else: else:
try: try:
subjects = requests.get(f'https://{state['REP_ADDRESS']}/user/list', subjects = requests.get(f'http://{state['REP_ADDRESS']}/user/list',
json=json.dumps({}), json=json.dumps({}),
headers={'Authorization': args.session['token']}) headers={'Authorization': args.session['token']})
subjects.raise_for_status() subjects.raise_for_status()

View File

@ -11,7 +11,7 @@ logging.basicConfig(format='%(levelname)s\t- %(message)s')
logger = logging.getLogger() logger = logging.getLogger()
logger.setLevel(logging.INFO) 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 # Generate a key pair for a subject
# password - file for public key, file for private key # password - file for public key, file for private key

View File

@ -15,7 +15,7 @@ logger.setLevel(logging.INFO)
state = main(sys.argv) 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 # session file - username
def suspendSubject(args): def suspendSubject(args):

View File

@ -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:])

0
delivery1/client/bin/subject.py Normal file → Executable file
View File