pyTenable icon indicating copy to clipboard operation
pyTenable copied to clipboard

pyTenable 1.4.3 - marshmallow.exceptions.ValidationError

Open Tomasfire opened this issue 4 years ago • 4 comments

Describe the bug Running Tenable asset export using pyTenable library with version 1.4.3 is raising marshmallow.exceptions.ValidationError.

To Reproduce Steps to reproduce the behavior:

  1. Execute the script to export Tenable assets.
  2. Script runs export_assets method.
    def export_assets(self, sources=None): 
        for asset in self._api.exports.assets(sources=sources, is_deleted=False, is_terminated=False):
            asset['network_interfaces'] = [NetworkInterface(**i) for i in asset['network_interfaces']]
            asset['tags'] = [Tag(**i) for i in asset['tags']]
            asset['sources'] = [AssetSource(**i) for i in asset['sources']]
            yield ExportedAsset(**asset)
  1. marshmallow.exceptions.ValidationError is thrown.

Expected behavior Assets are properly exported as in older version 1.3.3.

Screenshots

Traceback (most recent call last):
  File "sync.py", line 82, in <module>
    main(
  File "/opt/tenable-integrations/aws/here_integration/__init__.py", line 505, in main
    existing_assets: Iterable[ExportedAsset] = list(tenable.get_existing_assets(host_export_back_days=configuration.host_export_back_days))
  File "/opt/tenable-integrations/aws/here_integration/lib/nice_tenable.py", line 335, in export_assets
    for asset in self._api.exports.assets(sources=sources, is_deleted=False, is_terminated=False):
  File "/opt/tenable-integrations/aws/.venv/lib/python3.8/site-packages/tenable/io/exports/api.py", line 280, in assets
    return self._export('assets', AssetExportSchema(), **kwargs)
  File "/opt/tenable-integrations/aws/.venv/lib/python3.8/site-packages/tenable/io/exports/api.py", line 177, in _export
    payload = schema.dump(schema.load(kwargs))
  File "/opt/tenable-integrations/aws/.venv/lib/python3.8/site-packages/marshmallow/schema.py", line 719, in load
    return self._do_load(
  File "/opt/tenable-integrations/aws/.venv/lib/python3.8/site-packages/marshmallow/schema.py", line 904, in _do_load
    raise exc
marshmallow.exceptions.ValidationError: {'sources': ['Field may not be null.'], 'is_deleted': ['Unknown field.']}

System Information (please complete the following information):

  • OS: Ubuntu 20.04.3 LTS
  • Architecture x86_64
  • Version 5.11.0-46-generic
  • Memory 12GB

Additional context Issue might be related to file schema.py that seems to be refactored and boolean flag 'is_deleted' is missing. Either versions 1.4.2 and 1.4.3 are affected by this.

Tomasfire avatar Jan 18 '22 10:01 Tomasfire

PR open with the fixing change.

SteveMcGrath avatar Jan 18 '22 15:01 SteveMcGrath

@SteveMcGrath Thanks for the prompt PR. Is it also solving the problem with 'sources': ['Field may not be null.']?

Tomasfire avatar Jan 18 '22 16:01 Tomasfire

How are you passing sources?

SteveMcGrath avatar Jan 18 '22 16:01 SteveMcGrath

Issue was on our side. We are passing sources argument to the export, but never filled it with real data. It always stays on default sources=None value. After I changed: self._api.exports.assets(sources=sources, is_deleted=False, is_terminated=False) to self._api.exports.assets(is_deleted=False, is_terminated=False) and implemented your change from PR, export is running successfully.

Thanks for the hint in your previous comment, it was helpful.

Tomasfire avatar Jan 19 '22 11:01 Tomasfire

Closing as this is fixed with #523.

aseemsavio avatar Sep 29 '22 11:09 aseemsavio