How to use the anchorecli.cli.utils.get_ecode 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 / repo.py View on Github external
def get(input_repo):
    """
    INPUT_REPO: Input repository can be in the following formats: registry/repo
    """
    ecode = 0

    image_info = anchorecli.cli.utils.parse_dockerimage_string(input_repo)
    input_repo = image_info['registry'] + "/" + image_info['repo']
    
    try:
        ret = anchorecli.clients.apiexternal.get_repo(config, input_repo=input_repo)
        if ret:
            ecode = anchorecli.cli.utils.get_ecode(ret)
            if ret['success']:
                print(anchorecli.cli.utils.format_output(config, 'repo_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, 'repo_get', {}, err))
        if not ecode:
            ecode = 2

    anchorecli.cli.utils.doexit(ecode)
github anchore / anchore-cli / anchorecli / cli / repo.py View on Github external
def watch(input_repo):
    """
    INPUT_REPO: Input repo can be in the following formats: registry/repo
    """
    ecode = 0

    image_info = anchorecli.cli.utils.parse_dockerimage_string(input_repo)
    input_repo = image_info['registry'] + "/" + image_info['repo']
    
    try:
        ret = anchorecli.clients.apiexternal.watch_repo(config, input_repo)
        ecode = anchorecli.cli.utils.get_ecode(ret)
        if ret:
            if ret['success']:
                print(anchorecli.cli.utils.format_output(config, 'repo_watch', {}, 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, 'repo_watch', {}, err))
        if not ecode:
            ecode = 2

    anchorecli.cli.utils.doexit(ecode)
github anchore / anchore-cli / anchorecli / cli / registry.py View on Github external
def get(registry):
    """
    REGISTRY: Full hostname/port of registry. Eg. myrepo.example.com:5000
    """
    ecode = 0

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

    except Exception as err:
        print(anchorecli.cli.utils.format_error_output(config, 'registry_get', {}, err))
        if not ecode:
            ecode = 2
    anchorecli.cli.utils.doexit(ecode)
github anchore / anchore-cli / anchorecli / cli / evaluate.py View on Github external
ecode = 0

    try:
        itype, image, imageDigest = anchorecli.cli.utils.discover_inputimage(config, input_image)

        if imageDigest:
            thetag = input_image
            if tag:
                thetag = tag
            elif itype == 'tag':
                thetag = image
            else:
                raise Exception("input image name is not a tag, and no --tag is specified")

            ret = anchorecli.clients.apiexternal.check_eval(config, imageDigest=imageDigest, history=show_history, detail=detail, tag=thetag, policyId=policy)
            ecode = anchorecli.cli.utils.get_ecode(ret)
            if ret['success']:
                print(anchorecli.cli.utils.format_output(config, 'evaluate_check', {'detail': detail, 'history': show_history, 'tag': thetag}, ret['payload']))
                ecode = anchorecli.cli.utils.get_eval_ecode(ret['payload'], anchorecli.cli.utils.unquote_plus(imageDigest))
            else:
                raise Exception(json.dumps(ret['error'], indent=4))
        else:
            raise Exception("could not get image record from anchore")

    except Exception as err:
        print(anchorecli.cli.utils.format_error_output(config, 'evaluate_check', {}, 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 / 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)
github anchore / anchore-cli / anchorecli / cli / policy.py View on Github external
def activate(policyid):
    """
    POLICYID: Policy ID to be activated
    """
    ecode = 0

    try:
        ret = anchorecli.clients.apiexternal.get_policy(config, policyId=policyid, detail=True)
        ecode = anchorecli.cli.utils.get_ecode(ret)
        if ret['success']:
            policy_records = ret['payload']
            policy_record = {}
            if policy_records:
                policy_record = policy_records[0]
        else:
            raise Exception(json.dumps(ret['error'], indent=4))

        if not policy_record:
            raise Exception("no policy could be fetched to activate")

        policy_record['active'] = True

        ret = anchorecli.clients.apiexternal.update_policy(config, policyid, policy_record=policy_record)
        ecode = anchorecli.cli.utils.get_ecode(ret)
        if ret['success']: