コード例 #1
0
print(' done.')
print()

if args.cloud_account_name:
    cloud_accounts_list = [next(item for item in cloud_accounts_list if item['name'] == args.cloud_account_name)]

resource_list = []

for cloud_account in cloud_accounts_list:
    body_params = {
        'filters':[
            {'operator':'=', 'name':'includeEventForeignEntities', 'value': 'false'},
            {'operator':'=', 'name':'asset.severity', 'value': 'all'},
            {'operator':'=', 'name':'cloud.account',  'value': '%s' % cloud_account['name']},
            {'operator':'=', 'name':'cloud.type',     'value': '%s' % cloud_account['deploymentType']},
            {'operator':'=', 'name':'scan.status',    'value': 'all'}],
        'limit': 1000,
        'timeRange': {'type': 'to_now'}
    }
    print('API - Getting the current Resources for Cloud Account: %s ...' % cloud_account['name'])
    cloud_account_resource_list = pc_api.resource_scan_info_read(body_params=body_params)
    print('Done.')
    # Threaded Queries.
    resource_list.append(pc_api.get_cloud_resources(cloud_account_resource_list))

pc_utility.write_json_file(args.export_file_name, resource_list)
print()
print('Exported to: %s' % args.export_file_name)

pc_api.error_report()
コード例 #2
0
# HUGE WARNING: NO VALIDATION HERE IN THIS EXAMPLE (so that it fits the broadest set of use-cases)

# Prompt for warning if interactive
pc_utility.prompt_for_verification_to_continue(args)

# Make the HTTP request

try:
    response = pc_api.execute(args.http_method,
                              args.uri_path,
                              query_params=args.uri_params,
                              body_params=request_body_data)
    if args.response_file is None:
        print('API - HTTP request response is:', file=stderr)
        if args.pretty:
            print(json_dumps(response, indent=4, separators=(', ', ': ')),
                  file=stdout)
        else:
            print(json_dumps(response), file=stdout)
    else:
        print('API - HTTP request response stored in file %s' %
              args.response_file,
              file=stderr)
        pc_utility.write_json_file(args.response_file,
                                   response,
                                   pretty=bool(args.pretty))
except Exception:  # pylint: disable=W0703
    print('API - HTTP request failed', file=stderr)
    sys_exit(1)
コード例 #3
0
args = parser.parse_args()

# --Initialize-- #

settings = pc_utility.get_settings(args)
pc_api.configure(settings)

# --Main-- #

# Policy Custom Export

export_file_data = {}
export_file_data['export_file_version'] = DEFAULT_POLICY_EXPORT_FILE_VERSION
export_file_data['policy_list_original'] = []
export_file_data['policy_object_original'] = {}
export_file_data['search_object_original'] = {}

print('API - Getting the current list of Custom Policies ...', end='')
policy_list_current = pc_api.policy_custom_v2_list_read()
export_file_data['policy_list_original'] = policy_list_current
print(' done.')
print()

# Threaded Queries.
result = pc_api.export_policies_with_saved_searches(policy_list_current)

export_file_data['policy_object_original'] = result['policies']
export_file_data['search_object_original'] = result['searches']
pc_utility.write_json_file(args.export_file_name, export_file_data)
print('Exported to: %s' % args.export_file_name)