Пример #1
0
def _check_feed_client_credentials():
    from anchore_engine.clients.feeds.feed_service import get_client
    sleep_time = feed_config_check_backoff
    last_ex = None

    for i in range(feed_config_check_retries):
        if i > 0:
            logger.info(
                "Waiting for {} seconds to try feeds client config check again"
                .format(sleep_time))
            time.sleep(sleep_time)
            sleep_time += feed_config_check_backoff

        try:
            logger.info(
                'Checking feeds client credentials. Attempt {} of {}'.format(
                    i + 1, feed_config_check_retries))
            client = get_client()
            client = None
            logger.info('Feeds client credentials ok')
            return True
        except Exception as e:
            logger.warn(
                "Could not verify feeds endpoint and/or config. Got exception: {}"
                .format(e))
            last_ex = e
    else:
        if last_ex:
            raise last_ex
        else:
            raise Exception(
                'Exceeded retries for feeds client config check. Failing check'
            )
def test_feed_sync():
    test_client = get_client(feeds_url=feed_url,
                             token_url=token_url,
                             client_url=client_url,
                             user=('*****@*****.**', 'pbiU2RYZ2XrmYQ'),
                             conn_timeout=3,
                             read_timeout=10)
    for f in test_client.list_feeds().feeds:
        try:
            test_client.list_feed_groups(f.name)
        except Exception as e:
            logger.info(('Caught: {} for feed:  {}'.format(e, f)))


    next_token = False
    since_time = datetime.datetime.utcnow() - datetime.timedelta(days=2)
    since_time = None
    while next_token is not None:
        logger.info('Getting a page of data')
        if next_token:
            last_token = next_token
            logger.info(('Using token: {}'.format(next_token)))
            data = test_client.get_feed_group_data('vulnerabilities', 'alpine:3.6', since=since_time, next_token=next_token)
            next_token = data.next_token
            logger.info(('Got {} items and new next token: {}'.format(len(data.data), next_token)))
        else:
            last_token = None
            data = test_client.get_feed_group_data('vulnerabilities', 'alpine:3.6', since=since_time)
            next_token = data.next_token
            logger.info(('Got {} items and new next token: {}'.format(len(data.data), next_token)))

        if next_token:
            assert(next_token != last_token)
        assert(len(data.data) > 0)
def test_auth_error():
    with pytest.raises(InvalidCredentialsError):
        test_client = get_client(feeds_url=feed_url,
                                 token_url=token_url,
                                 client_url=client_url,
                                 user=('*****@*****.**', 'foobar'),
                                 conn_timeout=3,
                                 read_timeout=10)
        f = test_client.list_feeds()
def test_anon_user():
    test_client = get_client(feeds_url=feed_url,
                             token_url=token_url,
                             client_url=client_url,
                             user=('*****@*****.**', 'pbiU2RYZ2XrmYQ'),
                             conn_timeout=3,
                             read_timeout=10)
    for f in test_client.list_feeds().feeds:
        try:
            test_client.list_feed_groups(f.name)
        except Exception as e:
            logger.error(('Caught: {} for feed:  {}'.format(e, f)))
    test_client.get_feed_group_data('vulnerabilities', 'alpine:3.6',since=datetime.datetime.utcnow())
Пример #5
0
def _check_feed_client_credentials():
    from anchore_engine.clients.feeds.feed_service import get_client
    logger.info('Checking feeds client credentials')
    client = get_client()
    client = None
    logger.info('Feeds client credentials ok')