How to use the anchorecli.cli 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 / system.py View on Github external
def status():
    ecode = 0

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

    anchorecli.cli.utils.doexit(ecode)
github anchore / anchore-cli / anchorecli / cli / evaluate.py View on Github external
def evaluate(ctx_config):
    global config
    config = ctx_config

    try:
        anchorecli.cli.utils.check_access(config)
    except Exception as err:
        print(anchorecli.cli.utils.format_error_output(config, 'evaluate', {}, err))
        sys.exit(2)
github anchore / anchore-cli / anchorecli / cli / event.py View on Github external
def event(ctx_config):
    global config
    config = ctx_config

    try:
        anchorecli.cli.utils.check_access(config)
    except Exception as err:
        print(anchorecli.cli.utils.format_error_output(config, 'event', {}, err))
        sys.exit(2)
github anchore / anchore-cli / anchorecli / cli / repo.py View on Github external
def repo(ctx_config):
    global config
    config = ctx_config

    try:
        anchorecli.cli.utils.check_access(config)
    except Exception as err:
        print(anchorecli.cli.utils.format_error_output(config, 'repo', {}, err))
        sys.exit(2)
github anchore / anchore-cli / anchorecli / cli / archives.py View on Github external
def archive(ctx_config):
    global config
    config = ctx_config

    try:
        anchorecli.cli.utils.check_access(config)
    except Exception as err:
        print(anchorecli.cli.utils.format_error_output(config, 'image', {}, err))
        sys.exit(2)
github anchore / anchore-cli / anchorecli / cli / account.py View on Github external
"""
    ACCOUNT_NAME: name of account to disable

    """
    ecode = 0

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

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

    anchorecli.cli.utils.doexit(ecode)
github anchore / anchore-cli / anchorecli / cli / event.py View on Github external
def list(since=None, before=None, level=None, service=None, host=None, resource=None, event_type=None, resource_type=None, all=False, full=False):
    """
    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 / subscription.py View on Github external
"""
    SUBSCRIPTION_TYPE: Type of subscription. Valid options: 

      - tag_update: Receive notification when new image is pushed

      - policy_eval: Receive notification when image policy status changes

      - vuln_update: Receive notification when vulnerabilities are added, removed or modified

    SUBSCRIPTION_KEY: Fully qualified name of tag to subscribe to. Eg. docker.io/library/alpine:latest
    """
    ecode = 0

    try:
        ret = anchorecli.clients.apiexternal.activate_subscription(config, subscription_type, subscription_key)
        ecode = anchorecli.cli.utils.get_ecode(ret)
        if ret['success']:
            print(anchorecli.cli.utils.format_output(config, 'subscription_activate', {}, ret['payload']))
        else:
            raise Exception( json.dumps(ret['error'], indent=4))

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

    anchorecli.cli.utils.doexit(ecode)
github anchore / anchore-cli / anchorecli / cli / policy.py View on Github external
def delete(policyid):
    """
    POLICYID: Policy ID to delete
    """
    ecode = 0

    try:
        ret = anchorecli.clients.apiexternal.delete_policy(config, policyId=policyid)
        ecode = anchorecli.cli.utils.get_ecode(ret)
        if ret['success']:
            print(anchorecli.cli.utils.format_output(config, 'policy_delete', {}, ret['payload']))
        else:
            raise Exception(json.dumps(ret['error'], indent=4))

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

    anchorecli.cli.utils.doexit(ecode)