From f9e8b2d5222979a82db122afd194e63f469cd720 Mon Sep 17 00:00:00 2001 From: Chris Hines <chris.hines@monash.edu> Date: Wed, 22 May 2019 11:02:19 +0800 Subject: [PATCH] fix up status codes, so 403 Forbidden is used more correctly --- TES/tes/apiendpoints.py | 14 +++++++------- 1 file changed, 7 insertions(+), 7 deletions(-) diff --git a/TES/tes/apiendpoints.py b/TES/tes/apiendpoints.py index 5004dd7..5d9bddc 100644 --- a/TES/tes/apiendpoints.py +++ b/TES/tes/apiendpoints.py @@ -210,7 +210,7 @@ class JobStat(Resource): sshsess = SSHSession.get_sshsession() sshsess.refresh() except: - flask_restful.abort(400, message="Error relating to the ssh sessions") + flask_restful.abort(500, message="Error relating to the ssh sessions") try: cmd = json.loads(request.args.get('statcmd')) host = json.loads(request.args.get('host')) @@ -223,9 +223,9 @@ class JobStat(Resource): res = Ssh.execute(sshsess, host=host, user=user, cmd=cmd) except SshAgentException as e: logger.error(e) - flask_restful.abort(400, message="Identity error {}".format(e)) + flask_restful.abort(403, message="Identity error {}".format(e)) except SshCtrlException as e: - flask_restful.abort(400,message="We're having difficultly contacting {}. We failed with the message: {}".format(host,e)) + flask_restful.abort(403,message="We're having difficultly contacting {}. We failed with the message: {}".format(host,e)) if not (res['stderr'] == '' or res['stderr'] is None or res['stderr'] == b''): logger.error(res['stderr']) flask_restful.abort(400, message=res['stderr'].decode()) @@ -258,13 +258,13 @@ class MkDir(Resource): Ssh.sftpmkdir(sshsess, host=params['identity']['site']['host'], user=params['identity']['username'], path=params['path'],name=data['name'], sshport=sshport) except SftpPermissionException as e: - flask_restful.abort(400,message="You don't have permission to make a directory there") + flask_restful.abort(403,message="You don't have permission to make a directory there") except SftpException as e: - flask_restful.abort(400,message="Something went wrong making that directory") + flask_restful.abort(500,message="Something went wrong making that directory") except Exception as e: import traceback logger.error(traceback.format_exc()) - flask_restful.abort(400,message="Something went wrong creating that directory, probably a bug") + flask_restful.abort(500,message="Something went wrong creating that directory, probably a bug") return @@ -295,7 +295,7 @@ class DirList(Resource): try: dirls = json.loads(res['stdout'].decode()) except: - flask_restful.abort(404,message="You don't have permission to view that directory") + flask_restful.abort(403,message="You don't have permission to view that directory") else: logger.debug('using ssh.sftpls') -- GitLab