def report(): """Endpoint for fetching generated scan report.""" repo = request.args.get('git-url') sha = request.args.get('git-sha') response = dict() result = retrieve_worker_result(sha, "ReportGenerationTask") if result: task_result = result.get('task_result') if task_result: response.update({ "git_url": repo, "git_sha": sha, "scanned_at": task_result.get("scanned_at"), "dependencies": task_result.get("dependencies") }) return flask.jsonify(response), 200 else: response.update({ "status": "failure", "message": "Failed to retrieve scan report" }) return flask.jsonify(response), 404 else: response.update({ "status": "failure", "message": "No report found for this repository" }) return flask.jsonify(response), 404
def report(repo): """Endpoint for fetching generated scan report.""" repo_info = DatabaseIngestion.get_info(repo) response = dict() if repo_info.get('is_valid'): git_sha = repo_info.get('data', {}).get('git_sha') result = retrieve_worker_result(git_sha, "ReportGenerationTask") if result: response.update({"status": "success", "result": result}) return flask.jsonify(response), 200 else: response.update({ "status": "failure", "message": "No report found for this repository" }) return flask.jsonify(response), 404 else: response.update({ "status": "failure", "message": "No registered repository found" }) return flask.jsonify(response), 404
def register(): """ Endpoint for registering a new repositor. Registers new information and updates existing repo information. """ resp_dict = { "data": [], "success": True, "summary": "{} successfully registered" } input_json = request.get_json() validated_data = validate_request_data(input_json) if not validated_data[0]: resp_dict["success"] = False resp_dict["summary"] = validated_data[1] return flask.jsonify(resp_dict), 404 try: status = DatabaseIngestion.store_record(input_json) resp_dict["data"] = status except Exception as e: resp_dict["success"] = False resp_dict["summary"] = "Database Ingestion Failure due to" + e return flask.jsonify(resp_dict), 500 worker_result = retrieve_worker_result(input_json.get('git_sha'), "ReportGenerationTask") if worker_result: status = True else: status = scan_repo(input_json) if status is not True: resp_dict["success"] = False resp_dict["summary"] = "New Repo Scan Initializtion Failure" return flask.jsonify(resp_dict), 500 rep_summary = resp_dict["summary"].format(input_json['git_url']) resp_dict["summary"] = rep_summary return flask.jsonify(resp_dict), 200