diff --git a/Atomic/scan.py b/Atomic/scan.py index 891a6617..a620a480 100644 --- a/Atomic/scan.py +++ b/Atomic/scan.py @@ -110,9 +110,6 @@ 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): @@ -120,7 +117,9 @@ def get_additional_args(): " ([]) 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) diff --git a/Atomic/util.py b/Atomic/util.py index fff0909b..a0d7da07 100644 --- a/Atomic/util.py +++ b/Atomic/util.py @@ -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):