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 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
def register(): input_json = request.get_json() if not 'github_repo' in input_json: return flask.jsonify( {'error': '"github_repo" is a required parameter'}), 400 if not 'github_sha' in input_json: return flask.jsonify({'error': '"github_sha" is a required parameter'}), 400 if not 'email_ids' in input_json: return flask.jsonify({'error': '"email_ids" is a required parameter'}), 400 status = persist_repo_in_db(input_json) if status is not True: return flask.jsonify({ 'error': 'New repo registration failed as {}'.format( status.get('message', 'undefined')) }), 500 status = scan_repo(input_json) if status is not True: return flask.jsonify({ 'error': 'New repo scan initialization failed as {}'.format( status.get('message', 'undefined')) }), 500 return flask.jsonify({ 'message': '{} successfully registered'.format(input_json['github_repo']) }), 200
def register(): """ Endpoint for registering a new repository. Registers new information and updates existing repo information. """ resp_dict = {"success": True, "summary": ""} input_json = request.get_json() if request.content_type != 'application/json': resp_dict["success"] = False resp_dict["summary"] = "Set content type to application/json" return flask.jsonify(resp_dict), 400 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: repo_info = DatabaseIngestion.get_info(input_json.get('git-url')) if repo_info.get('is_valid'): data = repo_info.get('data') # Update the record to reflect new git_sha if any. DatabaseIngestion.update_data(input_json) else: try: # First time ingestion DatabaseIngestion.store_record(input_json) status = scan_repo(input_json) if status is not True: resp_dict["success"] = False resp_dict[ "summary"] = "New Repo Scan Initialization Failure" return flask.jsonify(resp_dict), 500 resp_dict["summary"] = "Repository {} with commit-hash {} " \ "has been successfully registered. " \ "Please check back for report after some time." \ .format(input_json.get('git-url'), input_json.get('git-sha')) return flask.jsonify(resp_dict), 200 except Exception as e: resp_dict["success"] = False resp_dict["summary"] = "Database Ingestion Failure due to: {}" \ .format(e) return flask.jsonify(resp_dict), 500 except Exception as e: resp_dict["success"] = False resp_dict["summary"] = "Cannot get information about repository {} " \ "due to {}" \ .format(input_json.get('git-url'), e) return flask.jsonify(resp_dict), 500 # Scan the repository irrespective of report is available or not. status = scan_repo(input_json) if status is not True: resp_dict["success"] = False resp_dict["summary"] = "New Repo Scan Initialization Failure" return flask.jsonify(resp_dict), 500 resp_dict.update({ "summary": "Repository {} was already registered, but no report for " "commit-hash {} was found. Please check back later.".format( input_json.get('git-url'), input_json.get('git-sha')), "last_scanned_at": data['last_scanned_at'], "last_scan_report": None }) return flask.jsonify(resp_dict), 200