Example #1
0
    def _build_scan_yml(self):
        file_system = FileSystemSingleton.INSTANCE

        if not self.scan_yml_file and not self.scan_yml_dict and not self.scan_yml:
            logging.error(f'No scan specified')
            return

        elif self.scan_yml_file and not self.scan_yml_dict and not self.scan_yml:
            if not isinstance(self.scan_yml_file, str):
                logging.error(
                    f'scan_builder.scan_yml_file must be str, but was {type(self.scan_yml_file)}: {self.scan_yml_file}'
                )
            elif file_system.is_readable_file(self.scan_yml_file):
                scan_yml_str = self.file_system.file_read_as_str(
                    self.scan_yml_file)
                if scan_yml_str:
                    self.scan_yml_dict = YamlHelper.parse_yaml(
                        scan_yml_str, self.scan_yml_file)
                else:
                    logging.error(
                        f'Failed to file scan yaml file: {self.scan_yml_file}')

        if self.scan_yml_dict and not self.scan_yml:
            from sodasql.scan.scan_yml_parser import ScanYmlParser
            scan_yml_parser = ScanYmlParser(self.scan_yml_dict,
                                            self.scan_yml_file)
            scan_yml_parser.log()
            self.parsers.append(scan_yml_parser)
            self.scan_yml = scan_yml_parser.scan_yml
Example #2
0
    def _build_scan_yml(self):
        if not self.scan_yml_file and not self.scan_yml_dict and not self.scan_yml:
            logger.error(f'No scan file specified')
            return
        elif self.scan_yml_file and not self.scan_yml_dict and not self.scan_yml:
            scan_yml_file_str: Optional[str] = None
            if isinstance(self.scan_yml_file, pathlib.PurePath):
                scan_yml_file_str = str(self.scan_yml_file)
            elif isinstance(self.scan_yml_file, str):
                scan_yml_file_str = self.scan_yml_file

            if not isinstance(scan_yml_file_str, str):
                logger.error(
                    f'scan_builder.scan_yml_file must be str, but was {type(scan_yml_file_str)}: {scan_yml_file_str}'
                )
            elif self.file_system.is_readable_file(scan_yml_file_str):
                scan_yml_str = self.file_system.file_read_as_str(
                    scan_yml_file_str)

                if scan_yml_str:
                    self.scan_yml_dict = YamlHelper.parse_yaml(
                        scan_yml_str, scan_yml_file_str)
                else:
                    logger.error(
                        f'Failed to parse scan yaml file: {scan_yml_file_str}')

        if self.scan_yml_dict and not self.scan_yml:
            from sodasql.scan.scan_yml_parser import ScanYmlParser
            scan_yml_parser = ScanYmlParser(self.scan_yml_dict,
                                            self.scan_yml_file)
            scan_yml_parser.log()
            self.parsers.append(scan_yml_parser)
            self.scan_yml = scan_yml_parser.scan_yml