コード例 #1
0
 def create_pv_nodes(self):
     """Create Package and Version nodes, if needed."""
     for pv_dict in self._cve_dict.get('affected'):
         epv_dict = pv_dict.copy()
         epv_dict['ecosystem'] = self._cve_dict.get('ecosystem')
         query = GraphPopulator.construct_graph_nodes(epv_dict)
         success, json_response = BayesianGraph.execute(query)
         e = epv_dict.get('ecosystem')
         p = epv_dict.get('name')
         v = epv_dict.get('version')
         if not success:
             logger.error('Error creating nodes for {e}/{p}/{v}: {r}'.format(
                 e=e, p=p, v=v, r=str(json_response))
             )
コード例 #2
0
def create_graph_nodes(list_epv):
    """Create blank graph nodes given an EPV."""
    count_blank_epvs_created = 0
    success_epvs = []
    failure_epvs = []

    for item in list_epv:
        str_gremlin = GraphPopulator.construct_graph_nodes(item)
        epv = item.get('ecosystem') + ":" + item.get('name') + ":" + item.get(
            'version')

        if str_gremlin:
            payload = {'gremlin': str_gremlin}
            print(json.dumps(payload))
            try:
                result = requests.post(config.GREMLIN_SERVER_URL_REST,
                                       data=json.dumps(payload),
                                       timeout=30)
                resp = result.json()
                print(json.dumps(resp))

                if resp['status']['code'] == 200:
                    count_blank_epvs_created += 1
                    success_epvs.append(epv)
            except Exception as e:  # pragma: no cover
                logger.error(e)
                failure_json = {epv: e}
                failure_epvs.append(failure_json)

    status = "Success"
    if count_blank_epvs_created == 0:
        status = "Failure"

    response = {
        "epv_nodes_created": count_blank_epvs_created,
        "success_list": success_epvs,
        "failure_list": failure_epvs,
        "status": status
    }
    return response