Source code for tenable.io.assets

'''
assets
======

The following methods allow for interaction into the Tenable.io
:devportal:`assets <assets>` API endpoints.

Methods available on ``tio.assets``:

.. rst-class:: hide-signature
.. autoclass:: AssetsAPI

    .. automethod:: asset_import
    .. automethod:: details
    .. automethod:: import_job_details
    .. automethod:: list
    .. automethod:: list_import_jobs
    .. automethod:: tags
'''
from .base import TIOEndpoint

[docs]class AssetsAPI(TIOEndpoint):
[docs] def list(self): ''' Returns a list of assets. :devportal:`assets: list-assets <assets-list-assets>` Returns: :obj:`list`: List of asset records. Examples: >>> for asset in tio.assets.list(): ... pprint(asset) ''' return self._api.get('assets').json()['assets']
[docs] def details(self, uuid): ''' Retrieves the details about a specific asset. :devportal:`assets: asset-info <assets-asset-info>` Args: uuid (str): The UUID (unique identifier) for the asset. Returns: :obj:`dict`: Asset resource definition. Examples: >>> asset = tio.assets.details( ... '00000000-0000-0000-0000-000000000000') ''' return self._api.get( 'assets/{}'.format( self._check('uuid', uuid, str) )).json()
[docs] def tags(self, uuid): ''' Retrieves the details about a specific asset. :devportal:`tags: asset-tags <tags-list-asset-tags>` Args: uuid (str): The UUID (unique identifier) for the asset. Returns: :obj:`dict`: Asset resource definition. Examples: >>> asset = tio.assets.tags( ... '00000000-0000-0000-0000-000000000000') ''' return self._api.get( 'tags/assets/{}/assignments'.format( self._check('uuid', uuid, 'uuid') )).json()
[docs] def asset_import(self, source, *assets): ''' Imports asset information into Tenable.io from an external source. :devportal:`assets: import <assets-import>` Imports a list of asset definition dictionaries. Each asset record must contain at least one of the following attributes: ``fqdn``, ``ipv4``, ``netbios_name``, ``mac_address``. Each record may also contain additional properties. Args: *assets (list): The list of asset dictionaries source (str): An identifier to be used to upload the assets. Returns: :obj:`str`: The job UUID. Examples: >>> tio.assets.asset_import('example_source', { ... 'fqdn': ['example.py.test'], ... 'ipv4': ['192.168.254.1'], ... 'netbios_name': 'example', ... 'mac_address': ['00:00:00:00:00:00'] ... }) ''' # We will likely want to perform some more stringent checking of the # asset resources that are being defined, however a simple type check # should suffice for now. return self._api.post( 'import/assets', json={ 'assets': [self._check('asset', i, dict) for i in assets], 'source': self._check('source', source, str) }).json()['asset_import_job_uuid']
[docs] def list_import_jobs(self): ''' Returns a list of asset import jobs. :devportal:`assets: list-import-jobs <assets-list-import-jobs>` Returns: :obj:`list`: List of job records. Examples: >>> for job in tio.assets.list_import_jobs(): ... pprint(job) ''' return self._api.get('import/asset-jobs').json()['asset_import_jobs']
[docs] def import_job_details(self, uuid): ''' Returns the details about a specific asset import job. :devportal:`assets: import-job-info <assets-import-job-info>` uuid (str): The UUID (unique identifier) for the job. Returns: :obj:`dict`: The job Resource record. Examples: >>> job = tio.assets.import_job_details( ... '00000000-0000-0000-0000-000000000000') >>> pprint(job) ''' return self._api.get( 'import/asset-jobs/{}'.format( self._check('uuid', uuid, str) )).json()