Source code for tenable.tenableone.inventory.software.api
"""Software========Methods described in this section relate to the software API.These methods can be accessed at ``TenableOne.inventory.software``... rst-class:: hide-signature.. autoclass:: SoftwareAPI :members:"""fromtypingimportOptionalfromtenable.base.endpointimportAPIEndpointfromtenable.tenableone.inventory.schemaimport(Field,Properties,PropertyFilter,QueryMode,SortDirection,)fromtenable.tenableone.inventory.software.schemaimportSoftwareValues
[docs]deflist_properties(self)->list[Field]:""" Retrieve software properties Returns: The software properties. Examples: >>> tenable_inventory_software_properties = tenable_inventory.software.list_properties() >>> for software_property in software_properties: ... pprint(software_property) """asset_properties_response:dict[str,list[dict]]=self._get(path='api/v1/t1/inventory/software/properties')returnProperties(**asset_properties_response).data
[docs]deflist(self,query_text:Optional[str]=None,query_mode:Optional[QueryMode]=None,filters:Optional[list[PropertyFilter]]=None,extra_properties:Optional[list[str]]=None,offset:Optional[int]=None,limit:Optional[int]=None,sort_by:Optional[str]=None,sort_direction:Optional[SortDirection]=None,)->SoftwareValues:""" Retrieve software Args: query_text (str, optional): The text to search for. query_mode (QueryMode, optional): The search mode. Defaults to QueryMode.SIMPLE. filters (list, optional): A list of filters to apply. Defaults to None. extra_properties (list, optional): Additional properties to include in the response. Defaults to None. offset (int, optional): Number of records to skip. Defaults to 0. limit (int, optional): Maximum number of records per page. Defaults to 1000. sort_by (str, optional): Field to sort by. sort_direction (SortDirection, optional): Sorting direction, either SortDirection.ASC or SortDirection.DESC. Returns: The request software. Examples: >>> tenable_inventory_software = tenable_inventory.software.list() >>> for software in tenable_inventory_software: ... pprint(software) """# Build query parametersparams={}ifextra_propertiesisnotNone:params['extra_properties']=','.join(extra_properties)ifoffsetisnotNone:params['offset']=offsetiflimitisnotNone:params['limit']=limitifsort_byisnotNoneandsort_directionisnotNone:params['sort']=f'{sort_by}:{sort_direction.value}'# Build request body with flattened search/query paramspayload={}ifquery_textisnotNoneorquery_modeisnotNone:payload['query']={}ifquery_textisnotNone:payload['query']['text']=query_textifquery_modeisnotNone:payload['query']['mode']=query_mode.valueiffiltersisnotNone:payload['filters']=[filter.model_dump(mode='json')forfilterinfilters]software_response:dict=self._post('api/v1/t1/inventory/software/search',json=payload,params=params)returnSoftwareValues(**software_response)