Secure your code as it's written. Use Snyk Code to scan source code in minutes - no build needed - and fix issues immediately.
def delete(host_id, servicename):
ecode = 0
try:
ret = anchorecli.clients.apiexternal.delete_system_service(config, host_id, servicename)
ecode = anchorecli.cli.utils.get_ecode(ret)
if ret['success']:
print(anchorecli.cli.utils.format_output(config, 'delete_system_service', {}, ret['payload']))
else:
raise Exception(json.dumps(ret['error'], indent=4))
except Exception as err:
print(anchorecli.cli.utils.format_error_output(config, 'delete_system_service', {}, err))
if not ecode:
ecode = 2
anchorecli.cli.utils.doexit(ecode)
def enable(account_name):
"""
ACCOUNT_NAME: name of account to enable
"""
ecode = 0
try:
ret = anchorecli.clients.apiexternal.enable_account(config, account_name=account_name)
ecode = anchorecli.cli.utils.get_ecode(ret)
if ret['success']:
print(anchorecli.cli.utils.format_output(config, 'account_enable', {}, ret['payload']))
else:
raise Exception( json.dumps(ret['error'], indent=4))
except Exception as err:
print(anchorecli.cli.utils.format_error_output(config, 'account_enable', {}, err))
if not ecode:
ecode = 2
anchorecli.cli.utils.doexit(ecode)
registry_type = "awsecr"
else:
registry_type = "docker_v2"
if not registry_name:
registry_name = registry
ret = anchorecli.clients.apiexternal.add_registry(config, registry=registry, registry_user=registry_user, registry_pass=registry_pass, registry_type=registry_type, insecure=insecure, validate=(not skip_validate), registry_name=registry_name)
ecode = anchorecli.cli.utils.get_ecode(ret)
if ret['success']:
print(anchorecli.cli.utils.format_output(config, 'registry_add', {}, ret['payload']))
else:
raise Exception( json.dumps(ret['error'], indent=4))
except Exception as err:
print(anchorecli.cli.utils.format_error_output(config, 'registry_add', {}, err))
if not ecode:
ecode = 2
anchorecli.cli.utils.doexit(ecode)
def list_archived_analyses():
ecode = 0
try:
ret = anchorecli.clients.apiexternal.list_archived_analyses(config)
ecode = anchorecli.cli.utils.get_ecode(ret)
if ret['success']:
print(anchorecli.cli.utils.format_output(config, 'analysis_archive_list', {}, ret['payload']))
else:
raise Exception(json.dumps(ret['error'], indent=4))
except Exception as err:
print(anchorecli.cli.utils.format_error_output(config, 'analysis_archive_list', {}, err))
if not ecode:
ecode = 2
anchorecli.cli.utils.doexit(ecode)
def get(event_id):
"""
EVENT_ID: ID of the event to be fetched
"""
ecode = 0
try:
ret = anchorecli.clients.apiexternal.get_event(config, event_id=event_id)
ecode = anchorecli.cli.utils.get_ecode(ret)
if ret['success']:
print(anchorecli.cli.utils.format_output(config, 'event_get', {}, ret['payload']))
else:
raise Exception(json.dumps(ret['error'], indent=4))
except Exception as err:
print(anchorecli.cli.utils.format_error_output(config, 'event_get', {}, err))
if not ecode:
ecode = 2
anchorecli.cli.utils.doexit(ecode)
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']:
print(anchorecli.cli.utils.format_output(config, 'image_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, 'image_get', {}, err))
if not ecode:
ecode = 2
anchorecli.cli.utils.doexit(ecode)
if debug:
logging.basicConfig(level=logging.DEBUG)
cli_opts = {
'u': u,
'p': p,
'url': url,
'hub-url': hub_url,
'api-version': api_version,
'insecure': insecure,
'json': json,
'debug': debug,
'as_account': as_account
}
config = utils.setup_config(cli_opts)
if config['debug']:
logging.basicConfig(level=logging.DEBUG)
ctx.obj = config