Changed dict keys to match APIs
This commit is contained in:
parent
a27348567f
commit
88808df921
|
@ -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.")
|
||||
|
|
|
@ -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:
|
||||
|
|
|
@ -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:
|
||||
|
|
|
@ -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.")
|
||||
|
|
|
@ -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")
|
||||
|
|
|
@ -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)
|
||||
|
|
|
@ -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:
|
||||
|
|
|
@ -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.")
|
||||
|
|
|
@ -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:
|
||||
|
|
|
@ -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.")
|
||||
|
|
|
@ -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:
|
||||
|
|
|
@ -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:
|
||||
|
|
|
@ -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:
|
||||
|
|
|
@ -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__':
|
||||
|
|
|
@ -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:])
|
Loading…
Reference in New Issue