tenable / pyTenable

Python Library for interfacing into Tenable's platform APIs
https://pytenable.readthedocs.io
MIT License
356 stars 175 forks source link

After using a object data, it is empty #811

Closed MAngel666 closed 4 months ago

MAngel666 commented 4 months ago

After "using" of an object it seems to be empty. I see the data only 1x.

Code:

sc = TenableSC(creds_api_tenable.api_host, access_key = creds_api_tenable.api_accesskey, secret_key = creds_api_tenable.api_secretkey)

vulns = sc.analysis.vulns(
    ('severity', '=', '1,2,3,4'),
    ('policy', '=', {'id': '1000001'}),
    ('lastSeen', '=', '0:30'),
    ('vulnUUID', '=', '337ec211-222e-4e3e-bdef-6ac133048750'),
)

for vuln in vulns:
    pprint(vuln)

for vuln in vulns:
    pprint(vuln)

Expected behavior I see the same data 2x, because of 2x the same for loop.

System Information (please complete the following information):

SteveMcGrath commented 4 months ago

This is expected behavior as that how an iterator works. It'll present the data an item at a time until none are left.

The library handles the information this way to get around a lot of large memory issues that would otherwise occur from handling large datasets. If you intend on using the same data multiple times I would suggest you either rethink the logic to only need to work on an item once, or store the data elsewhere to later retrieval.