How to use the anchorecli.clients.apiexternal.get_image function in anchorecli

To help you get started, we’ve selected a few anchorecli examples, based on popular ways it is used in public projects.

Secure your code as it's written. Use Snyk Code to scan source code in minutes - no build needed - and fix issues immediately.

github anchore / anchore-cli / anchorecli / cli / utils.py View on Github external
try:
        digest = unquote_plus(str(input_string))
        patt = re.match("(.*@|^)(sha256:.*)", digest)
        if patt:
            return("imageDigest", input_string, input_string)
        patt = re.match("(.*@|^)(local:.*)", digest)
        if patt:
            return("imageDigest", input_string, input_string)
    except Exception as err:
        pass

    urldigest = None
    ret_type = "tag"
    try:
        ret = anchorecli.clients.apiexternal.get_image(config, tag=input_string)
        if ret['success']:
            urldigest = ret['payload'][0]['imageDigest']
            try:
                image_record = ret['payload'][0]
                for image_detail in image_record['image_detail']:
                    if input_string == image_detail['imageId']:
                        ret_type = "imageid"
                        break
            except Exception as err:
                pass
        else:
            pass
    except Exception as err:
        urldigest = None

    return(ret_type, input_string, urldigest)
github anchore / anchore-cli / anchorecli / cli / image.py View on Github external
"""
    ecode = 0

    try:
        itype = anchorecli.cli.utils.discover_inputimage_format(config, input_image)
        image = input_image
        #timeout = float(timeout)
        t1 = time.time()
        while timeout < 0 or time.time() - t1 < timeout:
            _logger.debug("discovery from input: " + str(itype) + " : " + str(image))
            if itype == 'tag':
                ret = anchorecli.clients.apiexternal.get_image(config, tag=image, history=False)
            elif itype == 'imageid':
                ret = anchorecli.clients.apiexternal.get_image(config, image_id=image, history=False)
            elif itype == 'imageDigest':
                ret = anchorecli.clients.apiexternal.get_image(config, imageDigest=image, history=False)
            else:
                ecode = 1
                raise Exception("cannot use input image string: no discovered imageDigest")

            if ret['payload'] and ret['payload'][0]['analysis_status'] in ['analyzed', 'analysis_failed']:
                break
            else:
                if not ret['payload']:
                    raise Exception('Requested image not found in system')
                print('Status: {}'.format(ret['payload'][0]['analysis_status']))

            if timeout > 0:
                print('Waiting {} seconds for next retry. Total timeout remaining: {}'.format(interval, int(timeout - (time.time() - t1))))
            else:
                print('Waiting {} seconds for next retry.'.format(interval))
github anchore / anchore-cli / anchorecli / cli / image.py View on Github external
def get(input_image, show_history):
    """
    INPUT_IMAGE: Input image can be in the following formats: Image Digest, ImageID or registry/repo:tag
    """
    ecode = 0
    
    try:
        itype = anchorecli.cli.utils.discover_inputimage_format(config, input_image)
        image = input_image

        _logger.debug("discovery from input: " + str(itype) + " : " + str(image))
        if itype == 'tag':
            ret = anchorecli.clients.apiexternal.get_image(config, tag=image, history=show_history)
        elif itype == 'imageid':
            ret = anchorecli.clients.apiexternal.get_image(config, image_id=image, history=False)
        elif itype == 'imageDigest':
            ret = anchorecli.clients.apiexternal.get_image(config, imageDigest=image, history=False)
        else:
            ecode = 1
            raise Exception("cannot use input image string: no discovered imageDigest")

        if ret:
            ecode = anchorecli.cli.utils.get_ecode(ret)
            if ret['success']:
                print(anchorecli.cli.utils.format_output(config, 'image_get', {}, ret['payload']))
            else:
                raise Exception(json.dumps(ret['error'], indent=4))
        else:
            raise Exception("operation failed with empty response")

    except Exception as err:
github anchore / anchore-cli / anchorecli / cli / image.py View on Github external
def get(input_image, show_history):
    """
    INPUT_IMAGE: Input image can be in the following formats: Image Digest, ImageID or registry/repo:tag
    """
    ecode = 0
    
    try:
        itype = anchorecli.cli.utils.discover_inputimage_format(config, input_image)
        image = input_image

        _logger.debug("discovery from input: " + str(itype) + " : " + str(image))
        if itype == 'tag':
            ret = anchorecli.clients.apiexternal.get_image(config, tag=image, history=show_history)
        elif itype == 'imageid':
            ret = anchorecli.clients.apiexternal.get_image(config, image_id=image, history=False)
        elif itype == 'imageDigest':
            ret = anchorecli.clients.apiexternal.get_image(config, imageDigest=image, history=False)
        else:
            ecode = 1
            raise Exception("cannot use input image string: no discovered imageDigest")

        if ret:
            ecode = anchorecli.cli.utils.get_ecode(ret)
            if ret['success']:
                print(anchorecli.cli.utils.format_output(config, 'image_get', {}, ret['payload']))
            else:
                raise Exception(json.dumps(ret['error'], indent=4))
        else:
            raise Exception("operation failed with empty response")
github anchore / anchore-cli / anchorecli / cli / image.py View on Github external
:param timeout:
    :return:
    """
    ecode = 0

    try:
        itype = anchorecli.cli.utils.discover_inputimage_format(config, input_image)
        image = input_image
        #timeout = float(timeout)
        t1 = time.time()
        while timeout < 0 or time.time() - t1 < timeout:
            _logger.debug("discovery from input: " + str(itype) + " : " + str(image))
            if itype == 'tag':
                ret = anchorecli.clients.apiexternal.get_image(config, tag=image, history=False)
            elif itype == 'imageid':
                ret = anchorecli.clients.apiexternal.get_image(config, image_id=image, history=False)
            elif itype == 'imageDigest':
                ret = anchorecli.clients.apiexternal.get_image(config, imageDigest=image, history=False)
            else:
                ecode = 1
                raise Exception("cannot use input image string: no discovered imageDigest")

            if ret['payload'] and ret['payload'][0]['analysis_status'] in ['analyzed', 'analysis_failed']:
                break
            else:
                if not ret['payload']:
                    raise Exception('Requested image not found in system')
                print('Status: {}'.format(ret['payload'][0]['analysis_status']))

            if timeout > 0:
                print('Waiting {} seconds for next retry. Total timeout remaining: {}'.format(interval, int(timeout - (time.time() - t1))))
            else:
github anchore / anchore-cli / anchorecli / cli / image.py View on Github external
:param input_image:
    :param timeout:
    :return:
    """
    ecode = 0

    try:
        itype = anchorecli.cli.utils.discover_inputimage_format(config, input_image)
        image = input_image
        #timeout = float(timeout)
        t1 = time.time()
        while timeout < 0 or time.time() - t1 < timeout:
            _logger.debug("discovery from input: " + str(itype) + " : " + str(image))
            if itype == 'tag':
                ret = anchorecli.clients.apiexternal.get_image(config, tag=image, history=False)
            elif itype == 'imageid':
                ret = anchorecli.clients.apiexternal.get_image(config, image_id=image, history=False)
            elif itype == 'imageDigest':
                ret = anchorecli.clients.apiexternal.get_image(config, imageDigest=image, history=False)
            else:
                ecode = 1
                raise Exception("cannot use input image string: no discovered imageDigest")

            if ret['payload'] and ret['payload'][0]['analysis_status'] in ['analyzed', 'analysis_failed']:
                break
            else:
                if not ret['payload']:
                    raise Exception('Requested image not found in system')
                print('Status: {}'.format(ret['payload'][0]['analysis_status']))

            if timeout > 0:
github anchore / anchore-cli / anchorecli / cli / image.py View on Github external
"""
    INPUT_IMAGE: Input image can be in the following formats: Image Digest, ImageID or registry/repo:tag
    """
    ecode = 0
    
    try:
        itype = anchorecli.cli.utils.discover_inputimage_format(config, input_image)
        image = input_image

        _logger.debug("discovery from input: " + str(itype) + " : " + str(image))
        if itype == 'tag':
            ret = anchorecli.clients.apiexternal.get_image(config, tag=image, history=show_history)
        elif itype == 'imageid':
            ret = anchorecli.clients.apiexternal.get_image(config, image_id=image, history=False)
        elif itype == 'imageDigest':
            ret = anchorecli.clients.apiexternal.get_image(config, imageDigest=image, history=False)
        else:
            ecode = 1
            raise Exception("cannot use input image string: no discovered imageDigest")

        if ret:
            ecode = anchorecli.cli.utils.get_ecode(ret)
            if ret['success']:
                print(anchorecli.cli.utils.format_output(config, 'image_get', {}, ret['payload']))
            else:
                raise Exception(json.dumps(ret['error'], indent=4))
        else:
            raise Exception("operation failed with empty response")

    except Exception as err:
        print(anchorecli.cli.utils.format_error_output(config, 'image_get', {}, err))
        if not ecode: