def run(): args = _get_cmdline_args() log.setLevel(logging.ERROR - args.verbose * 10) if args.render_html: issues = [] for src in args.source: log.info(f"loading '{src}'") issues.extend(utils.load(src)) write(issues, file=args.output, format="html") return 0 if args.config: config = _load_config(args.config) rules = utils.load(args.rules) issues = [] for src in args.source: with TemporaryDirectory() as tmp: copy(src, tmp) if not args.config: config = _search_config(tmp) issues.extend(scan(tmp, config, rules)) write(issues, file=args.output, format=args.format) return bool(issues)
def test_run_scan(repo: Repo, tmpdir: str): expected = os.path.join(tmpdir, "repo.json") path, _ = repo args = ["", path, "-f", "json", "--output", expected] with patch.object(sys, "argv", args): cli.run() assert len(utils.load(expected)) == 4
def _load_config(file: File = None) -> Config: config = Config() if file: user_config = utils.load(file) if user_config: config.update(**user_config) else: log.warning(f"empty config supplied: '{_name(file)}'") args = _get_cmdline_args(**config.raw) config.update(**args.__dict__) log.info(f"using config\n\n{config}") return config
def run(config: argparse.Namespace) -> List[Issue]: log.setLevel(logging.ERROR - config.verbose * 10) rules = utils.load(config.rules) issues: List[Issue] = [] source_dir = config.source[0] config_obj = Config() config_obj.update(**config.__dict__) with TemporaryDirectory() as tmp: cli.copy(source_dir, tmp) issues.extend(cli.scan(tmp, config_obj, rules)) return issues
def test_run_scan_with_config(repo: Repo, datadir: str, tmpdir: str): expected = os.path.join(tmpdir, "repo.json") path, _ = repo args = [ "", path, "-f", "json", "--output", expected, "-c", os.path.join(datadir, config_json), ] with patch.object(sys, "argv", args): cli.run() assert len(utils.load(expected)) == 3
def rules() -> Rules: return utils.load(_RULES)
def repo(tempdir: str) -> Repo: print(check_output(["./scripts/makerepo", tempdir]).decode()) meta = utils.load(os.path.join(tempdir, "meta.yaml")) return os.path.join(tempdir, "repo"), meta
def test_load(datadir: str, config: Config): assert utils.load(os.path.join(datadir, "trufflehog.json")) == config assert utils.load(os.path.join(datadir, "trufflehog.yaml")) == config