How to use the anchorecli.cli.utils.format_output 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 / archives.py View on Github external
archive|delete: the transition to execute - archive or delete. delete transitions occur on already archived analysis, not on the active image analysis

    """
    ecode = 0

    if days_old == 0 and tag_versions_newer == 0:
        resp = click.prompt('Are you sure you want to use 0 for both days old limit and number of tag versions newer? WARNING: This will archive all images that match the registry/repo/tag selectors as soon as they are analyzed', type=click.Choice(['y', 'n']), default='n')
        if resp.lower() != 'y':
            ecode = 0
            anchorecli.cli.utils.doexit(ecode)

    try:
        ret = anchorecli.clients.apiexternal.add_transition_rule(config, days_old, tag_versions_newer, registry_selector, repository_selector, tag_selector, transition, is_global)
        ecode = anchorecli.cli.utils.get_ecode(ret)
        if ret['success']:
            print(anchorecli.cli.utils.format_output(config, 'transition_rules', {}, ret['payload']))
        else:
            raise Exception(json.dumps(ret['error'], indent=4))

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

    anchorecli.cli.utils.doexit(ecode)
github anchore / anchore-cli / anchorecli / cli / system.py View on Github external
def list():
    ecode = 0

    try:
        ret = anchorecli.clients.apiexternal.system_feeds_list(config)
        ecode = anchorecli.cli.utils.get_ecode(ret)
        if ret['success']:
            print(anchorecli.cli.utils.format_output(config, 'system_feeds_list', {}, ret['payload']))
        else:
            raise Exception(json.dumps(ret['error'], indent=4))
    except Exception as err:
        print(anchorecli.cli.utils.format_error_output(config, 'system_feeds_list', {}, err))
        if not ecode:
            ecode = 2

    anchorecli.cli.utils.doexit(ecode)
github anchore / anchore-cli / anchorecli / cli / archives.py View on Github external
def image_delete(digest, force):
    """
    INPUT_IMAGE: Input image can be in the following formats: Image Digest, ImageID or registry/repo:tag
    """
    ecode = 0
    
    try:
        ret = anchorecli.clients.apiexternal.delete_archived_analysis(config, digest)

        if ret:
            if ret['success']:
                print(anchorecli.cli.utils.format_output(config, 'image_delete', {}, 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_delete', {}, err))
        if not ecode:
            ecode = 2

    anchorecli.cli.utils.doexit(ecode)
github anchore / anchore-cli / anchorecli / cli / event.py View on Github external
pass
                    try:
                        answer = input("Really delete (clear) all events? (y/N)")
                    except:
                        answer = "n"
            elif before or since:
                answer = "y"
            else:
                raise click.exceptions.BadArgumentUsage('Must include either an event_id, --all, --since, or --before')

            if 'y' == answer.lower():
                ret = anchorecli.clients.apiexternal.delete_events(config, since=since, before=before)

                ecode = anchorecli.cli.utils.get_ecode(ret)
                if ret['success']:
                    print(anchorecli.cli.utils.format_output(config, 'event_delete', {}, ret['payload']))
                else:
                    raise Exception(json.dumps(ret['error'], indent=4))

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

    anchorecli.cli.utils.doexit(ecode)
github anchore / anchore-cli / anchorecli / cli / event.py View on Github external
"""
    RESOURCE: Value can be a tag, image digest or repository name. Displays results related to the specific resource
    """
    ecode = 0

    try:
        if level:
            if level.upper() not in ['INFO', 'ERROR']:
                raise Exception('{} is an invalid value for --level. Supported values are \'info\' or \'error\''.format(level))
            level = level.upper()

        ret = anchorecli.clients.apiexternal.list_events(config, since=since, before=before, level=level, service=service, host=host, resource=resource, event_type=event_type, resource_type=resource_type, all=all)
        ecode = anchorecli.cli.utils.get_ecode(ret)
        if ret['success']:
            if full:
                print(anchorecli.cli.utils.format_output(config, 'event_list_full', {}, ret['payload']))
            else:
                print(anchorecli.cli.utils.format_output(config, 'event_list', {}, ret['payload']))
        else:
            raise Exception(json.dumps(ret['error'], indent=4))

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

    anchorecli.cli.utils.doexit(ecode)
github anchore / anchore-cli / anchorecli / cli / archives.py View on Github external
def rule_get(rule_id):
    ecode = 0

    try:
        ret = anchorecli.clients.apiexternal.get_transition_rule(config, rule_id)

        if ret:
            ecode = anchorecli.cli.utils.get_ecode(ret)
            if ret['success']:
                print(anchorecli.cli.utils.format_output(config, 'transition_rules', {}, 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, 'transition_rules', {}, err))
        if not ecode:
            ecode = 2

    anchorecli.cli.utils.doexit(ecode)
github anchore / anchore-cli / anchorecli / cli / event.py View on Github external
"""
    ecode = 0

    try:
        if level:
            if level.upper() not in ['INFO', 'ERROR']:
                raise Exception('{} is an invalid value for --level. Supported values are \'info\' or \'error\''.format(level))
            level = level.upper()

        ret = anchorecli.clients.apiexternal.list_events(config, since=since, before=before, level=level, service=service, host=host, resource=resource, event_type=event_type, resource_type=resource_type, all=all)
        ecode = anchorecli.cli.utils.get_ecode(ret)
        if ret['success']:
            if full:
                print(anchorecli.cli.utils.format_output(config, 'event_list_full', {}, ret['payload']))
            else:
                print(anchorecli.cli.utils.format_output(config, 'event_list', {}, ret['payload']))
        else:
            raise Exception(json.dumps(ret['error'], indent=4))

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

    anchorecli.cli.utils.doexit(ecode)
github anchore / anchore-cli / anchorecli / cli / account.py View on Github external
def whoami():
    global whoami
    ecode = 0
    print(anchorecli.cli.utils.format_output(config, 'account_whoami', {}, whoami))
    anchorecli.cli.utils.doexit(ecode)