def run_submission(data): if ('plugin' not in data or 'plugin_info' not in data): API_LOG.log("Missing plugin fields in request") raise ex.BadRequestException("Missing plugin fields in request") if data['enable_auth']: if ('username' not in data or 'password' not in data): API_LOG.log("Missing plugin fields in request") raise ex.BadRequestException("Missing plugin fields in request") username = data['username'] password = data['password'] authorization = authorizer.get_authorization(api.authorization_url, username, password) if not authorization['success']: API_LOG.log("Unauthorized request") raise ex.UnauthorizedException() else: if data['plugin'] not in api.plugins: raise ex.BadRequestException() plugin = plugin_base.PLUGINS.get_plugin(data['plugin']) submission_id, executor = plugin.execute(data['plugin_info']) submissions[submission_id] = executor return {"job_id": submission_id}
def end_submission(submission_id, data, hard_finish): if 'enable_auth' not in data: API_LOG.log("Missing parameters in request") raise ex.BadRequestException() enable_auth = data['enable_auth'] if enable_auth: if 'username' not in data or 'password' not in data: API_LOG.log("Missing parameters in request") raise ex.BadRequestException() username = data['username'] password = data['password'] authorization = authorizer.get_authorization(api.authorization_url, username, password) if not authorization['success']: API_LOG.log("Unauthorized request") raise ex.UnauthorizedException() if submission_id not in submissions.keys(): API_LOG.log("Wrong request") raise ex.BadRequestException() if(hard_finish): submissions[submission_id].terminate_job() else: submissions[submission_id].stop_application() return {"job_id": submission_id}
def check_authorization(data): """ Checks the user's need to authenticate to Asperathos Raises: ex.BadRequestException -- Missing parameters in request ex.UnauthorizedException -- Unauthorized request """ if ('enable_auth' not in data): API_LOG.log("Missing parameters in request") raise ex.BadRequestException() enable_auth = data['enable_auth'] if enable_auth: if 'username' not in data or 'password' not in data: API_LOG.log("Missing parameters in request") raise ex.BadRequestException() username = data['username'] password = data['password'] authorization = authorizer.get_authorization(api.authorization_url, username, password) if not authorization['success']: API_LOG.log("Unauthorized request") raise ex.UnauthorizedException()
def run_submission(data): plugin_service.check_submission(plugin_connector, data) if ('plugin' not in data or 'plugin_info' not in data): API_LOG.log("Missing plugin fields in request") raise ex.BadRequestException("Missing plugin fields in request") if data['enable_auth']: if ('username' not in data or 'password' not in data): API_LOG.log("Missing plugin fields in request") raise ex.BadRequestException("Missing plugin fields in request") username = data['username'] password = data['password'] authorization = (authorizer.get_authorization(api.authorization_url, username, password)) if not authorization['success']: API_LOG.log("Unauthorized request") raise ex.UnauthorizedException() if data['plugin'] not in api.plugins: API_LOG.log("Plugin \"{}\" is missing.\ The plugins available are {}".format(data['plugin'], api.plugin)) raise ex.BadRequestException("Plugin \"{}\" is missing.\ The plugins available are {}".format(data['plugin'], api.plugin)) plugin = plugin_service.get_plugin(data['plugin']) submission_data = data['plugin_info'] submission_data['enable_auth'] = data['enable_auth'] submission_id, executor = plugin.execute(submission_data) submissions[submission_id] = executor return {"job_id": submission_id}
def stop_submission(submission_id, data): # if 'username' not in data or 'password' not in data: # API_LOG.log("Missing parameters in request") # raise ex.BadRequestException() # # username = data['username'] # password = data['password'] # # authorization = authorizer.get_authorization(api.authorization_url, # username, password) authorization = {} authorization['success'] = True if not authorization['success']: API_LOG.log("Unauthorized request") raise ex.UnauthorizedException() else: if submission_id not in submissions.keys(): raise ex.BadRequestException() # TODO: Call the executor by submission_id and stop the execution. return submissions[submission_id]
def run_submission(data): # if ('username' not in data or 'password' not in data or # 'plugin' not in data or 'plugin_info' not in data): # API_LOG.log("Missing parameters in request") # raise ex.BadRequestException() # # username = data['username'] # password = data['password'] # # authorization = authorizer.get_authorization(api.authorization_url, # username, password) authorization = {} authorization['success'] = True if not authorization['success']: API_LOG.log("Unauthorized request") raise ex.UnauthorizedException() else: if data['plugin'] not in api.plugins: raise ex.BadRequestException() plugin = plugin_base.PLUGINS.get_plugin(data['plugin']) submission_id, executor = plugin.execute(data['plugin_info']) submissions[submission_id] = executor return submission_id
def terminate_submission(submission_id, data): if 'username' not in data or 'password' not in data: API_LOG.log("Missing parameters in request") raise ex.BadRequestException() username = data['username'] password = data['password'] authorization = authorizer.get_authorization(api.authorization_url, username, password) if not authorization['success']: API_LOG.log("Unauthorized request") raise ex.UnauthorizedException() else: if submission_id not in submissions.keys(): API_LOG.log("Wrong request") raise ex.BadRequestException() submissions[submission_id].terminate_job()