args.uiurl, args.uiurl_compute) # Verification (override with -y) if not args.yes: print() print('Ready to execute commands against your Prisma Cloud tenant.') verification_response = str( input('Would you like to continue (y or yes to continue)?')) continue_response = {'yes', 'y'} print() if verification_response not in continue_response: pc_lib_general.pc_exit_error( 400, 'Verification failed due to user response. Exiting...') # Sort out API Login print('API - Getting authentication token...', end='') pc_settings = pc_lib_api.pc_jwt_get(pc_settings) print('Done.') # Get VMs list print('API - Getting VMs list...', end='') pc_settings, response_package = pc_lib_api.api_cloud_discovery_vms_get( pc_settings) print('Done.') file_name = "vms_list_full_" + str( datetime.now().strftime("%Y-%m-%d-%H-%M-%S")) + ".json" file_path = os.path.join(Path.home(), "prisma-compute-exports") print("Exporting data to: " + os.path.join(file_path, file_name)) pc_lib_general.pc_file_write_json(file_name, response_package, file_path) print('Done.')
pc_lib_general.pc_exit_error( 400, 'Verification failed due to user response. Exiting...') # Sort out API Login print('API - Getting authentication token...', end='') pc_settings = pc_lib_api.pc_jwt_get(pc_settings) print('Done.') # Grab the policies print('API - Getting current policy list...', end='') query_params = "policy.severity=high&policy.severity=medium&policy.severity=low&cloud.type=gcp&cloud.type=all&policy" \ ".subtype=run" \ "&policy.subtype=build&policy.subtype=run_and_build" pc_settings, response_package = pc_lib_api.api_policy_v2_list_filtered_get( pc_settings, query_params=query_params) policy_v2_list = response_package['data'] # Removing complianceMetadata from Json for policy_item in policy_v2_list: if "complianceMetadata" in policy_item: del policy_item['complianceMetadata'] print('Done.') # Preparing the destination file export_file_name = "policy_list_full_" + str( datetime.now().strftime("%Y-%m-%d-%H-%M-%S")) + ".json" export_file_path = os.path.join(Path.home(), "prisma-cloud-exports") if not os.path.exists(export_file_path): os.makedirs(export_file_path) pc_lib_general.pc_file_write_json(export_file_name, policy_v2_list, export_file_path)
policy_list_original = response_package['data'] export_file_data['policy_list_original'] = policy_list_original print(' Done.') print() # Get the individual policy objects in case something needs to be added for import print('API - Individual policy retrieval (might take a while)...') for policy_original_temp in policy_list_original: # Get the individual policy JSON object pc_settings, response_package = pc_lib_api.api_policy_get( pc_settings, policy_original_temp['policyId']) policy_specific_temp = response_package['data'] export_file_data['policy_object_original'][ policy_original_temp['policyId']] = policy_specific_temp # Get the related saved search object (if needed) if policy_original_temp['rule']['parameters']['savedSearch'] == "true": if policy_original_temp['rule']['criteria'] not in export_file_data[ 'search_object_original']: pc_settings, response_package = pc_lib_api.api_search_get( pc_settings, policy_original_temp['rule']['criteria']) search_specific_temp = response_package['data'] export_file_data['search_object_original'][policy_original_temp[ 'rule']['criteria']] = search_specific_temp print(' Done.') print() # Save compliance standard to file print('FILE - Saving Compliance Standard to a file...') pc_lib_general.pc_file_write_json(args.export_file_name, export_file_data) print(' File saved to ' + args.export_file_name)