Skip to content
This repository has been archived by the owner on Oct 10, 2020. It is now read-only.

Atomic/scan.py: Fix scan error message (BZ #1508453) #1123

Open
wants to merge 1 commit into
base: master
Choose a base branch
from
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
7 changes: 3 additions & 4 deletions Atomic/scan.py
Original file line number Diff line number Diff line change
Expand Up @@ -110,17 +110,16 @@ def get_additional_args():
scan_type = self.get_scan_type()

# Load the atomic config file and check scanner settings
yaml_error = "The image name or scanner arguments for '{}' is not " \
"defined in /etc/atomic.conf".format(self.scanner)

scanner_image_name, scanner_args, custom_args = get_scan_info(self.scanner, scan_type)

if not isinstance(scanner_args, list):
raise ValueError("The scanner arguments for {} must be in list"
" ([]) form.".format(self.scanner))

if None in [scanner_image_name, scanner_args]:
raise ValueError(yaml_error)
sconf_file = util.get_scanner_conf_path_by_name(self.scanner)
raise ValueError("The scanner configuration for '{}' in '{}' is missing its image name "
"or scanner arguments".format(self.scanner, sconf_file))

self.results_dir = os.path.join(self.results, self.scanner, self.cur_time)

Expand Down
16 changes: 16 additions & 0 deletions Atomic/util.py
Original file line number Diff line number Diff line change
Expand Up @@ -486,6 +486,22 @@ def _recursive_get(atomic_config, items):
else:
return default

def get_scanner_conf_path_by_name(scanner_name):
if not os.path.exists(ATOMIC_CONFD):
raise ValueError("{} does not exist".format(ATOMIC_CONFD))
files = [os.path.join(ATOMIC_CONFD, x) for x in os.listdir(ATOMIC_CONFD) if os.path.isfile(os.path.join(ATOMIC_CONFD, x))]
for f in files:
with open(f, 'r') as conf_file:
try:
temp_conf = yaml_load(conf_file)
if temp_conf.get('type') == "scanner" and temp_conf.get("scanner_name") == scanner_name:
return conf_file.name
except YAMLError:
pass
except AttributeError:
pass
raise ValueError("Unable to correlate {} to its configuration file".format(scanner_name))

def get_scanners():
scanners = []
if not os.path.exists(ATOMIC_CONFD):
Expand Down