Skip to content
This repository has been archived by the owner on Nov 29, 2021. It is now read-only.

Commit

Permalink
Improve docstrings and fix log messages
Browse files Browse the repository at this point in the history
  • Loading branch information
jjnicola committed Jan 26, 2021
1 parent f6a75a9 commit 302aae9
Showing 1 changed file with 51 additions and 28 deletions.
79 changes: 51 additions & 28 deletions ospd/ospd.py
Original file line number Diff line number Diff line change
Expand Up @@ -595,7 +595,7 @@ def start_scan(self, scan_id: str) -> None:
self.finish_scan(scan_id)
elif not is_stopped:
logger.info(
"%s: Host scan finished. Progress: %d, " "Status: %s",
"%s: Host scan finished. Progress: %d, Status: %s",
scan_id,
progress,
status.name,
Expand Down Expand Up @@ -710,7 +710,8 @@ def get_scan_status(self, scan_id: str) -> ScanStatus:
def scan_exists(self, scan_id: str) -> bool:
"""Checks if a scan with ID scan_id is in collection.
@return: 1 if scan exists, 0 otherwise.
Returns:
1 if scan exists, 0 otherwise.
"""
return self.scan_collection.id_exists(scan_id)

Expand Down Expand Up @@ -753,7 +754,8 @@ def elements_as_text(self, elems: Dict, indent: int = 2) -> str:
def delete_scan(self, scan_id: str) -> int:
"""Deletes scan_id scan from collection.
@return: 1 if scan deleted, 0 otherwise.
Returns:
1 if scan deleted, 0 otherwise.
"""
if self.get_scan_status(scan_id) == ScanStatus.RUNNING:
return 0
Expand All @@ -776,7 +778,8 @@ def get_scan_results_xml(
):
"""Gets scan_id scan's results in XML format.
@return: String of scan results in xml.
Returns:
String of scan results in xml.
"""
results = Element('results')
for result in self.scan_collection.results_iterator(
Expand Down Expand Up @@ -818,7 +821,8 @@ def _get_scan_progress_raw(self, scan_id: str) -> Dict:
def _get_scan_progress_xml(self, scan_id: str):
"""Gets scan_id scan's progress in XML format.
@return: String of scan progress in xml.
Returns:
String of scan progress in xml.
"""
current_progress = self._get_scan_progress_raw(scan_id)
return get_progress_xml(current_progress)
Expand All @@ -830,9 +834,11 @@ def _get_scan_progress_xml(self, scan_id: str):
def get_xml_str(self, data: Dict) -> List:
"""Creates a string in XML Format using the provided data structure.
@param: Dictionary of xml tags and their elements.
Arguments:
data: Dictionary of xml tags and their elements.
@return: String of data in xml format.
Returns:
String of data in xml format.
"""
return get_elements_from_dict(data)

Expand All @@ -846,7 +852,8 @@ def get_scan_xml(
):
"""Gets scan in XML format.
@return: String of scan in XML format.
Returns:
String of scan in XML format.
"""
if not scan_id:
return Element('scan')
Expand Down Expand Up @@ -899,7 +906,8 @@ def get_custom_vt_as_xml_str( # pylint: disable=unused-argument
The custom XML object which is returned will be embedded
into a <custom></custom> element.
@return: XML object as string for custom data.
Returns:
XML object as string for custom data.
"""
return ''

Expand All @@ -915,7 +923,8 @@ def get_params_vt_as_xml_str( # pylint: disable=unused-argument
The params XML object which is returned will be embedded
into a <params></params> element.
@return: XML object as string for vt parameters data.
Returns:
XML object as string for vt parameters data.
"""
return ''

Expand All @@ -931,7 +940,8 @@ def get_refs_vt_as_xml_str( # pylint: disable=unused-argument
The refs XML object which is returned will be embedded
into a <refs></refs> element.
@return: XML object as string for vt references data.
Returns:
XML object as string for vt references data.
"""
return ''

Expand All @@ -947,7 +957,8 @@ def get_dependencies_vt_as_xml_str( # pylint: disable=unused-argument
The vt_dependencies XML object which is returned will be embedded
into a <dependencies></dependencies> element.
@return: XML object as string for vt dependencies data.
Returns:
XML object as string for vt dependencies data.
"""
return ''

Expand All @@ -963,7 +974,8 @@ def get_creation_time_vt_as_xml_str( # pylint: disable=unused-argument
The vt_creation_time XML object which is returned will be embedded
into a <vt_creation_time></vt_creation_time> element.
@return: XML object as string for vt creation time data.
Returns:
XML object as string for vt creation time data.
"""
return ''

Expand All @@ -979,7 +991,8 @@ def get_modification_time_vt_as_xml_str( # pylint: disable=unused-argument
The vt_modification_time XML object which is returned will be embedded
into a <vt_modification_time></vt_modification_time> element.
@return: XML object as string for vt references data.
Returns:
XML object as string for vt references data.
"""
return ''

Expand All @@ -995,7 +1008,8 @@ def get_summary_vt_as_xml_str( # pylint: disable=unused-argument
The summary XML object which is returned will be embedded
into a <summary></summary> element.
@return: XML object as string for summary data.
Returns:
XML object as string for summary data.
"""
return ''

Expand All @@ -1011,7 +1025,8 @@ def get_impact_vt_as_xml_str( # pylint: disable=unused-argument
The impact XML object which is returned will be embedded
into a <impact></impact> element.
@return: XML object as string for impact data.
Returns:
XML object as string for impact data.
"""
return ''

Expand All @@ -1027,7 +1042,8 @@ def get_affected_vt_as_xml_str( # pylint: disable=unused-argument
The affected XML object which is returned will be embedded
into a <affected></affected> element.
@return: XML object as string for affected data.
Returns:
XML object as string for affected data.
"""
return ''

Expand All @@ -1043,7 +1059,8 @@ def get_insight_vt_as_xml_str( # pylint: disable=unused-argument
The insight XML object which is returned will be embedded
into a <insight></insight> element.
@return: XML object as string for insight data.
Returns:
XML object as string for insight data.
"""
return ''

Expand All @@ -1059,7 +1076,8 @@ def get_solution_vt_as_xml_str( # pylint: disable=unused-argument
The solution XML object which is returned will be embedded
into a <solution></solution> element.
@return: XML object as string for solution data.
Returns:
XML object as string for solution data.
"""
return ''

Expand All @@ -1075,7 +1093,8 @@ def get_detection_vt_as_xml_str( # pylint: disable=unused-argument
The detection XML object which is returned is an element with
tag <detection></detection> element
@return: XML object as string for detection data.
Returns:
XML object as string for detection data.
"""
return ''

Expand All @@ -1091,7 +1110,8 @@ def get_severities_vt_as_xml_str( # pylint: disable=unused-argument
The severities XML objects which are returned will be embedded
into a <severities></severities> element.
@return: XML object as string for severities data.
Returns:
XML object as string for severities data.
"""
return ''

Expand All @@ -1105,7 +1125,8 @@ def get_vt_iterator( # pylint: disable=unused-argument
def get_vt_xml(self, single_vt: Tuple[str, Dict]) -> Element:
"""Gets a single vulnerability test information in XML format.
@return: String of single vulnerability test information in XML format.
Returns:
String of single vulnerability test information in XML format.
"""
if not single_vt or single_vt[1] is None:
return Element('vt')
Expand Down Expand Up @@ -1217,7 +1238,7 @@ def get_vts_selection_list(
vt_id (vt_id, optional): ID of the vt to get.
filtered_vts (list, optional): Filtered VTs collection.
Return:
Returns:
List of selected VT's OID.
"""
vts_xml = []
Expand Down Expand Up @@ -1348,7 +1369,7 @@ def start_queued_scans(self) -> None:
def is_new_scan_allowed(self) -> bool:
"""Check if max_scans has been reached.
Return:
Returns:
True if a new scan can be launch.
"""
if (self.max_scans != 0) and (
Expand All @@ -1368,7 +1389,7 @@ def is_enough_free_memory(self) -> bool:
a new scan. The necessary memory is a rough calculation and very
conservative.
Return:
Returns:
True if there is enough memory for a new scan.
"""
if not self.min_free_mem_scan_queue:
Expand Down Expand Up @@ -1406,11 +1427,13 @@ def create_scan(
) -> Optional[str]:
"""Creates a new scan.
@target: Target to scan.
@options: Miscellaneous scan options supplied via <scanner_params>
Arguments:
target: Target to scan.
options: Miscellaneous scan options supplied via <scanner_params>
XML element.
@return: New scan's ID. None if the scan_id already exists.
Returns:
New scan's ID. None if the scan_id already exists.
"""
status = None
scan_exists = self.scan_exists(scan_id)
Expand Down

0 comments on commit 302aae9

Please sign in to comment.