def create_feed_update(notification): """ Creates a feed data update notification. :param notification: :return: """ if not connexion.request.is_json: abort(400) notification = FeedUpdateNotification.from_dict(notification) result = [] try: feeds = get_selected_feeds_to_sync(localconfig.get_config()) task = FeedsUpdateTask(feeds_to_sync=feeds) result = task.execute() except HTTPException: raise except Exception as e: log.exception('Error executing feed update task') abort( Response(status=500, response=json.dumps({ 'error': 'feed sync failure', 'details': 'Failure syncing feed: {}'.format(e.message) }), mimetype='application/json')) return jsonify(['{}/{}'.format(x[0], x[1]) for x in result]), 200
def cls_fully_loaded_test_env(cls_test_data_env2, request): """ Load the test env, including a feed sync and image analysis. Places the env in the class's test_env and test_image vars :param cls_test_data_env: :param request: :return: """ _init_distro_mappings() from anchore_engine.services.policy_engine.engine.tasks import FeedsUpdateTask t = FeedsUpdateTask(feeds_to_sync=[ 'vulnerabilities', 'packages', 'nvdv2', 'nvd', 'vulndb' ]) t.execute() for image_id, path in request.cls.test_env.image_exports(): logger.info(('Ensuring loaded: image id: {} from file: {}'.format( image_id, path))) t = ImageLoadTask(image_id=image_id, user_id='0', url='file://' + path) t.execute() db = get_thread_scoped_session() test_image = db.query(Image).get((request.cls.test_env.get_images_named( request.cls.__default_image__)[0][0], '0')) request.cls.test_image = test_image db.rollback()
def test_feed_task(test_data_env, anchore_db): logger.info('Running a feed sync with config: {}'.format(localconfig.get_config())) t = FeedsUpdateTask() t.execute() with session_scope() as db: feeds = db.query(FeedMetadata).all() logger.info('{}'.format(feeds)) assert len(feeds) == 4 # packages, vulns, snyk, nvd feed_groups = db.query(FeedGroupMetadata).all() # See the test/data/test_data_env/feeds dir for the proper count here logger.info('{}'.format(feed_groups)) assert len(feed_groups) == 11 # ToDo: set the source data to a small number and make this an exact count assert db.query(Vulnerability).count() > 0 assert db.query(NpmMetadata).count() > 0 assert db.query(GemMetadata).count() > 0 assert db.query(NvdMetadata).count() == 0
def testFeedLoader(self): t = FeedsUpdateTask() t.execute()