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

Commit

Permalink
Don't access scan info directly
Browse files Browse the repository at this point in the history
Also, improve typing
  • Loading branch information
jjnicola committed May 19, 2020
1 parent 54fe4da commit e0c2fbf
Show file tree
Hide file tree
Showing 4 changed files with 16 additions and 11 deletions.
1 change: 1 addition & 0 deletions CHANGELOG.md
Original file line number Diff line number Diff line change
Expand Up @@ -18,6 +18,7 @@ The format is based on [Keep a Changelog](https://keepachangelog.com/en/1.0.0/).
- Add [pontos](https://github.com/greenbone/pontos) as dev dependency for
managing the version information in ospd [#254](https://github.com/greenbone/ospd/pull/254)
- Add more info about scan progress with progress attribute in get_scans cmd. [#266](https://github.com/greenbone/ospd/pull/266)
- Add method to get complete target info [#275](https://github.com/greenbone/ospd/pull/275)

### Changes
- Modify __init__() method and use new syntax for super(). [#186](https://github.com/greenbone/ospd/pull/186)
Expand Down
4 changes: 1 addition & 3 deletions ospd/ospd.py
Original file line number Diff line number Diff line change
Expand Up @@ -1188,9 +1188,7 @@ def run(self) -> None:
def start_pending_scans(self):
for scan_id in self.scan_collection.ids_iterator():
if self.get_scan_status(scan_id) == ScanStatus.PENDING:
scan_target = self.scan_collection.scans_table[scan_id].get(
'target'
)
scan_target = self.scan_collection.get_target(scan_id)
scan_func = self.start_scan
scan_process = create_process(
func=scan_func, args=(scan_id, scan_target)
Expand Down
2 changes: 1 addition & 1 deletion ospd/protocol.py
Original file line number Diff line number Diff line change
Expand Up @@ -47,7 +47,7 @@ class OspRequest:
@staticmethod
def process_vts_params(
scanner_vts: Element,
) -> Dict[str, Union[Dict, List]]:
) -> Dict[str, Union[Dict[str, str], List]]:
""" Receive an XML object with the Vulnerability Tests an their
parameters to be use in a scan and return a dictionary.
Expand Down
20 changes: 13 additions & 7 deletions ospd/scan.py
Original file line number Diff line number Diff line change
Expand Up @@ -22,7 +22,7 @@

from collections import OrderedDict
from enum import Enum
from typing import List, Any, Dict, Iterator, Optional, Iterable
from typing import List, Any, Dict, Iterator, Optional, Iterable, Union

from ospd.network import target_str_to_list

Expand Down Expand Up @@ -347,38 +347,44 @@ def get_host_count(self, scan_id: str) -> int:

return total_hosts

def get_ports(self, scan_id: str):
def get_ports(self, scan_id: str) -> str:
""" Get a scan's ports list.
"""
target = self.scans_table[scan_id].get('target')
ports = target.pop('ports')
self.scans_table[scan_id]['target'] = target
return ports

def get_exclude_hosts(self, scan_id: str):
def get_exclude_hosts(self, scan_id: str) -> str:
""" Get an exclude host list for a given target.
"""
return self.scans_table[scan_id]['target'].get('exclude_hosts')

def get_finished_hosts(self, scan_id: str):
def get_finished_hosts(self, scan_id: str) -> str:
""" Get the finished host list sent by the client for a given target.
"""
return self.scans_table[scan_id]['target'].get('finished_hosts')

def get_credentials(self, scan_id: str):
def get_credentials(self, scan_id: str) -> Dict[str, Dict[str, str]]:
""" Get a scan's credential list. It return dictionary with
the corresponding credential for a given target.
"""
return self.scans_table[scan_id]['target'].get('credentials')

def get_target_options(self, scan_id: str):
def get_target_options(self, scan_id: str) -> Dict[str, str]:
""" Get a scan's target option dictionary.
It return dictionary with the corresponding options for
a given target.
"""
return self.scans_table[scan_id]['target'].get('options')

def get_vts(self, scan_id: str) -> Dict:
def get_target(
self, scan_id: str
) -> Dict[str, Union[str, Dict[str, Union[str, Dict[str, str]]]]]:
""" Get the complete target info"""
return self.scans_table[scan_id].get('target')

def get_vts(self, scan_id: str) -> Dict[str, Union[Dict[str, str], List]]:
""" Get a scan's vts. """
scan_info = self.scans_table[scan_id]
vts = scan_info.pop('vts')
Expand Down

0 comments on commit e0c2fbf

Please sign in to comment.