How to use the anchorecli.cli.utils.discover_inputimage_format 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 / image.py View on Github external
def wait(input_image, timeout, interval):
    """
    Wait for an image to go to analyzed or analysis_failed status with a specific timeout

    :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']:
github anchore / anchore-cli / anchorecli / cli / image.py View on Github external
def add(input_image, force, dockerfile, annotation, noautosubscribe):
    """
    INPUT_IMAGE: Input image can be in the following formats: registry/repo:tag
    """
    ecode = 0

    try:
        itype = anchorecli.cli.utils.discover_inputimage_format(config, input_image)

        dockerfile_contents = None
        if dockerfile:
            with open(dockerfile, 'r') as FH:
                dockerfile_contents = base64.b64encode(FH.read().encode('utf-8')).decode('utf-8')

        autosubscribe = not noautosubscribe

        if itype == 'tag':
            annotations = {}
            if annotation:
                for a in annotation:
                    try:
                        (k,v) = a.split('=', 1)
                        if k and v:
                            annotations[k] = v
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']: