Esempio n. 1
0
def toolbox(anchore_config, image):
    """
    A collection of tools for operating on images and containers and building anchore modules.

    Subcommands operate on the specified image passed in as --image <imgid>

    """
    global config, imagelist, nav
    config = anchore_config
    ecode = 0

    imagelist = [image]

    try:
        ret = anchore_utils.discover_imageIds(anchore_config, imagelist)
    except ValueError as err:
        raise err
    else:
        imagelist = ret.keys()

    try:
        nav = navigator.Navigator(anchore_config=config,
                                  imagelist=imagelist,
                                  allimages=contexts['anchore_allimages'])
    except Exception as err:
        anchore_print_err('operation failed')
        nav = None
        ecode = 1
Esempio n. 2
0
def toolbox(anchore_config, ctx, image):
    """
    A collection of tools for operating on images and containers and building anchore modules.

    Subcommands operate on the specified image passed in as --image <imgid>

    """

    global config, imagelist, nav
    config = anchore_config
    ecode = 0

    imagelist = [image]

    if ctx.invoked_subcommand not in ['import', 'delete']:
        try:
            try:
                ret = anchore_utils.discover_imageIds(imagelist)
            except ValueError as err:
                raise err
            else:
                #imagelist = ret.keys()
                imagelist = ret
        except Exception as err:
            anchore_print_err("could not load any images")
            sys.exit(1)

        try:
            nav = navigator.Navigator(anchore_config=config,
                                      imagelist=imagelist,
                                      allimages=contexts['anchore_allimages'])
        except Exception as err:
            anchore_print_err('operation failed')
            nav = None
            ecode = 1
Esempio n. 3
0
def toolbox(anchore_config, ctx, image, imageid):
    """
    A collection of tools for operating on images and containers and building anchore modules.

    Subcommands operate on the specified image passed in as --image <imgid>

    """

    global config, imagelist, nav

    config = anchore_config
    ecode = 0

    try:

        # set up imagelist of imageIds
        if image:
            imagelist = [image]
            try:
                result = anchore_utils.discover_imageIds(imagelist)
            except ValueError as err:
                raise err
            else:
                imagelist = result
        elif imageid:
            if len(imageid) != 64 or re.findall("[^0-9a-fA-F]+", imageid):
                raise Exception(
                    "input is not a valid imageId (64 characters, a-f, A-F, 0-9)"
                )

            imagelist = [imageid]
        else:
            imagelist = []

        if ctx.invoked_subcommand not in [
                'import', 'delete', 'kubesync', 'images', 'show'
        ]:
            if not imagelist:
                raise Exception(
                    "for this operation, you must specify an image with '--image' or '--imageid'"
                )
            else:
                try:
                    nav = navigator.Navigator(
                        anchore_config=config,
                        imagelist=imagelist,
                        allimages=contexts['anchore_allimages'])
                except Exception as err:
                    nav = None
                    raise err

    except Exception as err:
        anchore_print_err('operation failed')
        ecode = 1

    if ecode:
        sys.exit(ecode)
Esempio n. 4
0
def init_nav_contexts():
    try:
        # use the obj from the current click context. This is a bit hacky, but works as long as this method is
        # invoked in an execution context of click
        anchore_config = click.get_current_context().obj
        nav = navigator.Navigator(anchore_config=anchore_config,
                                  imagelist=imagelist,
                                  allimages=contexts['anchore_allimages'])
        return nav
    except Exception as err:
        anchore_print_err("explore operation failed")
        success = False
        ecode = 1

    if not success:
        contexts['anchore_allimages'].clear()
        sys.exit(ecode)