Example #1
0
    def run_differs(self, image, baseimage):
        self._logger.debug("comparison of " + str(image.meta['imagename']) + " to " + str(image.meta['imagename']) + ": begin")
        shortida = image.meta['shortId']
        shortidb = baseimage.meta['shortId']

        if not image.is_analyzed():
            self._logger.error("cannot compare image " + shortida + " - need to analyze first.")
            return (False)

        if not baseimage.is_analyzed():
            self._logger.error("cannot compare image " + shortidb + " - need to analyze first")
            return (False)

        outputdir = image.anchore_imagedir

        if not self.force and os.path.exists(
                                        outputdir + "/compare_output/" + baseimage.meta['imageId'] + "/differs.done"):
            self._logger.debug("images already compared and --force not specified, nothing to do")
            self._logger.info(shortida + " to " + shortidb + ": compared.")
            return (True)

        self._logger.info(shortida + " to " + shortidb + ": comparing ...")

        if not os.path.exists(outputdir):
            self._logger.debug("output directory '" + str(outputdir) + "' does not exist, creating")
            os.makedirs(outputdir)

        thedir = outputdir + "/compare_output/" + baseimage.meta['imageId'] + "/"
        if not os.path.exists(thedir):
            self._logger.debug("output directory '" + str(thedir) + "' does not exist, creating")
            os.makedirs(thedir)

        compares = anchore_utils.diff_images(image, baseimage)
        for azkey in compares.keys():
            for aokey in compares[azkey].keys():
                outputdict = compares[azkey][aokey]
                thedir = outputdir + "/compare_output/" + baseimage.meta['imageId'] + "/" + azkey + "/"
                if not os.path.exists(thedir):
                    os.makedirs(thedir)
                        
                thefile = thedir + "/" + aokey
                anchore_utils.write_kvfile_fromdict(thefile, outputdict)
                
        self._logger.debug("all comparisons completed")

        anchore_utils.touch_file(outputdir + "/compare_output/" + baseimage.meta['imageId'] + "/differs.done")

        self._logger.info(shortida + " to " + shortidb + ": compared.")

        self._logger.debug("comparison of " + str(image.meta['imagename']) + " to " + str(image.meta['imagename']) + ": end")
        return (True)
Example #2
0
def generate_reports(imagelist, showall=True, showdetails=True):
    ret = {}

    if showdetails:
        header = ['Image_Id', '*Type', 'Current_Tags', 'All_Tags', 'Is_Analyzed', 'Gate_Status', 'Size(bytes)', 'Counts', 'Base_Diffs']
    else:
        header = ['Image_Id', '*Type', 'Tags', 'Is_Analyzed', 'Gate_Status', 'Size(bytes)']

    for imageId in imagelist:
        isanalyzed = str(anchore_utils.is_image_analyzed(imageId))        
        ireport = anchore_utils.load_image_report(imageId)
        if ireport:
            usertype = str(ireport['meta']['usertype'])
            currtags = ','.join(ireport['anchore_current_tags'])
            alltags = ','.join(ireport['anchore_all_tags'])
        else:
            usertype = "None"
            try:
                idocker = contexts['docker_images'][imageId]
                currtags = ','.join(idocker['RepoTags'])
                alltags = currtags
            except:
                currtags = alltags = "N/A"

        if not showall and ((not usertype or usertype.lower() == 'none') and (not currtags and not alltags)):
            continue

        if ireport:
            baseId = str(ireport['familytree'][0])
            sizebytes = str(ireport['meta']['sizebytes'])
            shortId = str(ireport['meta']['shortId'])

        else:
            baseId = "N/A"
            sizebytes = "N/A"
            shortId = imageId[0:12]

        gates_eval_report = anchore_utils.load_gates_eval_report(imageId)
        record = {
            'image_report': ireport,
            'analysis_report': {},
            'gates_report': {},
            'gates_eval_report': gates_eval_report,
            'result': {
                'header':header,
                'rows': list()
            }
        }

        if showdetails: 
            record['analysis_report'] = anchore_utils.load_analysis_report(imageId)
            record['gates_report'] = anchore_utils.load_gates_report(imageId)

        
        gateaction = 'UNKNOWN'
        for g in gates_eval_report:
            if g['trigger'] == 'FINAL':
                gateaction = g['action']
                break

        if showdetails:
            try:
                pnum = str(len(anchore_utils.load_analysis_output(imageId, 'package_list', 'pkgs.all').keys()))
            except:
                pnum = "N/A"
            try:
                fnum = str(len(anchore_utils.load_analysis_output(imageId, 'file_list', 'files.all').keys()))
            except:
                fnum = "N/A"
            try:
                snum = str(len(anchore_utils.load_analysis_output(imageId, 'file_suids', 'files.suids').keys()))
            except:
                snum = "N/A"

            analysis_str = ' '.join(["PKGS="+pnum, "FILES="+fnum, "SUIDFILES="+snum])

            compare_str = "N/A"

            if imageId != baseId:
                diffdata = anchore_utils.diff_images(imageId, baseId)            
                record['base_compare_data'] = diffdata
                pnum = "N/A"
                if 'package_list' in diffdata and 'pkgs.all' in diffdata['package_list']:
                    for module_type in diffdata['package_list']['pkgs.all']:
                        pnum = str(len(diffdata['package_list']['pkgs.all'][module_type]))
                        break

                fnum = "N/A"
                if 'file_list' in diffdata and 'files.all' in diffdata['file_list']:
                    for module_type in diffdata['file_list']['files.all']:
                        fnum = str(len(diffdata['file_list']['files.all'][module_type]))

                snum = "N/A"
                if 'file_suids' in diffdata and 'files.suids' in diffdata['file_suids']:
                    for module_type in diffdata['file_suids']['files.suids']:
                        snum = str(len(diffdata['file_suids']['files.suids'][module_type]))

                compare_str = ' '.join(["PKGS="+pnum, "FILES="+fnum, "SUIDFILES="+snum])

            row = [ shortId, usertype, currtags, alltags, isanalyzed, gateaction, sizebytes, analysis_str, compare_str ]
        else:
            row = [ shortId, usertype, currtags, isanalyzed, gateaction, sizebytes]

        record['result']['rows'].append(row)

        ret[imageId] = record

    return ret
Example #3
0
    def generate_reports(self):
        ret = {}
        for imageId in self.images:
            image = self.allimages[imageId]
            baseId = image.get_earliest_base()
            bimage = self.allimages[baseId]
            sizebytes = image.meta['sizebytes']

            image_report = image.get_image_report()
            analysis_report = image.get_analysis_report()
            gates_report = image.get_gates_report()
            gates_eval_report = image.get_gates_eval_report()

            record = {
                'image_report': image_report,
                'analysis_report': analysis_report,
                'gates_report': gates_report,
                'gates_eval_report': gates_eval_report,
                'result': {
                    'header': [
                        'Image_Id', 'Type', 'Current_Tags', 'All_Tags',
                        'Gate_Status', 'Size(bytes)', 'Counts', 'Base_Diffs'
                    ],
                    'rows':
                    list()
                }
            }

            shortId = image.meta['shortId']
            usertype = str(image.get_usertype())
            currtags = ','.join(image.get_alltags_current())
            alltags = ','.join(image.get_alltags_ever())

            gateaction = 'UNKNOWN'
            for g in gates_eval_report:
                if g['trigger'] == 'FINAL':
                    gateaction = g['action']
                    break

            try:
                pnum = str(
                    len(
                        anchore_utils.load_analysis_output(
                            image.meta['imageId'], 'package_list',
                            'pkgs.all').keys()))
            except:
                pnum = "N/A"
            try:
                fnum = str(
                    len(
                        anchore_utils.load_analysis_output(
                            image.meta['imageId'], 'file_list',
                            'files.all').keys()))
            except:
                fnum = "N/A"
            try:
                snum = str(
                    len(
                        anchore_utils.load_analysis_output(
                            image.meta['imageId'], 'file_suids',
                            'files.suids').keys()))
            except:
                fnum = "N/A"

            analysis_str = ' '.join(
                ["PKGS=" + pnum, "FILES=" + fnum, "SUIDFILES=" + snum])

            compare_str = "N/A"

            if image.meta['imageId'] != baseId:
                diffdata = anchore_utils.diff_images(image.meta['imageId'],
                                                     baseId)
                record['base_compare_data'] = diffdata
                pnum = "N/A"
                if 'package_list' in diffdata and 'pkgs.all' in diffdata[
                        'package_list']:
                    for module_type in diffdata['package_list']['pkgs.all']:
                        pnum = str(
                            len(diffdata['package_list']['pkgs.all']
                                [module_type]))
                        break

                fnum = "N/A"
                if 'file_list' in diffdata and 'files.all' in diffdata[
                        'file_list']:
                    for module_type in diffdata['file_list']['files.all']:
                        fnum = str(
                            len(diffdata['file_list']['files.all']
                                [module_type]))

                snum = "N/A"
                if 'file_suids' in diffdata and 'files.suids' in diffdata[
                        'file_suids']:
                    for module_type in diffdata['file_suids']['files.suids']:
                        snum = str(
                            len(diffdata['file_suids']['files.suids']
                                [module_type]))

                compare_str = ' '.join(
                    ["PKGS=" + pnum, "FILES=" + fnum, "SUIDFILES=" + snum])

            row = [
                shortId, usertype, currtags, alltags, gateaction, sizebytes,
                analysis_str, compare_str
            ]

            record['result']['rows'].append(row)

            ret[imageId] = record
        return ret
Example #4
0
def generate_reports(imagelist, showall=True, showdetails=True):
    ret = {}

    if showdetails:
        header = [
            'Image_Id', '*Type', 'Current_Tags', 'All_Tags', 'Is_Analyzed',
            'Gate_Status', 'Size(bytes)', 'Counts', 'Base_Diffs'
        ]
    else:
        header = [
            'Image_Id', '*Type', 'Tags', 'Is_Analyzed', 'Gate_Status',
            'Size(bytes)'
        ]

    for imageId in imagelist:
        isanalyzed = str(anchore_utils.is_image_analyzed(imageId))
        ireport = anchore_utils.load_image_report(imageId)
        if ireport:
            usertype = str(ireport['meta']['usertype'])
            currtags = ','.join(ireport['anchore_current_tags'])
            alltags = ','.join(ireport['anchore_all_tags'])
        else:
            usertype = "None"
            try:
                idocker = contexts['docker_images'][imageId]
                currtags = ','.join(idocker['RepoTags'])
                alltags = currtags
            except:
                currtags = alltags = "N/A"

        if not showall and ((not usertype or usertype.lower() == 'none') and
                            (not currtags and not alltags)):
            continue

        if ireport:
            baseId = str(ireport['familytree'][0])
            sizebytes = str(ireport['meta']['sizebytes'])
            shortId = str(ireport['meta']['shortId'])

        else:
            baseId = "N/A"
            sizebytes = "N/A"
            shortId = imageId[0:12]

        gates_eval_report = anchore_utils.load_gates_eval_report(imageId)
        record = {
            'image_report': ireport,
            'analysis_report': {},
            'gates_report': {},
            'gates_eval_report': gates_eval_report,
            'result': {
                'header': header,
                'rows': list()
            }
        }

        if showdetails:
            record['analysis_report'] = anchore_utils.load_analysis_report(
                imageId)
            record['gates_report'] = anchore_utils.load_gates_report(imageId)

        gateaction = 'UNKNOWN'
        for g in gates_eval_report:
            if g['trigger'] == 'FINAL':
                gateaction = g['action']
                break

        if showdetails:
            try:
                pnum = str(
                    len(
                        anchore_utils.load_analysis_output(
                            imageId, 'package_list', 'pkgs.all').keys()))
            except:
                pnum = "N/A"
            try:
                fnum = str(
                    len(
                        anchore_utils.load_analysis_output(
                            imageId, 'file_list', 'files.all').keys()))
            except:
                fnum = "N/A"
            try:
                snum = str(
                    len(
                        anchore_utils.load_analysis_output(
                            imageId, 'file_suids', 'files.suids').keys()))
            except:
                snum = "N/A"

            analysis_str = ' '.join(
                ["PKGS=" + pnum, "FILES=" + fnum, "SUIDFILES=" + snum])

            compare_str = "N/A"

            if imageId != baseId:
                diffdata = anchore_utils.diff_images(imageId, baseId)
                record['base_compare_data'] = diffdata
                pnum = "N/A"
                if 'package_list' in diffdata and 'pkgs.all' in diffdata[
                        'package_list']:
                    for module_type in diffdata['package_list']['pkgs.all']:
                        pnum = str(
                            len(diffdata['package_list']['pkgs.all']
                                [module_type]))
                        break

                fnum = "N/A"
                if 'file_list' in diffdata and 'files.all' in diffdata[
                        'file_list']:
                    for module_type in diffdata['file_list']['files.all']:
                        fnum = str(
                            len(diffdata['file_list']['files.all']
                                [module_type]))

                snum = "N/A"
                if 'file_suids' in diffdata and 'files.suids' in diffdata[
                        'file_suids']:
                    for module_type in diffdata['file_suids']['files.suids']:
                        snum = str(
                            len(diffdata['file_suids']['files.suids']
                                [module_type]))

                compare_str = ' '.join(
                    ["PKGS=" + pnum, "FILES=" + fnum, "SUIDFILES=" + snum])

            row = [
                shortId, usertype, currtags, alltags, isanalyzed, gateaction,
                sizebytes, analysis_str, compare_str
            ]
        else:
            row = [
                shortId, usertype, currtags, isanalyzed, gateaction, sizebytes
            ]

        record['result']['rows'].append(row)

        ret[imageId] = record

    return ret
Example #5
0
    def generate_reports(self):
        ret = {}
        for imageId in self.images:
            image = self.allimages[imageId]
            baseId = image.get_earliest_base()
            bimage = self.allimages[baseId]
            sizebytes = image.meta['sizebytes']

            image_report = image.get_image_report()
            analysis_report = image.get_analysis_report()
            gates_report = image.get_gates_report()
            gates_eval_report = image.get_gates_eval_report()

            record = {
                'image_report': image_report,
                'analysis_report': analysis_report,
                'gates_report': gates_report,
                'gates_eval_report': gates_eval_report,
                'result': {
                    'header':['Image_Id', 'Type', 'Current_Tags', 'All_Tags', 'Gate_Status', 'Size(bytes)', 'Counts', 'Base_Diffs'],
                    'rows': list()
                }
            }

            shortId = image.meta['shortId']
            usertype = str(image.get_usertype())
            currtags = ','.join(image.get_alltags_current())
            alltags = ','.join(image.get_alltags_ever())

            gateaction = 'UNKNOWN'
            for g in gates_eval_report:
                if g['trigger'] == 'FINAL':
                    gateaction = g['action']
                    break

            try:
                pnum = str(len(anchore_utils.load_analysis_output(image.meta['imageId'], 'package_list', 'pkgs.all').keys()))
            except:
                pnum = "N/A"
            try:
                fnum = str(len(anchore_utils.load_analysis_output(image.meta['imageId'], 'file_list', 'files.all').keys()))
            except:
                fnum = "N/A"
            try:
                snum = str(len(anchore_utils.load_analysis_output(image.meta['imageId'], 'file_suids', 'files.suids').keys()))
            except:
                fnum = "N/A"

            analysis_str = ' '.join(["PKGS="+pnum, "FILES="+fnum, "SUIDFILES="+snum])

            compare_str = "N/A"

            if image.meta['imageId'] != baseId:
                diffdata = anchore_utils.diff_images(image.meta['imageId'], baseId)            
                record['base_compare_data'] = diffdata
                pnum = "N/A"
                if 'package_list' in diffdata and 'pkgs.all' in diffdata['package_list']:
                    for module_type in diffdata['package_list']['pkgs.all']:
                        pnum = str(len(diffdata['package_list']['pkgs.all'][module_type]))
                        break

                fnum = "N/A"
                if 'file_list' in diffdata and 'files.all' in diffdata['file_list']:
                    for module_type in diffdata['file_list']['files.all']:
                        fnum = str(len(diffdata['file_list']['files.all'][module_type]))

                snum = "N/A"
                if 'file_suids' in diffdata and 'files.suids' in diffdata['file_suids']:
                    for module_type in diffdata['file_suids']['files.suids']:
                        snum = str(len(diffdata['file_suids']['files.suids'][module_type]))

                compare_str = ' '.join(["PKGS="+pnum, "FILES="+fnum, "SUIDFILES="+snum])

            row = [ shortId, usertype, currtags, alltags, gateaction, sizebytes, analysis_str, compare_str ]

            record['result']['rows'].append(row)

            ret[imageId] = record
        return ret
Example #6
0
    def run_differs(self, image, baseimage):
        self._logger.debug("comparison of " + str(image.meta['imagename']) +
                           " to " + str(image.meta['imagename']) + ": begin")
        shortida = image.meta['shortId']
        shortidb = baseimage.meta['shortId']

        if not image.is_analyzed():
            self._logger.error("cannot compare image " + shortida +
                               " - need to analyze first.")
            return (False)

        if not baseimage.is_analyzed():
            self._logger.error("cannot compare image " + shortidb +
                               " - need to analyze first")
            return (False)

        outputdir = image.anchore_imagedir

        if not self.force and os.path.exists(outputdir + "/compare_output/" +
                                             baseimage.meta['imageId'] +
                                             "/differs.done"):
            self._logger.debug(
                "images already compared and --force not specified, nothing to do"
            )
            self._logger.info(shortida + " to " + shortidb + ": compared.")
            return (True)

        self._logger.info(shortida + " to " + shortidb + ": comparing ...")

        if not os.path.exists(outputdir):
            self._logger.debug("output directory '" + str(outputdir) +
                               "' does not exist, creating")
            os.makedirs(outputdir)

        thedir = outputdir + "/compare_output/" + baseimage.meta[
            'imageId'] + "/"
        if not os.path.exists(thedir):
            self._logger.debug("output directory '" + str(thedir) +
                               "' does not exist, creating")
            os.makedirs(thedir)

        compares = anchore_utils.diff_images(image, baseimage)
        for azkey in compares.keys():
            for aokey in compares[azkey].keys():
                outputdict = compares[azkey][aokey]
                thedir = outputdir + "/compare_output/" + baseimage.meta[
                    'imageId'] + "/" + azkey + "/"
                if not os.path.exists(thedir):
                    os.makedirs(thedir)

                thefile = thedir + "/" + aokey
                anchore_utils.write_kvfile_fromdict(thefile, outputdict)

        self._logger.debug("all comparisons completed")

        anchore_utils.touch_file(outputdir + "/compare_output/" +
                                 baseimage.meta['imageId'] + "/differs.done")

        self._logger.info(shortida + " to " + shortidb + ": compared.")

        self._logger.debug("comparison of " + str(image.meta['imagename']) +
                           " to " + str(image.meta['imagename']) + ": end")
        return (True)