Secure your code as it's written. Use Snyk Code to scan source code in minutes - no build needed - and fix issues immediately.
def add(input_policy):
ecode = 0
try:
with open(input_policy, 'r') as FH:
policybundle = json.loads(FH.read())
ret = anchorecli.clients.apiexternal.add_policy(config, policybundle=policybundle, detail=True)
ecode = anchorecli.cli.utils.get_ecode(ret)
if ret['success']:
print(anchorecli.cli.utils.format_output(config, 'policy_add', {}, ret['payload']))
else:
raise Exception(json.dumps(ret['error'], indent=4))
except Exception as err:
print(anchorecli.cli.utils.format_error_output(config, 'policy_add', {}, err))
if not ecode:
ecode = 2
anchorecli.cli.utils.doexit(ecode)
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)