Secure your code as it's written. Use Snyk Code to scan source code in minutes - no build needed - and fix issues immediately.
def policylist():
ecode = 0
try:
ret = anchorecli.clients.apiexternal.get_policies(config, detail=False)
ecode = anchorecli.cli.utils.get_ecode(ret)
if ret['success']:
print(anchorecli.cli.utils.format_output(config, 'policy_list', {'detail':False}, ret['payload']))
else:
raise Exception( json.dumps(ret['error'], indent=4))
except Exception as err:
print(anchorecli.cli.utils.format_error_output(config, 'policy_list', {}, err))
if not ecode:
ecode = 2
anchorecli.cli.utils.doexit(ecode)
'success': False,
'payload': {},
'httpcode': 500,
}
try:
bundle = _fetch_bundle(config, bundlename=bundlename, auth=auth)
if target_id:
bundleid = target_id
else:
bundleid = bundle['name']
bundle['id'] = bundleid
if not force:
ret = anchorecli.clients.apiexternal.get_policies(config)
if ret['success']:
for installed_policy in ret['payload']:
if installed_policy['policyId'] == bundleid:
raise Exception("Policy with ID ({}) already installed - use force to override or specify target unique ID".format(bundleid))
ret = anchorecli.clients.apiexternal.add_policy(config, policybundle=bundle, detail=True)
except Exception as err:
ret['success'] = False
ret['error'] = str(err)
return(ret)