예제 #1
0
def vulnerabilities_for_image(image_obj):
    """
    Return the list of vulnerabilities for the specified image id by recalculating the matches for the image. Ignores
    any persisted matches. Query only, does not update the data. Caller must add returned results to a db session and commit
    in order to persist.

    :param image_obj: the image
    :return: list of ImagePackageVulnerability records for the packages in the given image
    """

    # Recompute. Session and persistence in the session is up to the caller
    try:
        ts = time.time()
        computed_vulnerabilties = []
        for package in image_obj.packages:
            pkg_vulnerabilities = package.vulnerabilities_for_package()
            for v in pkg_vulnerabilities:
                img_v = ImagePackageVulnerability()
                img_v.pkg_image_id = image_obj.id
                img_v.pkg_user_id = image_obj.user_id
                img_v.pkg_name = package.name
                img_v.pkg_type = package.pkg_type
                img_v.pkg_arch = package.arch
                img_v.pkg_version = package.version
                img_v.pkg_path = package.pkg_path
                img_v.vulnerability_id = v.vulnerability_id
                img_v.vulnerability_namespace_name = v.namespace_name
                computed_vulnerabilties.append(img_v)
        #log.debug("TIMER VULNERABILITIES: {}".format(time.time() - ts))

        return computed_vulnerabilties
    except Exception as e:
        log.exception('Error computing full vulnerability set for image {}/{}'.format(image_obj.user_id, image_obj.id))
        raise
예제 #2
0
def test_cmp():
    c1 = ImagePackageVulnerability()
    c1.pkg_name = "testpkg1"
    c1.pkg_version = "1.0"
    c1.pkg_arch = "x86"
    c1.pkg_type = "rpm"
    c1.pkg_image_id = "image123"
    c1.pkg_user_id = "0"
    c1.vulnerability_namespace_name = "centos:6"
    c1.vulnerability_id = "CVE-2016-123"
    c1.created_at = datetime.datetime.utcnow()

    c2 = copy.deepcopy(c1)
    assert c1 == c2
    c3 = copy.deepcopy(c1)
    assert c1 == c3
    c4 = copy.deepcopy(c1)
    assert c1 == c4

    c3.pkg_version = "1.1"
    c4.pkg_user_id = "1"

    assert c1 == c2
    assert c1 != c4
    assert c1 != c3
    assert list({c1, c2, c3}) == list({c1, c3})

    logger.info("Set: {}".format({c1, c2, c3}))
예제 #3
0
    def test_cmp(self):
        c1 = ImagePackageVulnerability()
        c1.pkg_name = 'testpkg1'
        c1.pkg_version = '1.0'
        c1.pkg_arch = 'x86'
        c1.pkg_type = 'rpm'
        c1.pkg_image_id = 'image123'
        c1.pkg_user_id = '0'
        c1.vulnerability_namespace_name = 'centos:6'
        c1.vulnerability_id = 'CVE-2016-123'
        c1.created_at = datetime.datetime.utcnow()

        c2 = copy.deepcopy(c1)
        self.assertEqual(c1, c2)
        c3 = copy.deepcopy(c1)
        self.assertEqual(c1, c3)
        c4 = copy.deepcopy(c1)
        self.assertEqual(c1, c4)

        c3.pkg_version = '1.1'
        c4.pkg_user_id = '1'

        self.assertEqual(c1, c2)
        self.assertNotEqual(c1, c4)
        self.assertNotEqual(c1, c3)
        self.assertListEqual(list({c1, c2, c3}), list({c1, c3}))

        print('Set: {}'.format({c1, c2, c3}))
예제 #4
0
def test_cmp():
    c1 = ImagePackageVulnerability()
    c1.pkg_name = 'testpkg1'
    c1.pkg_version = '1.0'
    c1.pkg_arch = 'x86'
    c1.pkg_type = 'rpm'
    c1.pkg_image_id = 'image123'
    c1.pkg_user_id = '0'
    c1.vulnerability_namespace_name = 'centos:6'
    c1.vulnerability_id = 'CVE-2016-123'
    c1.created_at = datetime.datetime.utcnow()

    c2 = copy.deepcopy(c1)
    assert c1 == c2
    c3 = copy.deepcopy(c1)
    assert c1 == c3
    c4 = copy.deepcopy(c1)
    assert c1 == c4

    c3.pkg_version = '1.1'
    c4.pkg_user_id = '1'

    assert c1 == c2
    assert c1 != c4
    assert c1 != c3
    assert list({c1, c2, c3}) == list({c1, c3})

    logger.info('Set: {}'.format({c1, c2, c3}))