adjusted client changes
This commit is contained in:
parent
583e804342
commit
ae9ae8b510
|
@ -31,11 +31,11 @@ def activateSubject(args):
|
||||||
|
|
||||||
if not args.session or not args.username:
|
if not args.session or not args.username:
|
||||||
logger.error("Need session file and username.")
|
logger.error("Need session file and username.")
|
||||||
sys.exit(-1)
|
sys.exit(1)
|
||||||
|
|
||||||
if (not os.path.isfile(BASE_DIR + args.session)):
|
if (not os.path.isfile(BASE_DIR + args.session)):
|
||||||
logger.error("File '" + args.session + "' not found.")
|
logger.error("File '" + args.session + "' not found.")
|
||||||
sys.exit(-1)
|
sys.exit(1)
|
||||||
|
|
||||||
# Get session file content
|
# Get session file content
|
||||||
with open(BASE_DIR + args.session, 'r') as f:
|
with open(BASE_DIR + args.session, 'r') as f:
|
||||||
|
@ -46,7 +46,9 @@ def activateSubject(args):
|
||||||
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.")
|
||||||
sys.exit(1)
|
sys.exit(-1)
|
||||||
|
|
||||||
|
sys.exit(0)
|
||||||
|
|
||||||
if __name__ == '__main__':
|
if __name__ == '__main__':
|
||||||
activateSubject(sys.argv[1:])
|
activateSubject(sys.argv[1:])
|
|
@ -36,26 +36,25 @@ def addDoc(args):
|
||||||
|
|
||||||
if not args.session or not args.name or not args.file:
|
if not args.session or not args.name or not args.file:
|
||||||
logger.error("Need session file, document's name and file to upload.")
|
logger.error("Need session file, document's name and file to upload.")
|
||||||
sys.exit(-1)
|
sys.exit(1)
|
||||||
|
|
||||||
if (not os.path.isfile(os.path.join(BASE_DIR, args.session))):
|
if (not os.path.isfile(os.path.join(BASE_DIR, args.session))):
|
||||||
logger.error("File '" + args.session + "' not found.")
|
logger.error("File '" + args.session + "' not found.")
|
||||||
sys.exit(-1)
|
sys.exit(1)
|
||||||
|
|
||||||
if (not os.path.isfile(os.path.join(BASE_DIR, args.file))):
|
if (not os.path.isfile(os.path.join(BASE_DIR, args.file))):
|
||||||
logger.error("File '" + args.file + "' not found")
|
logger.error("File '" + args.file + "' not found")
|
||||||
sys.exit(-1)
|
sys.exit(1)
|
||||||
|
|
||||||
#Get session file content
|
#Get session file content
|
||||||
with open(os.path.join(BASE_DIR, args.session), 'r') as f:
|
with open(os.path.join(BASE_DIR, args.session), 'r') as f:
|
||||||
args.session = json.load(f)
|
args.session = json.load(f)
|
||||||
|
|
||||||
# Get hash of document's name for doc handle
|
#Encrypt content
|
||||||
doc_name = digest.get_hash(bytes(args.name, encoding='utf-8'))
|
key, nonce = encrypt_file(BASE_DIR + args.file, BASE_DIR + 'encryptedText')
|
||||||
|
|
||||||
|
|
||||||
#Upload document metadata
|
#Upload document metadata
|
||||||
doc = {'document_name' : doc_name}
|
doc = {'document_name' : args.name, 'key' : key, 'alg' : 'AES-CFB', 'nonce' : nonce }
|
||||||
|
|
||||||
try:
|
try:
|
||||||
req = requests.post(f'http://{state['REP_ADDRESS']}/file/upload', json=json.dumps(doc), headers={'Authorization': args.session['token']})
|
req = requests.post(f'http://{state['REP_ADDRESS']}/file/upload', json=json.dumps(doc), headers={'Authorization': args.session['token']})
|
||||||
|
@ -63,20 +62,19 @@ def addDoc(args):
|
||||||
|
|
||||||
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.")
|
||||||
sys.exit(1)
|
sys.exit(-1)
|
||||||
|
|
||||||
#Upload Document content
|
#Upload Document content
|
||||||
#Create salt
|
|
||||||
salt = os.urandom(16)
|
|
||||||
|
|
||||||
#Encrypt content
|
|
||||||
encrypt_file(salt, BASE_DIR + args.file, BASE_DIR + 'encryptedText')
|
|
||||||
|
|
||||||
with open(BASE_DIR + 'encryptedText', 'rb') as f:
|
with open(BASE_DIR + 'encryptedText', 'rb') as f:
|
||||||
content = f.read()
|
content = f.read()
|
||||||
|
|
||||||
|
file = {'file' : open(BASE_DIR + args.file, 'rb')}
|
||||||
|
|
||||||
try:
|
try:
|
||||||
req = requests.post(f'http://{state['REP_ADDRESS']}/file/upload', json=json.dumps({'dw' : content.hex()}), headers={'Authorization': args.session['token']})
|
req = requests.post(f'http://{state['REP_ADDRESS']}/file/upload',
|
||||||
|
files=file,
|
||||||
|
headers={'Authorization': args.session['token'], 'File-Checksum' : content.hex()})
|
||||||
req.raise_for_status()
|
req.raise_for_status()
|
||||||
|
|
||||||
except requests.exceptions.RequestException as errex:
|
except requests.exceptions.RequestException as errex:
|
||||||
|
|
|
@ -36,11 +36,11 @@ def addSubject(args):
|
||||||
|
|
||||||
if not args.session or not args.username or not args.name or not args.email or not args.credentials:
|
if not args.session or not args.username or not args.name or not args.email or not args.credentials:
|
||||||
logger.error("Need session file, username, name, email and credentials file.")
|
logger.error("Need session file, username, name, email and credentials file.")
|
||||||
sys.exit(-1)
|
sys.exit(1)
|
||||||
|
|
||||||
if (not os.path.isfile(BASE_DIR + args.session)):
|
if (not os.path.isfile(BASE_DIR + args.session)):
|
||||||
logger.error("File '" + args.session + "' not found.")
|
logger.error("File '" + args.session + "' not found.")
|
||||||
sys.exit(-1)
|
sys.exit(1)
|
||||||
|
|
||||||
# Get session file content
|
# Get session file content
|
||||||
with open(BASE_DIR + args.session, 'r') as f:
|
with open(BASE_DIR + args.session, 'r') as f:
|
||||||
|
@ -48,7 +48,7 @@ def addSubject(args):
|
||||||
|
|
||||||
if (not os.path.isfile(BASE_DIR + args.credentials)):
|
if (not os.path.isfile(BASE_DIR + args.credentials)):
|
||||||
logger.error("File '" + args.file + "' not found")
|
logger.error("File '" + args.file + "' not found")
|
||||||
sys.exit(-1)
|
sys.exit(1)
|
||||||
|
|
||||||
subject = {'username' : args.username, 'name' : args.name, 'email' : args.email, 'credentials_file' : args.credentials}
|
subject = {'username' : args.username, 'name' : args.name, 'email' : args.email, 'credentials_file' : args.credentials}
|
||||||
|
|
||||||
|
@ -58,7 +58,7 @@ def addSubject(args):
|
||||||
|
|
||||||
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.")
|
||||||
sys.exit(1)
|
sys.exit(-1)
|
||||||
|
|
||||||
sys.exit(0)
|
sys.exit(0)
|
||||||
|
|
||||||
|
|
|
@ -41,17 +41,17 @@ def createOrganization(args):
|
||||||
|
|
||||||
if not args.org or not args.username or not args.name or not args.email or not args.pubkey:
|
if not args.org or not args.username or not args.name or not args.email or not args.pubkey:
|
||||||
logger.error("Need organization, username, name, email and key file.")
|
logger.error("Need organization, username, name, email and key file.")
|
||||||
sys.exit(-1)
|
sys.exit(1)
|
||||||
|
|
||||||
# Validate email
|
# Validate email
|
||||||
if not re.match(r'^[a-zA-Z0-9._%+-]+@[a-zA-Z0-9.-]+\.[a-zA-Z]{2,}$', args.email):
|
if not re.match(r'^[a-zA-Z0-9._%+-]+@[a-zA-Z0-9.-]+\.[a-zA-Z]{2,}$', args.email):
|
||||||
logger.error("Need a valid email.")
|
logger.error("Need a valid email.")
|
||||||
sys.exit(-1)
|
sys.exit(1)
|
||||||
|
|
||||||
# Validate key file
|
# Validate key file
|
||||||
if (not os.path.isfile(BASE_DIR + args.pubkey)):
|
if (not os.path.isfile(BASE_DIR + args.pubkey)):
|
||||||
logger.error("File '" + args.pubkey + "' not found.")
|
logger.error("File '" + args.pubkey + "' not found.")
|
||||||
sys.exit(-1)
|
sys.exit(1)
|
||||||
|
|
||||||
# load public key from file
|
# load public key from file
|
||||||
pubKey = asymmetric_functs.load_public_key(BASE_DIR + args.pubkey)
|
pubKey = asymmetric_functs.load_public_key(BASE_DIR + args.pubkey)
|
||||||
|
@ -63,7 +63,9 @@ def createOrganization(args):
|
||||||
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.")
|
||||||
sys.exit(1)
|
sys.exit(-1)
|
||||||
|
|
||||||
|
sys.exit(0)
|
||||||
|
|
||||||
if __name__ == '__main__':
|
if __name__ == '__main__':
|
||||||
createOrganization(sys.argv[1:])
|
createOrganization(sys.argv[1:])
|
||||||
|
|
|
@ -38,11 +38,11 @@ def createSession(args):
|
||||||
|
|
||||||
if not args.org or not args.username or not args.password or not args.credentials or not args.session:
|
if not args.org or not args.username or not args.password or not args.credentials or not args.session:
|
||||||
logger.error("Need organization, username, password, credentials and session file")
|
logger.error("Need organization, username, password, credentials and session file")
|
||||||
sys.exit(-1)
|
sys.exit(1)
|
||||||
|
|
||||||
if (not os.path.isfile(BASE_DIR + args.credentials)):
|
if (not os.path.isfile(BASE_DIR + args.credentials)):
|
||||||
logger.error("File '" + args.credentials + "' not found.")
|
logger.error("File '" + args.credentials + "' not found.")
|
||||||
sys.exit(-1)
|
sys.exit(1)
|
||||||
|
|
||||||
session = {'org' : args.org, 'username' : args.username, 'password' : args.password, 'credentials_file' : args.credentials}
|
session = {'org' : args.org, 'username' : args.username, 'password' : args.password, 'credentials_file' : args.credentials}
|
||||||
|
|
||||||
|
@ -53,10 +53,12 @@ def createSession(args):
|
||||||
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")
|
||||||
sys.exit(1)
|
sys.exit(-1)
|
||||||
|
|
||||||
with open(BASE_DIR + args.session, 'w') as f:
|
with open(BASE_DIR + args.session, 'w') as f:
|
||||||
f.write(req.json())
|
f.write(req.json())
|
||||||
|
|
||||||
|
sys.exit(0)
|
||||||
|
|
||||||
if __name__ == '__main__':
|
if __name__ == '__main__':
|
||||||
createSession(sys.argv[1:])
|
createSession(sys.argv[1:])
|
|
@ -24,28 +24,28 @@ def decryptFile(args):
|
||||||
|
|
||||||
args = parser.parse_args()
|
args = parser.parse_args()
|
||||||
|
|
||||||
if len(args) != 2:
|
if not args.encrypted or not args.metadata:
|
||||||
logger.error("Need encrypted file and it's metadata.")
|
logger.error("Need encrypted file and it's metadata.")
|
||||||
sys.exit(-1)
|
sys.exit(1)
|
||||||
|
|
||||||
# If first argument is not a file or not found
|
# If first argument is not a file or not found
|
||||||
if (not os.path.isfile(BASE_DIR + args.encrypted)):
|
if (not os.path.isfile(BASE_DIR + args.encrypted)):
|
||||||
logger.error("File '" + args.encrypted + "' not found.")
|
logger.error("File '" + args.encrypted + "' not found.")
|
||||||
sys.exit(-1)
|
sys.exit(1)
|
||||||
|
|
||||||
if (not os.path.isfile(BASE_DIR + args.metadata)):
|
if (not os.path.isfile(BASE_DIR + args.metadata)):
|
||||||
logger.error("File '" + args.metadata + "' not found.")
|
logger.error("File '" + args.metadata + "' not found.")
|
||||||
sys.exit(-1)
|
sys.exit(1)
|
||||||
|
|
||||||
#Decrypt file
|
#Decrypt file
|
||||||
metadata = json.loads(BASE_DIR + args.metadata)
|
metadata = json.loads(BASE_DIR + args.metadata)
|
||||||
salt = metadata['salt']
|
|
||||||
|
|
||||||
content = symmetric_encryption.decrypt_file(metadata['password'], args.encrypted)
|
content = symmetric_encryption.decrypt_file(args.encrypted)
|
||||||
|
|
||||||
# Send decrypted content to stdout
|
# Send decrypted content to stdout
|
||||||
sys.stdout.write(content)
|
sys.stdout.write(content)
|
||||||
|
|
||||||
|
sys.exit(0)
|
||||||
|
|
||||||
if __name__ == '__main__':
|
if __name__ == '__main__':
|
||||||
decryptFile(sys.argv[1:])
|
decryptFile(sys.argv[1:])
|
||||||
|
|
|
@ -32,11 +32,11 @@ def delDoc(args):
|
||||||
|
|
||||||
if not args.session or not args.name:
|
if not args.session or not args.name:
|
||||||
logger.error("Need session file and document's name.")
|
logger.error("Need session file and document's name.")
|
||||||
sys.exit(-1)
|
sys.exit(1)
|
||||||
|
|
||||||
if (not os.path.isfile(BASE_DIR + args.session)):
|
if (not os.path.isfile(BASE_DIR + args.session)):
|
||||||
logger.error("File '" + args.session + "' not found.")
|
logger.error("File '" + args.session + "' not found.")
|
||||||
sys.exit(-1)
|
sys.exit(1)
|
||||||
|
|
||||||
# Get session file content
|
# Get session file content
|
||||||
with open(BASE_DIR + args.session, 'r') as f:
|
with open(BASE_DIR + args.session, 'r') as f:
|
||||||
|
@ -51,7 +51,7 @@ def delDoc(args):
|
||||||
|
|
||||||
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.")
|
||||||
sys.exit(1)
|
sys.exit(-1)
|
||||||
|
|
||||||
sys.exit(0)
|
sys.exit(0)
|
||||||
|
|
||||||
|
|
|
@ -9,6 +9,7 @@ import argparse
|
||||||
from subject import main
|
from subject import main
|
||||||
|
|
||||||
from lib import digest
|
from lib import digest
|
||||||
|
from lib import symmetric_encryption
|
||||||
|
|
||||||
logging.basicConfig(format='%(levelname)s\t- %(message)s')
|
logging.basicConfig(format='%(levelname)s\t- %(message)s')
|
||||||
logger = logging.getLogger()
|
logger = logging.getLogger()
|
||||||
|
@ -65,24 +66,23 @@ def getDoc(args):
|
||||||
file.raise_for_status()
|
file.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.")
|
||||||
sys.exit(1)
|
sys.exit(-1)
|
||||||
|
|
||||||
file = file.json()
|
file = file.json()
|
||||||
|
|
||||||
if not digest.get_hash(file) == metadata['file_handle']:
|
if not digest.get_hash(file) == metadata['file_handle']:
|
||||||
logger.error("Files integrity is lost.")
|
logger.error("Files integrity is lost.")
|
||||||
sys.exit(1)
|
sys.exit(-1)
|
||||||
|
|
||||||
key, alg = metadata['key'], metadata['alg']
|
content = symmetric_encryption.decrypt_file(file)
|
||||||
salt, passwd = alg['salt'], alg['password']
|
|
||||||
|
|
||||||
|
|
||||||
if args.output:
|
if args.output:
|
||||||
with open(BASE_DIR + args.output, 'w') as f:
|
with open(BASE_DIR + args.output, 'w') as f:
|
||||||
f.write(file)
|
f.write(content)
|
||||||
|
|
||||||
else:
|
else:
|
||||||
sys.stdout.write(file)
|
sys.stdout.write(content)
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
|
|
|
@ -33,11 +33,11 @@ def getDocMetadata(args):
|
||||||
|
|
||||||
if not args.session or not args.name:
|
if not args.session or not args.name:
|
||||||
logger.error("Need session file and document's name.")
|
logger.error("Need session file and document's name.")
|
||||||
sys.exit(-1)
|
sys.exit(1)
|
||||||
|
|
||||||
if (not os.path.isfile(BASE_DIR + args.session)):
|
if (not os.path.isfile(BASE_DIR + args.session)):
|
||||||
logger.error("File '" + args.session + "' not found.")
|
logger.error("File '" + args.session + "' not found.")
|
||||||
sys.exit(-1)
|
sys.exit(1)
|
||||||
|
|
||||||
# Get session file content
|
# Get session file content
|
||||||
with open(BASE_DIR + args.session, 'r') as f:
|
with open(BASE_DIR + args.session, 'r') as f:
|
||||||
|
@ -51,11 +51,13 @@ def getDocMetadata(args):
|
||||||
|
|
||||||
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.")
|
||||||
sys.exit(1)
|
sys.exit(-1)
|
||||||
|
|
||||||
metadata = metadata.json()
|
metadata = metadata.json()
|
||||||
|
|
||||||
sys.stdout.write(metadata)
|
sys.stdout.write(metadata)
|
||||||
|
|
||||||
|
sys.exit(0)
|
||||||
|
|
||||||
if __name__ == '__main__':
|
if __name__ == '__main__':
|
||||||
getDocMetadata(sys.argv[1:])
|
getDocMetadata(sys.argv[1:])
|
|
@ -36,10 +36,11 @@ def getFile(args):
|
||||||
|
|
||||||
if not args.filehandle:
|
if not args.filehandle:
|
||||||
logger.error("Need a file handle.")
|
logger.error("Need a file handle.")
|
||||||
sys.exit(-1)
|
sys.exit(1)
|
||||||
else:
|
else:
|
||||||
if not os.path.isfile(BASE_DIR + args.filehandle):
|
if not os.path.isfile(BASE_DIR + args.filehandle):
|
||||||
logger.error("File '" + args.filehandle + "' not found" )
|
logger.error("File '" + args.filehandle + "' not found" )
|
||||||
|
sys.exit(1)
|
||||||
|
|
||||||
#Get file
|
#Get file
|
||||||
try:
|
try:
|
||||||
|
@ -47,7 +48,7 @@ def getFile(args):
|
||||||
file.raise_for_status()
|
file.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.")
|
||||||
sys.exit(1)
|
sys.exit(-1)
|
||||||
|
|
||||||
file = file.json()
|
file = file.json()
|
||||||
|
|
||||||
|
@ -57,5 +58,7 @@ def getFile(args):
|
||||||
with open(BASE_DIR + args.file, "wb") as f:
|
with open(BASE_DIR + args.file, "wb") as f:
|
||||||
f.write(file)
|
f.write(file)
|
||||||
|
|
||||||
|
sys.exit(0)
|
||||||
|
|
||||||
if __name__ == '__main__':
|
if __name__ == '__main__':
|
||||||
getFile(sys.argv[1:])
|
getFile(sys.argv[1:])
|
|
@ -46,10 +46,10 @@ def list_docs(args):
|
||||||
if args.session:
|
if args.session:
|
||||||
if (not os.path.isfile(BASE_DIR + args.session)):
|
if (not os.path.isfile(BASE_DIR + args.session)):
|
||||||
logger.error("File '" + args.session + "' not found.")
|
logger.error("File '" + args.session + "' not found.")
|
||||||
sys.exit(-1)
|
sys.exit(1)
|
||||||
else:
|
else:
|
||||||
logger.error("Need session file.")
|
logger.error("Need session file.")
|
||||||
sys.exit(-1)
|
sys.exit(1)
|
||||||
|
|
||||||
# Get session file content
|
# Get session file content
|
||||||
with open(BASE_DIR + args.session, 'r') as f:
|
with open(BASE_DIR + args.session, 'r') as f:
|
||||||
|
@ -68,7 +68,7 @@ def list_docs(args):
|
||||||
|
|
||||||
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.")
|
||||||
sys.exit(1)
|
sys.exit(-1)
|
||||||
|
|
||||||
subjects = subjects.json()
|
subjects = subjects.json()
|
||||||
|
|
||||||
|
@ -86,7 +86,7 @@ def list_docs(args):
|
||||||
|
|
||||||
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.")
|
||||||
sys.exit(1)
|
sys.exit(-1)
|
||||||
|
|
||||||
subjects = subjects.json()
|
subjects = subjects.json()
|
||||||
|
|
||||||
|
@ -104,24 +104,25 @@ def list_docs(args):
|
||||||
|
|
||||||
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.")
|
||||||
sys.exit(1)
|
sys.exit(-1)
|
||||||
|
|
||||||
subjects = subjects.json()
|
subjects = subjects.json()
|
||||||
|
|
||||||
else:
|
else:
|
||||||
try:
|
try:
|
||||||
subjects = requests.get(f'http://{state['REP_ADDRESS']}/file/list', headers={'Authorization': args.session['token']})
|
subjects = requests.get(f'http://{state['REP_ADDRESS']}/file/list', json=json.dumps({}), headers={'Authorization': args.session['token']})
|
||||||
subjects.raise_for_status()
|
subjects.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.")
|
||||||
sys.exit(1)
|
sys.exit(-1)
|
||||||
|
|
||||||
subjects = subjects.json()
|
subjects = subjects.json()
|
||||||
|
|
||||||
for s in subjects:
|
for s in subjects:
|
||||||
sys.stdout.write(s['id'] + " - " + s['username'])
|
sys.stdout.write(s['id'] + " - " + s['username'])
|
||||||
|
|
||||||
|
sys.exit(0)
|
||||||
|
|
||||||
if __name__ == '__main__':
|
if __name__ == '__main__':
|
||||||
list_docs(sys.argv[1:])
|
list_docs(sys.argv[1:])
|
|
@ -23,10 +23,12 @@ def listOrganizations():
|
||||||
|
|
||||||
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.")
|
||||||
sys.exit(1)
|
sys.exit(-1)
|
||||||
|
|
||||||
for org in orgs.json():
|
for org in orgs.json():
|
||||||
sys.stdout.write(str(org['id']) + " - " + org['name'])
|
sys.stdout.write(str(org['id']) + " - " + org['name'])
|
||||||
|
|
||||||
|
sys.exit(0)
|
||||||
|
|
||||||
if __name__ == '__main__':
|
if __name__ == '__main__':
|
||||||
listOrganizations()
|
listOrganizations()
|
|
@ -34,10 +34,10 @@ def list_subjects(args):
|
||||||
if args.session:
|
if args.session:
|
||||||
if (not os.path.isfile(BASE_DIR + args.session)):
|
if (not os.path.isfile(BASE_DIR + args.session)):
|
||||||
logger.error("File '" + args.session + "' not found.")
|
logger.error("File '" + args.session + "' not found.")
|
||||||
sys.exit(-1)
|
sys.exit(1)
|
||||||
else:
|
else:
|
||||||
logger.error("Need session file.")
|
logger.error("Need session file.")
|
||||||
sys.exit(-1)
|
sys.exit(1)
|
||||||
|
|
||||||
# Get session file content
|
# Get session file content
|
||||||
with open(BASE_DIR + args.session, 'r') as f:
|
with open(BASE_DIR + args.session, 'r') as f:
|
||||||
|
@ -52,21 +52,24 @@ def list_subjects(args):
|
||||||
|
|
||||||
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.")
|
||||||
sys.exit(1)
|
sys.exit(-1)
|
||||||
|
|
||||||
else:
|
else:
|
||||||
try:
|
try:
|
||||||
subjects = requests.get(f'https://{state['REP_ADDRESS']}/user/list',
|
subjects = requests.get(f'https://{state['REP_ADDRESS']}/user/list',
|
||||||
|
json=json.dumps({}),
|
||||||
headers={'Authorization': args.session['token']})
|
headers={'Authorization': args.session['token']})
|
||||||
subjects.raise_for_status()
|
subjects.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.")
|
||||||
sys.exit(1)
|
sys.exit(-1)
|
||||||
|
|
||||||
for s in subjects.json():
|
for s in subjects.json():
|
||||||
sys.stdout.write(s['id'] + " - " + s['username'])
|
sys.stdout.write(s['id'] + " - " + s['username'])
|
||||||
|
|
||||||
|
|
||||||
|
sys.exit(0)
|
||||||
|
|
||||||
if __name__ == '__main__':
|
if __name__ == '__main__':
|
||||||
list_subjects(sys.argv[1:])
|
list_subjects(sys.argv[1:])
|
|
@ -27,13 +27,13 @@ def generateKeyPair(args):
|
||||||
|
|
||||||
if not args.password or not args.pubfile or not args.privfile:
|
if not args.password or not args.pubfile or not args.privfile:
|
||||||
logger.error("Need password and file to store keys")
|
logger.error("Need password and file to store keys")
|
||||||
sys.exit(-1)
|
sys.exit(1)
|
||||||
|
|
||||||
|
|
||||||
#Generate the key pair
|
#Generate the key pair
|
||||||
key_pair.generate_key_pair(BASE_DIR + args.pubfile, BASE_DIR + args.privfile, 2048, args.password)
|
key_pair.generate_key_pair(BASE_DIR + args.pubfile, BASE_DIR + args.privfile, 2048, args.password)
|
||||||
|
|
||||||
return 0
|
sys.exit(0)
|
||||||
|
|
||||||
if __name__ == '__main__':
|
if __name__ == '__main__':
|
||||||
generateKeyPair(sys.argv[1:])
|
generateKeyPair(sys.argv[1:])
|
||||||
|
|
|
@ -30,13 +30,13 @@ def suspendSubject(args):
|
||||||
|
|
||||||
args = parser.parse_args()
|
args = parser.parse_args()
|
||||||
|
|
||||||
if len(args) != 2:
|
if not args.session or not args.username:
|
||||||
logger.error("Need session file and username.")
|
logger.error("Need session file and username.")
|
||||||
sys.exit(-1)
|
sys.exit(1)
|
||||||
|
|
||||||
if (not os.path.isfile(BASE_DIR + args.session)):
|
if (not os.path.isfile(BASE_DIR + args.session)):
|
||||||
logger.error("File '" + args.session + "' not found.")
|
logger.error("File '" + args.session + "' not found.")
|
||||||
sys.exit(-1)
|
sys.exit(1)
|
||||||
|
|
||||||
# Get session file content
|
# Get session file content
|
||||||
with open(BASE_DIR + args.session, 'r') as f:
|
with open(BASE_DIR + args.session, 'r') as f:
|
||||||
|
@ -47,7 +47,9 @@ def suspendSubject(args):
|
||||||
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.")
|
||||||
sys.exit(1)
|
sys.exit(-1)
|
||||||
|
|
||||||
|
sys.exit(0)
|
||||||
|
|
||||||
if __name__ == '__main__':
|
if __name__ == '__main__':
|
||||||
suspendSubject(sys.argv[1:])
|
suspendSubject(sys.argv[1:])
|
|
@ -66,7 +66,7 @@ def parse_args(state):
|
||||||
if args.key:
|
if args.key:
|
||||||
if not os.path.exists(args.key[0]) or not os.path.isfile(args.key[0]):
|
if not os.path.exists(args.key[0]) or not os.path.isfile(args.key[0]):
|
||||||
logger.error(f'Key file not found or invalid: {args.key[0]}')
|
logger.error(f'Key file not found or invalid: {args.key[0]}')
|
||||||
sys.exit(-1)
|
sys.exit(1)
|
||||||
|
|
||||||
with open(args.key[0], 'r') as f:
|
with open(args.key[0], 'r') as f:
|
||||||
state['REP_PUB_KEY'] = f.read()
|
state['REP_PUB_KEY'] = f.read()
|
||||||
|
@ -102,11 +102,11 @@ def main(args):
|
||||||
|
|
||||||
if 'REP_ADDRESS' not in state:
|
if 'REP_ADDRESS' not in state:
|
||||||
logger.error("Must define Repository Address")
|
logger.error("Must define Repository Address")
|
||||||
sys.exit(-1)
|
sys.exit(1)
|
||||||
|
|
||||||
# if 'REP_PUB_KEY' not in state:
|
# if 'REP_PUB_KEY' not in state:
|
||||||
# logger.error("Must set the Repository Public Key")
|
# logger.error("Must set the Repository Public Key")
|
||||||
# sys.exit(-1)
|
# sys.exit(1)
|
||||||
|
|
||||||
save(state)
|
save(state)
|
||||||
|
|
||||||
|
|
Loading…
Reference in New Issue