def get_issues(): from_time = request.args.get("start_time") to_time = request.args.get("end_time") start = int(request.args.get("from", 0)) end = int(request.args.get("size", 100)) start_time = int(arrow.get(from_time).float_timestamp * 1000) end_time = int(arrow.get(to_time).float_timestamp * 1000) false_positive = request.args.get("false_positive", "false") sort_order = ElasticSearchHelpers.create_sort(True) time_filter = ElasticSearchHelpers.create_timestamp_filter( start_time, end_time) query_filter = ElasticSearchHelpers.create_query_string_filter( "false_positive:" + false_positive) try: query = ElasticSearchHelpers.create_elasticsearch_filtered_query( filtered_query=query_filter, timestamp_filter=time_filter, sort_order=sort_order) datastore = get_data_store() params = dict(from_=start) params["size"] = end results = datastore.search(query=query, params=params) issues = make_issues_object(results["hits"]["hits"], results["hits"]["total"]) response = make_response(json.dumps(issues)) response.headers["Content-Type"] = "application/json" return response except DataStoreException: return "Failed to retrieve issues", 500
def get_issues(): from_time = request.args.get("start_time") to_time = request.args.get("end_time") start = int(request.args.get("from", 0)) end = int(request.args.get("size", 100)) start_time = int(arrow.get(from_time).float_timestamp * 1000) end_time = int(arrow.get(to_time).float_timestamp * 1000) false_positive = request.args.get("false_positive", "false") sort_order = ElasticSearchHelpers.create_sort(True) time_filter = ElasticSearchHelpers.create_timestamp_filter(start_time, end_time) query_filter = ElasticSearchHelpers.create_query_string_filter("false_positive:" + false_positive) try: query = ElasticSearchHelpers.create_elasticsearch_filtered_query(filtered_query=query_filter, timestamp_filter=time_filter, sort_order=sort_order) datastore = get_data_store() params = dict(from_=start) params["size"] = end results = datastore.search(query=query, params=params) issues = make_issues_object(results["hits"]["hits"], results["hits"]["total"]) response = make_response(json.dumps(issues)) response.headers["Content-Type"] = "application/json" return response except DataStoreException: return "Failed to retrieve issues", 500
def filter_by_rule(): from_time = request.args.get("start_time", arrow.utcnow().replace(days=-7)) to_time = request.args.get("end_time", arrow.utcnow()) start = int(request.args.get("from", 0)) end = int(request.args.get("size", 100)) start_time = int(arrow.get(from_time).float_timestamp * 1000) end_time = int(arrow.get(to_time).float_timestamp * 1000) false_positive = request.args.get("false_positive", "false") sort_order = ElasticSearchHelpers.create_sort(True) time_filter = ElasticSearchHelpers.create_timestamp_filter(start_time, end_time) query_filter = ElasticSearchHelpers.create_query_string_filter("false_positive:" + false_positive) try: query = ElasticSearchHelpers.create_elasticsearch_filtered_query(filtered_query=query_filter, timestamp_filter=time_filter, sort_order=sort_order) datastore = get_data_store() params = dict(from_=start) params["size"] = end params["_source"] = "check_id" results = datastore.search(query=query, params=params) rules = set() for result in results["hits"]["hits"]: rule = result["_source"]["check_id"] rules .add(rule) # sets are not JSON serializable response = make_response(json.dumps(list(rules))) response.headers["Content-Type"] = "application/json" return response except DataStoreException: return "Failed to retrieve commits", 500
def filter_by_reviewer(): from_time = request.args.get("start_time", arrow.utcnow().replace(days=-7)) to_time = request.args.get("end_time", arrow.utcnow()) start = int(request.args.get("from", 0)) end = int(request.args.get("size", 100)) start_time = int(arrow.get(from_time).float_timestamp * 1000) end_time = int(arrow.get(to_time).float_timestamp * 1000) false_positive = request.args.get("false_positive", "false") sort_order = ElasticSearchHelpers.create_sort(True) time_filter = ElasticSearchHelpers.create_timestamp_filter( start_time, end_time) query_filter = ElasticSearchHelpers.create_query_string_filter( "false_positive:" + false_positive) try: query = ElasticSearchHelpers.create_elasticsearch_filtered_query( filtered_query=query_filter, timestamp_filter=time_filter, sort_order=sort_order) datastore = get_data_store() params = dict(from_=start) params["size"] = end params["_source"] = "last_reviewer" results = datastore.search(query=query, params=params) reviewers = set() for result in results["hits"]["hits"]: reviewers.add(result["_source"]["last_reviewer"]) # sets are not JSON serializable response = make_response(json.dumps(list(reviewers))) response.headers["Content-Type"] = "application/json" return response except DataStoreException: return "Failed to retrieve commits", 500
def filter_by_repo(): try: query = ElasticSearchHelpers.create_elasticsearch_aggregate_query("repo_name") datastore = get_data_store() results = datastore.search(query=query) repos = set() for result in results["aggregations"]["my_aggregation"]["buckets"]: repo = result["key"] repos.add(repo) # sets are not JSON serializable response = make_response(json.dumps(list(repos))) response.headers["Content-Type"] = "application/json" return response except DataStoreException: return "Failed to retrieve commits", 500
def get_issues_by_reviewer(reviewer): start = int(request.args.get("from", 0)) end = int(request.args.get("size", 100)) query = ElasticSearchHelpers.create_elasticsearch_simple_query(search_parameter="last_reviewer", search_string=urllib.quote_plus(reviewer)) query["from_"] = start query["size"] = end try: datastore = get_data_store() results = datastore.search(params=query) issues = make_issues_object(results["hits"]["hits"], results["hits"]["total"]) response = make_response(json.dumps(issues)) response.headers["Content-Type"] = "application/json" return response except DataStoreException: return "Failed to retrieve issues by reviewer", 500
def update_issue_state(issue_id): if "status" in request.form and "current_user" in request.form: changed_status = request.form["status"] current_user = request.form["current_user"] else: return "Changed Status Value Required.", 400 doc = ElasticSearchHelpers.create_elasticsearch_doc({"false_positive": changed_status, "last_reviewer": current_user}) try: datastore = get_data_store() datastore.update(index_id=issue_id, doc=doc) response = make_response("Completed") return response except DataStore, e: return "Failed to update issue status", 500
def filter_by_repo(): try: query = ElasticSearchHelpers.create_elasticsearch_aggregate_query( "repo_name") datastore = get_data_store() results = datastore.search(query=query) repos = set() for result in results["aggregations"]["my_aggregation"]["buckets"]: repo = result["key"] repos.add(repo) # sets are not JSON serializable response = make_response(json.dumps(list(repos))) response.headers["Content-Type"] = "application/json" return response except DataStoreException: return "Failed to retrieve commits", 500
def get_issues_by_rule(check_id): start = int(request.args.get("from", 0)) end = int(request.args.get("size", 100)) query = ElasticSearchHelpers.create_elasticsearch_simple_query( search_parameter="check_id", search_string=urllib.quote_plus(check_id)) query["from_"] = start query["size"] = end try: datastore = get_data_store() results = datastore.search(params=query) issues = make_issues_object(results["hits"]["hits"], results["hits"]["total"]) response = make_response(json.dumps(issues)) response.headers["Content-Type"] = "application/json" return response except DataStoreException: return "Failed to retrieve issues by rule", 500
def update_issue_state(issue_id): if "status" in request.form and "current_user" in request.form: changed_status = request.form["status"] current_user = request.form["current_user"] else: return "Changed Status Value Required.", 400 doc = ElasticSearchHelpers.create_elasticsearch_doc({ "false_positive": changed_status, "last_reviewer": current_user }) try: datastore = get_data_store() datastore.update(index_id=issue_id, doc=doc) response = make_response("Completed") return response except DataStore, e: return "Failed to update issue status", 500