def scan(self, paths: list) -> dict: """Scan file(s) or directory per rule.""" if not (self.scan_rules and paths): return self.validate_rules() if self.show_progress: pbar = common.ProgressBar('Choice Match', len(self.scan_rules)) self.scan_rules = pbar.progrees_loop(self.scan_rules) for rule in self.scan_rules: scan_paths = paths if rule['type'] != 'code' and self.alternative_path: # Scan only alternative path scan_paths = [Path(self.alternative_path)] self.choice_matcher(scan_paths, rule) return self.findings
def scan(self, paths: list) -> dict: """Scan file(s) or directory.""" if not self.scan_rules: return self.validate_rules() if self.show_progress: pbar = common.ProgressBar('Pattern Match', len(paths)) paths = pbar.progrees_loop(paths) for sfile in paths: if self.exts: if not sfile.suffix.lower() in self.exts: continue data = sfile.read_text('utf-8', 'ignore') self.pattern_matcher(data, sfile.as_posix()) return self.findings
def scan(self, paths: list) -> dict: """Do sgrep scan.""" if self.exts: filtered = [] for sfile in paths: if sfile.suffix.lower() in self.exts: filtered.append(sfile) if filtered: paths = filtered if self.show_progress: pbar = common.ProgressBar('Semantic Grep', len(paths)) sgrep_out = pbar.progress_function(invoke_semgrep, (paths, self.scan_rules)) else: sgrep_out = invoke_semgrep(paths, self.scan_rules) self.format_output(sgrep_out) return self.findings
def scan(self, paths: list) -> dict: """Scan file(s) or directory.""" if not (self.scan_rules and paths): return self.validate_rules() if self.show_progress: pbar = common.ProgressBar('Pattern Match', len(paths)) paths = pbar.progrees_loop(paths) for sfile in paths: ext = sfile.suffix.lower() if self.exts and ext not in self.exts: continue if sfile.stat().st_size / 1000 / 1000 > 5: # Skip scanning files greater than 5 MB print(f'Skipping large file {sfile.as_posix()}') continue data = sfile.read_text('utf-8', 'ignore') self.pattern_matcher(data, sfile, ext) return self.findings