policy_item['rule']['name_tf'] = '' policy_item['rule']['type_tf'] = '' policy_item['rule']['criteria_tf'] = '' if 'type_cft' not in policy_item['rule']: policy_item['rule']['name_cft'] = '' policy_item['rule']['type_cft'] = '' policy_item['rule']['criteria_cft'] = '' if 'type_k8s' not in policy_item['rule']: policy_item['rule']['name_k8s'] = '' policy_item['rule']['type_k8s'] = '' policy_item['rule']['criteria_k8s'] = '' if 'criteria' not in policy_item['rule']: policy_item['rule']['criteria'] = '' policy_item['rql_query'] = '' if "complianceMetadata" in policy_item: del policy_item['complianceMetadata'] if 'savedSearch' in policy_item['rule']['parameters'] and policy_item['rule']['parameters'][ 'savedSearch'] == 'true': pc_settings, policy_rql = pc_lib_api.api_search_get(pc_settings, policy_item['rule']['criteria']) # pprint(policy_rql['data']['query']) policy_item['rql_query'] = policy_rql['data']['query'] # Converting to CSV and appending to file policies_df = pandas.json_normalize(policy_item) # put json inside a dataframe policies_df = policies_df[sorted(policies_df.columns)] # sorting columns alphabetically to match the header of the file policies_df.to_csv(export_file_path + "/" + export_file_name, sep=',', encoding='utf-8', index=False, date_format='%m-%d-%y || %I:%M:%S %p CDT%z', mode='a', header=False) print('Done.')
print('Done.') # Print the JSON object from the policy list API call (different from the specific policy object call below) print() print('Policy from list:') print(json.dumps(policy)) print() # Get the individual complete policy object from the API print('API - Getting the specific policy...', end='') pc_settings, response_package = pc_lib_api.api_policy_get(pc_settings, policy_id) policy_specific = response_package['data'] print('Done.') # Print the JSON object from the specific policy API call (use this one for any updates to the policy object) print() print('Original Policy Object:') print(json.dumps(policy_specific)) print() # Print the JSON object of the related Saved Search (if desired with the -rql switch) if args.rql: # Get the related Saved Search object for the policy pc_settings, response_package = pc_lib_api.api_search_get(pc_settings, policy['rule']['criteria']) policy_search = response_package['data'] # Print the search object for the policy print() print('Related Saved Search Object:') print(json.dumps(policy_search))